When wifi is lost OMG is going to AP mode (#220)
* When wifi is lost OMG is going to AP mode Avoid that except when OMG has never been connected to MQTT
This commit is contained in:
1 parent
d8a8d1cb07
commit
474e7ab70c
3 files changed
+18
-16
No files matched your search
+13
-13
@@ -120,6 +120,8 @@ unsigned long ReceivedSignal[array_size][2] ={{0,0},{0,0},{0,0},{0,0}};
|
|||||||
//adding this to bypass the problem of the arduino builder issue 50
|
//adding this to bypass the problem of the arduino builder issue 50
|
||||||
void callback(char*topic, byte* payload,unsigned int length);
|
void callback(char*topic, byte* payload,unsigned int length);
|
||||||
|
|
||||||
|
boolean connectedOnce = false; //indicate if we have been connected once to MQTT
|
||||||
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
@@ -202,10 +204,10 @@ boolean reconnect() {
|
|||||||
// Wait 5 seconds before retrying
|
// Wait 5 seconds before retrying
|
||||||
delay(5000);
|
delay(5000);
|
||||||
|
|
||||||
if (failure_number > 3){
|
if (failure_number > maxMQTTretry){
|
||||||
trc(F("failed connecting to mqtt at start reinit setup"));
|
trc(F("failed connecting to mqtt"));
|
||||||
#if defined(ESP8266) && !defined(ESPWifiManualSetup)
|
#if defined(ESP8266) && !defined(ESPWifiManualSetup)
|
||||||
setup_wifimanager(true);
|
if (!connectedOnce) setup_wifimanager(); // if we didn't connected once to mqtt we reset and start in AP mode again to have a chance to change the parameters
|
||||||
#elif defined(ESP32) || defined(ESPWifiManualSetup)// ESP32 case we don't use Wifi manager yet
|
#elif defined(ESP32) || defined(ESPWifiManualSetup)// ESP32 case we don't use Wifi manager yet
|
||||||
setup_wifi();
|
setup_wifi();
|
||||||
#endif
|
#endif
|
||||||
@@ -243,7 +245,7 @@ void setup()
|
|||||||
Serial.begin(SERIAL_BAUD, SERIAL_8N1, SERIAL_TX_ONLY);
|
Serial.begin(SERIAL_BAUD, SERIAL_8N1, SERIAL_TX_ONLY);
|
||||||
#endif
|
#endif
|
||||||
#if defined(ESP8266) && !defined(ESPWifiManualSetup)
|
#if defined(ESP8266) && !defined(ESPWifiManualSetup)
|
||||||
setup_wifimanager(false);
|
setup_wifimanager();
|
||||||
#else // ESP32 case we don't use Wifi manager yet
|
#else // ESP32 case we don't use Wifi manager yet
|
||||||
setup_wifi();
|
setup_wifi();
|
||||||
#endif
|
#endif
|
||||||
@@ -397,10 +399,10 @@ void setup_wifi() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(ESP8266) && !defined(ESPWifiManualSetup)
|
#elif defined(ESP8266) && !defined(ESPWifiManualSetup)
|
||||||
void setup_wifimanager(boolean reset_settings){
|
void setup_wifimanager(){
|
||||||
#ifdef cleanFS
|
#ifdef cleanFS
|
||||||
//clean FS, for testing
|
//clean FS, for testing
|
||||||
//SPIFFS.format();
|
SPIFFS.format();
|
||||||
#endif
|
#endif
|
||||||
//read configuration from FS json
|
//read configuration from FS json
|
||||||
trc("mounting FS...");
|
trc("mounting FS...");
|
||||||
@@ -462,10 +464,10 @@ void setup_wifimanager(boolean reset_settings){
|
|||||||
wifiManager.addParameter(&custom_mqtt_user);
|
wifiManager.addParameter(&custom_mqtt_user);
|
||||||
wifiManager.addParameter(&custom_mqtt_pass);
|
wifiManager.addParameter(&custom_mqtt_pass);
|
||||||
|
|
||||||
//reset settings - for testing
|
#ifdef cleanFS
|
||||||
//reset_settings = true;
|
//reset settings - for testing
|
||||||
if (reset_settings) wifiManager.resetSettings();
|
wifiManager.resetSettings();
|
||||||
|
#endif
|
||||||
//set minimu quality of signal so it ignores AP's under that quality
|
//set minimu quality of signal so it ignores AP's under that quality
|
||||||
wifiManager.setMinimumSignalQuality(MinimumWifiSignalQuality);
|
wifiManager.setMinimumSignalQuality(MinimumWifiSignalQuality);
|
||||||
|
|
||||||
@@ -579,7 +581,7 @@ void loop()
|
|||||||
digitalWrite(led_receive, HIGH);
|
digitalWrite(led_receive, HIGH);
|
||||||
}
|
}
|
||||||
digitalWrite(led_error, HIGH);
|
digitalWrite(led_error, HIGH);
|
||||||
|
connectedOnce = true;
|
||||||
client.loop();
|
client.loop();
|
||||||
|
|
||||||
#if defined(ESP8266) || defined(ESP32)
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
@@ -863,7 +865,6 @@ void trc(String msg){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void trc(int msg){
|
void trc(int msg){
|
||||||
if (TRACE) {
|
if (TRACE) {
|
||||||
Serial.println(msg);
|
Serial.println(msg);
|
||||||
@@ -876,7 +877,6 @@ void trc(unsigned int msg){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void trc(long msg){
|
void trc(long msg){
|
||||||
if (TRACE) {
|
if (TRACE) {
|
||||||
Serial.println(msg);
|
Serial.println(msg);
|
||||||
|
|||||||
+2
-1
@@ -53,7 +53,8 @@ char mqtt_port[6] = "1883";
|
|||||||
//#define ESPWifiManualSetup true //uncomment you don't want to use wifimanager for your credential settings on ESP
|
//#define ESPWifiManualSetup true //uncomment you don't want to use wifimanager for your credential settings on ESP
|
||||||
#define WifiManager_password "your_password"
|
#define WifiManager_password "your_password"
|
||||||
//#define MDNS_SD //uncomment if you want to use mdns for discovering automatically your ip server, please note that MDNS with ESP32 can cause the BLE to not work
|
//#define MDNS_SD //uncomment if you want to use mdns for discovering automatically your ip server, please note that MDNS with ESP32 can cause the BLE to not work
|
||||||
//#define cleanFS //uncomment if you want to clean the ESP memory and reenter your credentials
|
//#define cleanFS true //uncomment if you want to clean the ESP memory and reenter your credentials
|
||||||
|
#define maxMQTTretry 4 //maximum MQTT connection attempts before going to wifi setup
|
||||||
|
|
||||||
//set minimum quality of signal so it ignores AP's under that quality
|
//set minimum quality of signal so it ignores AP's under that quality
|
||||||
#define MinimumWifiSignalQuality 8
|
#define MinimumWifiSignalQuality 8
|
||||||
|
|||||||
+3
-2
@@ -51,8 +51,9 @@ char mqtt_port[6] = "1883";
|
|||||||
|
|
||||||
//#define ESPWifiManualSetup true //uncomment you don't want to use wifimanager for your credential settings on ESP
|
//#define ESPWifiManualSetup true //uncomment you don't want to use wifimanager for your credential settings on ESP
|
||||||
#define WifiManager_password "your_password"
|
#define WifiManager_password "your_password"
|
||||||
//#define MDNS_SD //comment if you don't want to use mdns for discovering automatically your ip server, please note that MDNS with ESP32 can cause the BLE to not work
|
//#define MDNS_SD //uncomment if you want to use mdns for discovering automatically your ip server, please note that MDNS with ESP32 can cause the BLE to not work
|
||||||
//#define cleanFS //uncomment if you want to clean the ESP memory and reenter your credentials
|
//#define cleanFS true //uncomment if you want to clean the ESP memory and reenter your credentials
|
||||||
|
#define maxMQTTretry 4 //maximum MQTT connection attempts before going to wifi setup
|
||||||
|
|
||||||
//set minimum quality of signal so it ignores AP's under that quality
|
//set minimum quality of signal so it ignores AP's under that quality
|
||||||
#define MinimumWifiSignalQuality 8
|
#define MinimumWifiSignalQuality 8
|
||||||
|
|||||||
Reference in new issue
Block a user