diff --git a/src/main.cpp b/src/main.cpp index 52e1ab9..6a5954f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,7 @@ #include "serialmanager.h" #include "wifi-manager.h" - +int wifi_reconnect_count = 0; void defaultcolors(){ Serial.println(F("Setting default customisable colors")); printerConfig.runningColor = hex2rgb("#000000",255,255);//WHITE Running @@ -86,7 +86,8 @@ void setup(){ Serial.println(F(" **")); Serial.println(); globalVariables.started = true; - + Serial.println(F("Updating LEDs from Setup")); + updateleds(); } void loop(){ @@ -97,12 +98,22 @@ void loop(){ ledsloop(); if (WiFi.status() != WL_CONNECTED){ - if (WiFi.status() == WL_DISCONNECTED) Serial.print(F("Wifi connection Disconnected. ")); - + Serial.print(F("Wifi connection dropped. ")); + Serial.print(F("Wifi Status: ")); + Serial.println(wl_status_to_string(WiFi.status())); Serial.println(F("Attempting to reconnect to WiFi...")); - WiFi.disconnect(); - delay(10); - WiFi.reconnect(); + wifi_reconnect_count += 1; + if(wifi_reconnect_count <= 2){ + WiFi.disconnect(); + delay(100); + WiFi.reconnect(); + } else { + //Not connecting after 10 simple disconnect / reconnects + //Do something more drastic in case needing to switch to new AP + scanNetwork(); + connectToWifi(); + wifi_reconnect_count = 0; + } } } if(printerConfig.rescanWiFiNetwork) diff --git a/src/mqttmanager.h b/src/mqttmanager.h index 1e162ee..1ebca38 100644 --- a/src/mqttmanager.h +++ b/src/mqttmanager.h @@ -55,8 +55,8 @@ void connectMqtt(){ mqttClient.subscribe(report_topic.c_str()); printerVariables.online = true; printerVariables.disconnectMQTTms = 0; - Serial.println(F("Updating LEDs from MQTT connect")); - updateleds(); + //Serial.println(F("Updating LEDs from MQTT connect")); + //updateleds(); }else{ Serial.println(F("Failed to connect with error code: ")); Serial.print(mqttClient.state()); @@ -93,7 +93,7 @@ void ParseCallback(char *topic, byte *payload, unsigned int length){ auto deserializeError = deserializeJson(messageobject, payload, length, DeserializationOption::Filter(filter)); if (!deserializeError){ if (printerConfig.debuging){ - Serial.print(F("Mqtt message received, ")); + Serial.println(F("Mqtt message received.")); Serial.print(F("FreeHeap: ")); Serial.println(ESP.getFreeHeap()); } @@ -106,6 +106,7 @@ void ParseCallback(char *topic, byte *payload, unsigned int length){ || messageobject["print"]["command"] == "project_file" //1 message per print || messageobject["print"]["command"] == "clean_print_error" //During error (no info) || messageobject["print"]["command"] == "resume" //After error or pause + || messageobject["print"]["command"] == "get_accessories" //After error or pause || messageobject["print"]["command"] == "prepare"){ //1 message per print return; }