Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/display/plugins/WebUIPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void WebUIPlugin::loop() {
ota->checkForUpdates();
pluginManager->trigger("ota:update:status", "value", ota->isUpdateAvailable());
lastUpdateCheck = now;
updateOTAStatus(ota->getCurrentVersion());
updateOTAStatus();
}
if (now > lastStatus + STATUS_PERIOD && !ws.getClients().empty()) {
lastStatus = now;
Expand Down Expand Up @@ -495,7 +495,7 @@ void WebUIPlugin::handleOTASettings(uint32_t clientId, JsonDocument &request) {
lastUpdateCheck = 0;
}
}
updateOTAStatus("Checking...");
updateOTAStatus();
}

void WebUIPlugin::handleOTAStart(uint32_t clientId, JsonDocument &request) {
Expand Down Expand Up @@ -886,20 +886,24 @@ void WebUIPlugin::handleBLEScaleInfo(AsyncWebServerRequest *request) {
request->send(response);
}

void WebUIPlugin::updateOTAStatus(const String &version) {
void WebUIPlugin::updateOTAStatus() {
if (ws.getClients().empty()) {
return;
}
Settings const &settings = controller->getSettings();
const String controllerVersion = controller->getSystemInfo().version;
if (controllerVersion != lastSyncedControllerVersion) {
ota->setControllerVersion(controllerVersion);
lastSyncedControllerVersion = controllerVersion;
}
JsonDocument doc(&psramAllocator);
doc["latestVersion"] = ota->getCurrentVersion();
doc["tp"] = "res:ota-settings";
doc["latestVersion"] = ota->getCurrentVersion();
doc["displayUpdateAvailable"] = ota->isUpdateAvailable(false);
doc["controllerUpdateAvailable"] = ota->isUpdateAvailable(true);
doc["displayVersion"] = BUILD_GIT_VERSION;
doc["controllerVersion"] = controller->getSystemInfo().version;
doc["controllerVersion"] = controllerVersion;
doc["hardware"] = controller->getSystemInfo().hardware;
doc["latestVersion"] = ota->getCurrentVersion();
doc["channel"] = settings.getOTAChannel();
doc["updating"] = updating;
// LittleFS usage metrics
Expand Down
3 changes: 2 additions & 1 deletion src/display/plugins/WebUIPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class WebUIPlugin : public Plugin {
void handleBLEScaleScan(AsyncWebServerRequest *request);
void handleBLEScaleConnect(AsyncWebServerRequest *request);
void handleBLEScaleInfo(AsyncWebServerRequest *request);
void updateOTAStatus(const String &version);
void updateOTAStatus();
void updateOTAProgress(uint8_t phase, int progress);
void sendAutotuneResult();
void sendAutotuneFailed();
Expand Down Expand Up @@ -83,6 +83,7 @@ class WebUIPlugin : public Plugin {
bool apMode = false;
bool serverRunning = false;
String updateComponent = "";
String lastSyncedControllerVersion = "";
float currentBluetoothWeight = 0.0f;
// Reused for every 500ms status broadcast. Allocating a fresh JsonDocument
// each tick was a major contributor to internal-heap fragmentation
Expand Down
Loading