From c4f5124f5dfb6317ab12b1fcd09ef263a771d798 Mon Sep 17 00:00:00 2001 From: Neuroquila-n8fall Date: Fri, 7 Oct 2022 08:24:44 +0200 Subject: [PATCH 01/14] remove unused variable --- src/webconfig.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/webconfig.cpp b/src/webconfig.cpp index fb4ffcd..0fe9389 100644 --- a/src/webconfig.cpp +++ b/src/webconfig.cpp @@ -4,7 +4,6 @@ AsyncWebServer *server; AsyncEventSource *eventSource; volatile bool ShouldReboot = false; -static size_t content_len; void StartApMode() { From 05f2aaddd60408fbef51a0a36c8483d47eef5a96 Mon Sep 17 00:00:00 2001 From: Neuroquila-n8fall Date: Fri, 7 Oct 2022 08:25:16 +0200 Subject: [PATCH 02/14] Fix: Reboot ESP when requested by web interface --- src/main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index cdfe654..ef97381 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -146,6 +146,14 @@ Serial.println("\e[1;36mSetup Mode not enabled. You can enable it at every time void loop() { + // Init reboot if requested + if (ShouldReboot) { + WiFi.disconnect(); + server->end(); + vTaskDelay(3000 / portTICK_PERIOD_MS); + ESP.restart(); + } + // Stop executing when SetupMode is active. if (SetupMode) { From ce1f115fe7166b71cb3d8dd49764ec66e109fd28 Mon Sep 17 00:00:00 2001 From: Neuroquila-n8fall Date: Fri, 7 Oct 2022 08:25:25 +0200 Subject: [PATCH 03/14] Fix typo --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ef97381..f323266 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -237,7 +237,7 @@ void loop() // We can only "suggest" to set to a certain temperature or switching off the pump(s) // I have "borrowed" the concept of a step-chain from PLC programming since it appears - // to have been incoorporated into the controller as well because values arrive in + // to have been incorporated into the controller as well because values arrive in // intervals of approximately 1 second. CANMessage msg; From 34aeaa866ba97a863a807c24ecc4c49bc9f453d2 Mon Sep 17 00:00:00 2001 From: Neuroquila-n8fall Date: Fri, 7 Oct 2022 08:39:30 +0200 Subject: [PATCH 04/14] Delete unused function --- src/webconfig.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/webconfig.cpp b/src/webconfig.cpp index 0fe9389..9a96d2c 100644 --- a/src/webconfig.cpp +++ b/src/webconfig.cpp @@ -927,16 +927,3 @@ void getSystemStatus(AsyncWebServerRequest *request) sendJson(doc, request); } - -// Make size of files human readable -String humanReadableSize(const size_t bytes) -{ - if (bytes < 1024) - return String(bytes) + " B"; - else if (bytes < (1024 * 1024)) - return String(bytes / 1024.0) + " KB"; - else if (bytes < (1024 * 1024 * 1024)) - return String(bytes / 1024.0 / 1024.0) + " MB"; - else - return String(bytes / 1024.0 / 1024.0 / 1024.0) + " GB"; -} From 70d222f32c1ce4aec96acffb7ff8e0234445bcbd Mon Sep 17 00:00:00 2001 From: Neuroquila-n8fall Date: Fri, 7 Oct 2022 08:41:27 +0200 Subject: [PATCH 05/14] Use long type for interpolation --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f323266..ed0933e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -506,7 +506,7 @@ void SetDateTime() msg.data[3] = 4; if (configuration.General.Debug) { - Log.printf("DEBUG: Date and Time DOW:%i H:%i M:%i\r\n", myTZ.dateTime("N").toInt(), myTZ.hour(), myTZ.minute()); + Log.printf("DEBUG: Date and Time DOW:%li H:%i M:%i\r\n", myTZ.dateTime("N").toInt(), myTZ.hour(), myTZ.minute()); } SendMessage(msg); From 002b6fa634d8e37b253e5416d008ab49dd86c3bb Mon Sep 17 00:00:00 2001 From: Neuroquila-n8fall Date: Fri, 7 Oct 2022 08:41:58 +0200 Subject: [PATCH 06/14] Formatting ... use auto type for millis --- src/wifi_config.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/wifi_config.cpp b/src/wifi_config.cpp index 0cf2000..b8a811f 100644 --- a/src/wifi_config.cpp +++ b/src/wifi_config.cpp @@ -27,12 +27,15 @@ void connectWifi() WiFi.disconnect(); WiFi.setHostname(configuration.Wifi.Hostname); WiFi.mode(WIFI_STA); - + Serial.println("WiFi not connected. Reconnecting..."); - if(configuration.General.Debug) - Serial.printf("Connecting to %s using password %s and hostname %s \r\n", configuration.Wifi.SSID, configuration.Wifi.Password, configuration.Wifi.Hostname); - unsigned long prevConnectMillis = millis(); + if(configuration.General.Debug) { + Serial.printf("Connecting to %s using password %s and hostname %s \r\n", configuration.Wifi.SSID, + configuration.Wifi.Password, configuration.Wifi.Hostname); + } + + auto prevConnectMillis = millis(); WiFi.begin(configuration.Wifi.SSID, configuration.Wifi.Password); while (WiFi.waitForConnectResult() != WL_CONNECTED) { From 8cbf22abff36d840f7bf9c22a20d1c47b89ce3a6 Mon Sep 17 00:00:00 2001 From: Neuroquila-n8fall Date: Fri, 7 Oct 2022 08:45:52 +0200 Subject: [PATCH 07/14] Replace 'var' --- data/frontend/canalyzer.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/data/frontend/canalyzer.html b/data/frontend/canalyzer.html index a8cce81..a3d17cc 100644 --- a/data/frontend/canalyzer.html +++ b/data/frontend/canalyzer.html @@ -90,8 +90,8 @@

Watch CAN Messages

} async function loadKnownAddresses() { - var addresses = await getConfigJson("/api/config/canbus"); - var keys = getDeepKeys(addresses); + const addresses = await getConfigJson("/api/config/canbus"); + const keys = getDeepKeys(addresses); keys.forEach(e => { let value = jsonPathToValue(addresses, e); knownAddresses.push(value); @@ -126,7 +126,7 @@

Watch CAN Messages

*/ function addToKnownAddress(id) { const msgId = `0x${id.toUpperCase()}`; - var found = unknownAddresses.findIndex((e) => e === msgId); + const found = unknownAddresses.findIndex((e) => e === msgId); unknownAddresses.slice(found, 1); _(`${id.toLowerCase()}-unknown`).remove(); knownAddresses.push(`0x${id}`); @@ -143,7 +143,7 @@

Watch CAN Messages

*/ function addUnknownAddress(id) { const msgId = `0x${id.toUpperCase()}`; - var found = knownAddresses.findIndex((e) => e === msgId); + const found = knownAddresses.findIndex((e) => e === msgId); if(found > -1) { unknownAddresses.slice(found, 1); _(`${id.toLowerCase()}-enabled`).remove(); @@ -265,7 +265,7 @@

Watch CAN Messages

} function decimalToHex(d, padding) { - var hex = Number(d).toString(16); + let hex = Number(d).toString(16); padding = typeof (padding) === "undefined" || padding === null ? padding = 2 : padding; while (hex.length < padding) { @@ -276,10 +276,10 @@

Watch CAN Messages

} function startEvents(){ - var es = new EventSource('/events'); - es.addEventListener('can', function(e) { + const es = new EventSource('/events'); + es.addEventListener('can', function(e) { addMessage(e.data); - }, false); + }, false); } \ No newline at end of file From 3f1d647418b64dc89ddfc58610f7aa265258cade Mon Sep 17 00:00:00 2001 From: Neuroquila-n8fall Date: Fri, 7 Oct 2022 08:46:56 +0200 Subject: [PATCH 08/14] Formatting --- data/frontend/canalyzer.html | 444 ++++++++++++++++++----------------- 1 file changed, 233 insertions(+), 211 deletions(-) diff --git a/data/frontend/canalyzer.html b/data/frontend/canalyzer.html index a3d17cc..7372ab9 100644 --- a/data/frontend/canalyzer.html +++ b/data/frontend/canalyzer.html @@ -10,225 +10,247 @@ - -
-
-
-
-

Options and Utilities

-
- - -
-
-
-
Known Addresses
-
- -
-
-
-
Unknown Addresses
-
- -
+ +
+
+
+
+

Options and Utilities

+
+ +
-
- -
-

Watch CAN Messages

+
+
Known Addresses
+
+
-
- - - - - - - - - - - - - - - - - - -
ID12345678
+
+
+
Unknown Addresses
+
+
-
+
+
+ +
+

Watch CAN Messages

+
+
+ + + + + + + + + + + + + + + + + + +
+ ⇋ + ID + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 +
+
+
+
- - - - - + + + + + return hex; + } + + function startEvents() { + const es = new EventSource('/events'); + es.addEventListener('can', function (e) { + addMessage(e.data); + }, false); + } + \ No newline at end of file From 022988109f5e6756e1dae0d73304e866ed36e2ea Mon Sep 17 00:00:00 2001 From: Neuroquila-n8fall Date: Fri, 7 Oct 2022 09:03:35 +0200 Subject: [PATCH 09/14] Refactoring Use addEventListener instead of inline definition. Remove unused code and doubled attributes --- data/frontend/auxsensors.html | 16 ++++++++-------- data/frontend/canbus.html | 8 +++++--- data/frontend/firmware.html | 4 +++- data/frontend/general.html | 6 ++++-- data/frontend/leds.html | 4 +++- data/frontend/mqtt.html | 9 ++++++--- data/frontend/reboot.html | 27 +++++++++++++++------------ data/frontend/wifi.html | 6 ++++-- 8 files changed, 48 insertions(+), 32 deletions(-) diff --git a/data/frontend/auxsensors.html b/data/frontend/auxsensors.html index dfd6cc1..9807079 100644 --- a/data/frontend/auxsensors.html +++ b/data/frontend/auxsensors.html @@ -31,7 +31,7 @@

Auxiliary Sensors Configuration

Add Sensor

-
+
Sensor Label @@ -71,7 +71,7 @@

Add Sensor

Configured Sensors

-
+
@@ -85,10 +85,14 @@

Configured Sensors

\ No newline at end of file diff --git a/data/frontend/general.html b/data/frontend/general.html index c1a5a9a..4630d50 100644 --- a/data/frontend/general.html +++ b/data/frontend/general.html @@ -22,7 +22,7 @@

General Settings

- +
@@ -50,7 +50,7 @@

General Settings

+ class="form-control" autocomplete="busmsgtimeout" value="30" required> Time in seconds before control over the heating is assumed when no other controllers have been detected on the bus.
@@ -93,6 +93,8 @@

General Settings

getTz(); loadGeneralConfig(); + _("general-form").addEventListener("onsubmit", sendGeneralConfig); + async function loadGeneralConfig() { let form = document.forms["general-form"]; const config = await getGeneralConfig(); diff --git a/data/frontend/leds.html b/data/frontend/leds.html index e505736..f3d80bb 100644 --- a/data/frontend/leds.html +++ b/data/frontend/leds.html @@ -36,7 +36,7 @@

LED Configuration

Loading...
- +
Status LED @@ -96,6 +96,8 @@

LED Configuration

loadNavigation(); loadConfig(); + _("led-form").addEventListener("onsubmit", saveConfig); + async function loadConfig() { const form = document.forms["led-form"]; _("form-fieldset").disabled = true; diff --git a/data/frontend/mqtt.html b/data/frontend/mqtt.html index 41d17e6..01ba1f1 100644 --- a/data/frontend/mqtt.html +++ b/data/frontend/mqtt.html @@ -26,13 +26,13 @@

MQTT Configuration

Server Configuration

- +
@@ -76,7 +76,7 @@

Server Configuration

Topics Configuration

- +
@@ -194,6 +194,9 @@

Topics Configuration

loadMqttConfig(); loadMqttTopicsConfig(); + _("mqtt-form").addEventListener("onsubmit", sendMqttConfig); + _("mqtt-topics-form").addEventListener("onsubmit", sendMqttTopicsConfig); + async function loadMqttConfig() { const form = document.forms["mqtt-form"]; form.disabled = true; diff --git a/data/frontend/reboot.html b/data/frontend/reboot.html index d6a0de6..25c5f61 100644 --- a/data/frontend/reboot.html +++ b/data/frontend/reboot.html @@ -10,23 +10,26 @@ +
- + } + + countdown(); + \ No newline at end of file diff --git a/data/frontend/wifi.html b/data/frontend/wifi.html index 5a8418e..df9eeaf 100644 --- a/data/frontend/wifi.html +++ b/data/frontend/wifi.html @@ -22,7 +22,7 @@

Set Wifi Credentials

- +
@@ -86,7 +86,9 @@

Found Networks

loadNavigation();