on IoT device, ESP8266 Arduino, I've have some issue with random disconnections
User can set SSID and PASSWORD with an APP, so the code hase been a little modified starting from standard samples
cutting here below some snippets of my code
void setup()
{
Serial.begin(115200);
WiFi.setAutoConnect(false)
WiFi.setAutoReconnect(true);
WiFi.hostname(("MYDEVICE_" + serialNumber).c_str());
if (AP)
{
turnAP(true);
}
else if (WIFI)
{
WiFi.mode(WIFI_STA);
connectToWiFi(&ssid[0], &pass[0]);
}
else
{
WiFi.mode(WIFI_OFF);
}
loopCounter = 0;
} // setup
void loop()
{
if (WiFi.status() == WL_CONNECTED)
{
if (lastConnectionState != WL_CONNECTED)
{
initWebSocket();
connectWebSocket();
}
else
{
webSocket.loop();
}
}
//Connection error during NORMAL BEHAVIOUR
else if ((WiFi.status() == WL_NO_SSID_AVAIL ||
WiFi.status() == WL_CONNECT_FAILED ||
WiFi.status() == WL_CONNECTION_LOST) && !accessPointIsOn)
{
handleNetworkError(false);
}
//Connection error during AP
else if ((WiFi.status() == WL_NO_SSID_AVAIL ||
WiFi.status() == WL_CONNECT_FAILED ||
WiFi.status() == WL_CONNECTION_LOST) && accessPointIsOn)
{
lastConnectionError = WiFiStatusToString();
WiFi.disconnect();
delay(50);
}
lastConnectionState = WiFi.status();
loopCounter++;
}
Everithing works fine but sometimes, randomly, maybe after one hour or one week, I find the ESP not connected
I know... I used WiFi.setAutoConnect(false)
The reason is that I noticed that wiithout it, changing SSID after setup seems to be difficult
Without that, ESP starts immediately with automatic connection and this does not allow me to change SSID/PWD
setAutoReconnect works fine. In Fact, i I restart the router, ESP reconnect automatically
The proble is, don't know why, but sometimes I find ESP not connected
WHat I missing?
Is anybody can help me please ?
Thanks