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 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