From a99a969759e13356183b6a62cb656a634a8b8623 Mon Sep 17 00:00:00 2001 From: Niels <7136117+TheDutchDev@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:29:23 +0100 Subject: [PATCH 1/2] Update mqttmanager.h Add filter on MQTT layer to prevent memory overflow --- src/mqttmanager.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/mqttmanager.h b/src/mqttmanager.h index 778eb2a..a4fddbc 100644 --- a/src/mqttmanager.h +++ b/src/mqttmanager.h @@ -141,11 +141,13 @@ void ParseCallback(JsonDocument &messageobject){ void mqttCallback(char *topic, byte *payload, unsigned int length){ DynamicJsonDocument messageobject(mqttdocument); - auto deserializeError = deserializeJson(messageobject, payload, length); + + // Create filter to only grab "print" part from MQTT payload + StaticJsonDocument<64> filter; + filter["print"] = true; + + auto deserializeError = deserializeJson(messageobject, payload, length, DeserializationOption::Filter(filter)); if (!deserializeError){ - if (!messageobject.containsKey("print")) { - return; - } ParseCallback(messageobject); }else{ Serial.println(F("Deserialize error while parsing mqtt")); @@ -175,4 +177,4 @@ void mqttloop(){ } } -#endif \ No newline at end of file +#endif From 0bb43403bd803c7c9cfc00c2772998f2c97f74e5 Mon Sep 17 00:00:00 2001 From: Niels <7136117+TheDutchDev@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:31:04 +0100 Subject: [PATCH 2/2] Update wifi-manager.h Fix Wifi reconnect loop --- src/wifi-manager.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/wifi-manager.h b/src/wifi-manager.h index c6c1278..0854042 100644 --- a/src/wifi-manager.h +++ b/src/wifi-manager.h @@ -39,21 +39,25 @@ bool setupWifi(){ } while (connectionAttempts < maxConnectionAttempts) { + if (WiFi.status() == WL_CONNECTED) + break; + //WiFi.mode(WIFI_STA); WiFi.begin(globalVariables.SSID, globalVariables.APPW); delay(1000); - if (WiFi.status() != WL_CONNECTED){ - Serial.print(F("Connecting to WIFI.. ")); - Serial.println(globalVariables.SSID); - Serial.println(globalVariables.APPW); - delay(8000); - }; + + Serial.print(F("Connecting to WIFI.. ")); + Serial.println(globalVariables.SSID); + Serial.println(globalVariables.APPW); + delay(8000); // can probably be lower? connectionAttempts++; } + if (WiFi.status() != WL_CONNECTED){ Serial.println(F("Failed to connect to wifi.")); return false; } + int signalStrength = WiFi.RSSI(); Serial.println(F("Connected To Wifi:")); Serial.println(signalStrength); @@ -74,4 +78,4 @@ bool setupWifi(){ return true; } -#endif \ No newline at end of file +#endif