From 021f8055b050a8e435249309f35d76677615c944 Mon Sep 17 00:00:00 2001 From: CurlyMoo Date: Sun, 3 Nov 2024 17:26:52 +0100 Subject: [PATCH 1/6] Allow forcing rules on boot despite crash --- HeishaMon/HeishaMon.ino | 2 +- HeishaMon/htmlcode.h | 7 +++++++ HeishaMon/webfunctions.cpp | 14 ++++++++++++++ HeishaMon/webfunctions.h | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/HeishaMon/HeishaMon.ino b/HeishaMon/HeishaMon.ino index 1491a649..51921de7 100644 --- a/HeishaMon/HeishaMon.ino +++ b/HeishaMon/HeishaMon.ino @@ -1471,7 +1471,7 @@ void setup() { #elif defined(ESP32) esp_reset_reason_t reset_reason = esp_reset_reason(); loggingSerial.printf(PSTR("Reset reason: %d\n"), reset_reason); - if (reset_reason > 3 && reset_reason < 12) { //is this correct for esp32? + if (heishamonSettings->force_rules == true || (reset_reason > 3 && reset_reason < 12)) { //is this correct for esp32? #endif loggingSerial.println("Not loading rules due to crash reboot!"); } else { diff --git a/HeishaMon/htmlcode.h b/HeishaMon/htmlcode.h index 5c298d0b..f3ff15ad 100644 --- a/HeishaMon/htmlcode.h +++ b/HeishaMon/htmlcode.h @@ -752,6 +752,13 @@ static const char settingsForm2[] PROGMEM = " " " " " " + " " + " " + " Force loading rules on boot (despite crash conditions):" + " " + " " + " " + " " " " " " " " diff --git a/HeishaMon/webfunctions.cpp b/HeishaMon/webfunctions.cpp index f1f6b83f..1d15177e 100755 --- a/HeishaMon/webfunctions.cpp +++ b/HeishaMon/webfunctions.cpp @@ -219,6 +219,7 @@ void loadSettings(settingsStruct *heishamonSettings) { if ( jsonDoc["mqtt_password"] ) strlcpy(heishamonSettings->mqtt_password, jsonDoc["mqtt_password"], sizeof(heishamonSettings->mqtt_password)); if ( jsonDoc["ntp_servers"] ) strlcpy(heishamonSettings->ntp_servers, jsonDoc["ntp_servers"], sizeof(heishamonSettings->ntp_servers)); if ( jsonDoc["timezone"]) heishamonSettings->timezone = jsonDoc["timezone"]; + heishamonSettings->force_rules = ( jsonDoc["force_rules"] == "enabled" ) ? true : false; heishamonSettings->use_1wire = ( jsonDoc["use_1wire"] == "enabled" ) ? true : false; heishamonSettings->use_s0 = ( jsonDoc["use_s0"] == "enabled" ) ? true : false; heishamonSettings->listenonly = ( jsonDoc["listenonly"] == "enabled" ) ? true : false; @@ -407,6 +408,10 @@ void settingsToJson(JsonDocument &jsonDoc, settingsStruct *heishamonSettings) { jsonDoc["listenonly"] = "enabled"; } else { jsonDoc["listenonly"] = "disabled"; + } if (heishamonSettings->force_rules) { + jsonDoc["force_rules"] = "enabled"; + } else { + jsonDoc["force_rules"] = "disabled"; } if (heishamonSettings->listenmqtt) { jsonDoc["listenmqtt"] = "enabled"; @@ -475,6 +480,7 @@ int saveSettings(struct webserver_t *client, settingsStruct *heishamonSettings) settingsToJson(jsonDoc, heishamonSettings); //stores current settings in a json document + jsonDoc["force_rules"] = String(""); jsonDoc["listenonly"] = String(""); jsonDoc["listenmqtt"] = String(""); jsonDoc["logMqtt"] = String(""); @@ -513,6 +519,8 @@ int saveSettings(struct webserver_t *client, settingsStruct *heishamonSettings) } } else if (strcmp(tmp->name.c_str(), "listenonly") == 0) { jsonDoc["listenonly"] = tmp->value; + } else if (strcmp(tmp->name.c_str(), "force_rules") == 0) { + jsonDoc["force_rules"] = tmp->value; } else if (strcmp(tmp->name.c_str(), "listenmqtt") == 0) { jsonDoc["listenmqtt"] = tmp->value; } else if (strcmp(tmp->name.c_str(), "logMqtt") == 0) { @@ -776,6 +784,12 @@ int getSettings(struct webserver_t *client, settingsStruct *heishamonSettings) { itoa(heishamonSettings->listenonly, str, 10); webserver_send_content(client, str, strlen(str)); + + webserver_send_content_P(client, PSTR(",\"force_rules\":"), 14); + + itoa(heishamonSettings->force_rules, str, 10); + webserver_send_content(client, str, strlen(str)); + } break; case 6: { char str[20]; diff --git a/HeishaMon/webfunctions.h b/HeishaMon/webfunctions.h index 6df994f6..f83f5cf4 100644 --- a/HeishaMon/webfunctions.h +++ b/HeishaMon/webfunctions.h @@ -48,6 +48,7 @@ struct settingsStruct { char mqtt_topic_listen[128] = "master_panasonic_heat_pump"; char ntp_servers[254] = "pool.ntp.org"; + bool force_rules = false; //force rules on boot, even after a crash bool listenonly = false; //listen only so heishamon can be installed parallel to cz-taw1, set commands will not work though bool listenmqtt = false; //do we get heatpump data from another heishamon over mqtt? bool optionalPCB = false; //do we emulate an optional PCB? From ae7c5ab5c216974547b51fae11632602f4b0a314 Mon Sep 17 00:00:00 2001 From: CurlyMoo Date: Sun, 3 Nov 2024 17:32:14 +0100 Subject: [PATCH 2/6] Fix wrong condition --- HeishaMon/HeishaMon.ino | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/HeishaMon/HeishaMon.ino b/HeishaMon/HeishaMon.ino index 51921de7..c0e73397 100644 --- a/HeishaMon/HeishaMon.ino +++ b/HeishaMon/HeishaMon.ino @@ -1467,13 +1467,18 @@ void setup() { #if defined(ESP8266) rst_info *resetInfo = ESP.getResetInfoPtr(); loggingSerial.printf(PSTR("Reset reason: %d, exception cause: %d\n"), resetInfo->reason, resetInfo->exccause); - if (resetInfo->reason > 0 && resetInfo->reason < 4) { + if (heishamonSettings->force_rules == false) { + if (resetInfo->reason > 0 && resetInfo->reason < 4) { #elif defined(ESP32) - esp_reset_reason_t reset_reason = esp_reset_reason(); - loggingSerial.printf(PSTR("Reset reason: %d\n"), reset_reason); - if (heishamonSettings->force_rules == true || (reset_reason > 3 && reset_reason < 12)) { //is this correct for esp32? + esp_reset_reason_t reset_reason = esp_reset_reason(); + loggingSerial.printf(PSTR("Reset reason: %d\n"), reset_reason); + if (reset_reason > 3 && reset_reason < 12) { //is this correct for esp32? #endif - loggingSerial.println("Not loading rules due to crash reboot!"); + loggingSerial.println("Not loading rules due to crash reboot!"); + } else { + rules_parse((char *)"/rules.txt"); + rules_boot(); + } } else { rules_parse((char *)"/rules.txt"); rules_boot(); From dbbd15c2988f9bd2f499ee9b497c99711835b69b Mon Sep 17 00:00:00 2001 From: CurlyMoo Date: Sun, 3 Nov 2024 17:34:04 +0100 Subject: [PATCH 3/6] Replace arrow with dot --- HeishaMon/HeishaMon.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HeishaMon/HeishaMon.ino b/HeishaMon/HeishaMon.ino index c0e73397..a9a68343 100644 --- a/HeishaMon/HeishaMon.ino +++ b/HeishaMon/HeishaMon.ino @@ -1467,7 +1467,7 @@ void setup() { #if defined(ESP8266) rst_info *resetInfo = ESP.getResetInfoPtr(); loggingSerial.printf(PSTR("Reset reason: %d, exception cause: %d\n"), resetInfo->reason, resetInfo->exccause); - if (heishamonSettings->force_rules == false) { + if (heishamonSettings.force_rules == false) { if (resetInfo->reason > 0 && resetInfo->reason < 4) { #elif defined(ESP32) esp_reset_reason_t reset_reason = esp_reset_reason(); From 40b4b517adca7582794162b57e3f9aedebf59eec Mon Sep 17 00:00:00 2001 From: CurlyMoo Date: Sun, 3 Nov 2024 22:57:49 +0100 Subject: [PATCH 4/6] Update upload artifact version --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 32e3b532..4cc99a6a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -48,10 +48,10 @@ jobs: - name: Add MD5 checksum to ESP32 binary run: cd HeishaMon && MD5=`md5sum HeishaMon.ino.bin | cut -d\ -f1` && mv HeishaMon.ino.bin HeishaMon_ESP32-alpha-$MD5.bin - shell: bash + shell: bash - name: Upload artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: HeishaMon.ino.bin - path: HeishaMon/HeishaMon_*.bin \ No newline at end of file + path: HeishaMon/HeishaMon_*.bin From 422e150442541175080c290992ff83f576fbba5a Mon Sep 17 00:00:00 2001 From: CurlyMoo Date: Sun, 3 Nov 2024 23:06:38 +0100 Subject: [PATCH 5/6] Fix wrong condition --- HeishaMon/HeishaMon.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HeishaMon/HeishaMon.ino b/HeishaMon/HeishaMon.ino index 95f43ce7..af4a90e9 100644 --- a/HeishaMon/HeishaMon.ino +++ b/HeishaMon/HeishaMon.ino @@ -1486,10 +1486,10 @@ void setup() { } loggingSerial.println(F("Enabling rules..")); + if (heishamonSettings.force_rules == false) { #if defined(ESP8266) rst_info *resetInfo = ESP.getResetInfoPtr(); loggingSerial.printf(PSTR("Reset reason: %d, exception cause: %d\n"), resetInfo->reason, resetInfo->exccause); - if (heishamonSettings.force_rules == false) { if (resetInfo->reason > 0 && resetInfo->reason < 4) { #elif defined(ESP32) esp_reset_reason_t reset_reason = esp_reset_reason(); From be46cfd51353df5a1ca22e50dced0d5b226353fd Mon Sep 17 00:00:00 2001 From: CurlyMoo Date: Mon, 4 Nov 2024 21:18:30 +0100 Subject: [PATCH 6/6] Fix string length --- HeishaMon/webfunctions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HeishaMon/webfunctions.cpp b/HeishaMon/webfunctions.cpp index 94232b1f..c3b81815 100755 --- a/HeishaMon/webfunctions.cpp +++ b/HeishaMon/webfunctions.cpp @@ -801,7 +801,7 @@ int getSettings(struct webserver_t *client, settingsStruct *heishamonSettings) { itoa(heishamonSettings->listenonly, str, 10); webserver_send_content(client, str, strlen(str)); - webserver_send_content_P(client, PSTR(",\"force_rules\":"), 14); + webserver_send_content_P(client, PSTR(",\"force_rules\":"), 15); itoa(heishamonSettings->force_rules, str, 10); webserver_send_content(client, str, strlen(str));