[WebUI] Show the active modules as text in the page heading (#2406)
Every page heading printed the modules JSON array as is (["LilyGo_SSD1306","WebUI","LORA"]). Show it as a comma separated list. The heading buffer was also filled with serializeJson(modules, jsonChar, measureJson(modules) + 1), i.e. the size of the text rather than of the 100 bytes buffer, which overflows when many modules are enabled; the new helper (and the boot log) use the buffer size. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eb1e7c71e6
commit
3ec01a72fd
2 files changed
+37
-23
No files matched your search
+1
-1
@@ -1646,7 +1646,7 @@ void setup() {
|
||||
THEENGS_LOG_TRACE(F("mqtt_max_payload_size: %d" CR), mqtt_max_payload_size);
|
||||
SYSConfig.offline ? THEENGS_LOG_NOTICE(F("Offline enabled" CR)) : THEENGS_LOG_NOTICE(F("Offline disabled" CR));
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
serializeJson(modules, jsonChar, sizeof(jsonChar));
|
||||
THEENGS_LOG_NOTICE(F("OpenMQTTGateway modules: %s" CR), jsonChar);
|
||||
THEENGS_LOG_NOTICE(F("************** Setup OpenMQTTGateway end **************" CR));
|
||||
}
|
||||
|
||||
+36
-22
@@ -52,6 +52,20 @@ WebServer server(80);
|
||||
webUIQueueMessage* currentWebUIMessage;
|
||||
|
||||
extern JsonArray modules;
|
||||
|
||||
/**
|
||||
* Active modules as readable text for the page heading, e.g. "LilyGo_SSD1306, WebUI, LORA"
|
||||
* (the modules list is a JSON array, serializing it showed ["LilyGo_SSD1306","WebUI","LORA"]).
|
||||
* Truncated to the buffer size.
|
||||
*/
|
||||
static void modulesHeading(char* out, size_t size) {
|
||||
String text;
|
||||
for (JsonVariant module : modules) {
|
||||
if (text.length()) text += ", ";
|
||||
text += module.as<const char*>();
|
||||
}
|
||||
strlcpy(out, text.c_str(), size);
|
||||
}
|
||||
extern char discovery_prefix[];
|
||||
extern String latestVersion;
|
||||
|
||||
@@ -507,7 +521,7 @@ void handleRoot() {
|
||||
} else if (server.hasArg("rst")) { // TODO: This should redirect to the RST page
|
||||
THEENGS_LOG_WARNING(F("[WebUI] Restart" CR));
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Restart").c_str());
|
||||
server.sendContent(restart_script);
|
||||
@@ -525,7 +539,7 @@ void handleRoot() {
|
||||
}
|
||||
} else {
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Main Menu").c_str());
|
||||
server.sendContent(root_script);
|
||||
@@ -549,7 +563,7 @@ void handleCN() {
|
||||
}
|
||||
} else {
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Configuration").c_str());
|
||||
server.sendContent(script);
|
||||
@@ -591,7 +605,7 @@ void handleWU() {
|
||||
}
|
||||
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Configure WebUI").c_str());
|
||||
server.sendContent(script);
|
||||
@@ -678,7 +692,7 @@ void handleWI() {
|
||||
WEBUI_TRACE_LOG(F("handleWI scan: results %s" CR), WiFiScan.c_str());
|
||||
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Configure WiFi").c_str());
|
||||
server.sendContent(wifi_script);
|
||||
@@ -708,7 +722,7 @@ void handleWI() {
|
||||
String topic = String(mqtt_topic) + String(gateway_name) + String(subjectMQTTtoSYSset);
|
||||
THEENGS_LOG_WARNING(F("[WebUI] Save WiFi and Restart" CR));
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Save WiFi and Restart").c_str());
|
||||
server.sendContent(restart_script);
|
||||
@@ -726,7 +740,7 @@ void handleWI() {
|
||||
}
|
||||
}
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Configure WiFi").c_str());
|
||||
server.sendContent(wifi_script);
|
||||
@@ -832,7 +846,7 @@ void handleMQ() {
|
||||
WEBtoSYS["cnt_index"] = CNT_DEFAULT_INDEX;
|
||||
WEBtoSYS["save_cnt"] = true;
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Save MQTT and Reconnect").c_str());
|
||||
server.sendContent(restart_script);
|
||||
@@ -853,7 +867,7 @@ void handleMQ() {
|
||||
}
|
||||
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Configure MQTT").c_str());
|
||||
server.sendContent(script);
|
||||
@@ -925,7 +939,7 @@ void handleCG() {
|
||||
}
|
||||
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Save and Restart").c_str());
|
||||
server.sendContent(restart_script);
|
||||
@@ -949,7 +963,7 @@ void handleCG() {
|
||||
}
|
||||
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Configure gateway").c_str());
|
||||
server.sendContent(script);
|
||||
@@ -984,7 +998,7 @@ void handleLO() {
|
||||
}
|
||||
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Configure Logging").c_str());
|
||||
server.sendContent(script);
|
||||
@@ -1111,7 +1125,7 @@ void handleBL() {
|
||||
}
|
||||
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Configure BLE").c_str());
|
||||
if (strlen(ble_script) > 0) {
|
||||
@@ -1279,7 +1293,7 @@ void handleLA() {
|
||||
}
|
||||
}
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Configure LORA").c_str());
|
||||
server.sendContent(script);
|
||||
@@ -1439,7 +1453,7 @@ void handleRF() {
|
||||
String activeReceiverHtml = generateActiveReceiverOptions(iRFConfig.getActiveReceiver());
|
||||
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Configure RF").c_str());
|
||||
server.sendContent(script);
|
||||
@@ -1463,7 +1477,7 @@ void handleRT() {
|
||||
}
|
||||
if (server.hasArg("non")) {
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
THEENGS_LOG_WARNING(F("[WebUI] Erase and Restart" CR));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Erase and Restart").c_str());
|
||||
@@ -1503,7 +1517,7 @@ void handleCL() {
|
||||
}
|
||||
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Configure Cloud").c_str());
|
||||
server.sendContent(script);
|
||||
@@ -1547,7 +1561,7 @@ void handleTK() {
|
||||
if (setCloudDeviceToken(deviceToken) && server.arg("RT").toInt() == requestToken && server.arg("uptime").toInt() + 600 > uptime()) {
|
||||
setCloudEnabled(true);
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Received Device Token").c_str());
|
||||
server.sendContent(script);
|
||||
@@ -1578,7 +1592,7 @@ void handleIN() {
|
||||
}
|
||||
} else {
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
|
||||
String informationDisplay = stateMeasures(); // .replace(",\"", "}1"); // .replace("\":", "=2")
|
||||
|
||||
@@ -1695,7 +1709,7 @@ void handleUP() {
|
||||
}
|
||||
}
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Firmware Upgrade").c_str());
|
||||
@@ -1709,7 +1723,7 @@ void handleUP() {
|
||||
|
||||
void sendRestartPage() {
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Updating Firmware and Restart").c_str());
|
||||
server.sendContent(restart_script);
|
||||
@@ -1770,7 +1784,7 @@ void handleCS() {
|
||||
server.send(200, "text/plain", message);
|
||||
} else {
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
modulesHeading(jsonChar, sizeof(jsonChar));
|
||||
beginChunkedResponse();
|
||||
sendHeaderChunk((String(gateway_name) + " - Console").c_str());
|
||||
server.sendContent(console_script);
|
||||
|
||||
Reference in new issue
Block a user