mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 05:36:37 +00:00
No auto reboot when wifi is disconnected. Execute offline.cmd and online.cmd
This commit is contained in:
parent
5e19ee3fc7
commit
1bb974d084
@ -50,6 +50,7 @@ char wifiPassword[64] = "";
|
|||||||
#endif
|
#endif
|
||||||
char wifiIpAddress[16] = "";
|
char wifiIpAddress[16] = "";
|
||||||
uint16_t wifiReconnectCounter = 0;
|
uint16_t wifiReconnectCounter = 0;
|
||||||
|
bool wifiOnline = false;
|
||||||
|
|
||||||
// const byte DNS_PORT = 53;
|
// const byte DNS_PORT = 53;
|
||||||
// DNSServer dnsServer;
|
// DNSServer dnsServer;
|
||||||
@ -77,6 +78,12 @@ static void wifiConnected(IPAddress ipaddress)
|
|||||||
// lv_obj_move_background(msgbox);
|
// lv_obj_move_background(msgbox);
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
|
if(wifiOnline)
|
||||||
|
return; // already connected
|
||||||
|
else
|
||||||
|
wifiOnline = true; // now we are connected
|
||||||
|
|
||||||
|
wifiReconnectCounter = 0;
|
||||||
dispatch_exec(NULL, "/online.cmd", TAG_WIFI);
|
dispatch_exec(NULL, "/online.cmd", TAG_WIFI);
|
||||||
|
|
||||||
LOG_VERBOSE(TAG_WIFI, F("Connected = %s"),
|
LOG_VERBOSE(TAG_WIFI, F("Connected = %s"),
|
||||||
@ -88,14 +95,6 @@ static void wifiDisconnected(const char* ssid, uint8_t reason)
|
|||||||
{
|
{
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
|
|
||||||
// haspProgressVal(wifiReconnectCounter * 3);
|
|
||||||
// networkStop();
|
|
||||||
|
|
||||||
// if(wifiReconnectCounter > 33) {
|
|
||||||
// LOG_ERROR(TAG_WIFI, F("Retries exceed %u: Rebooting..."), wifiReconnectCounter);
|
|
||||||
// dispatch_reboot(false);
|
|
||||||
// }
|
|
||||||
|
|
||||||
switch(reason) {
|
switch(reason) {
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
case REASON_UNSPECIFIED:
|
case REASON_UNSPECIFIED:
|
||||||
@ -280,16 +279,21 @@ static void wifiDisconnected(const char* ssid, uint8_t reason)
|
|||||||
snprintf_P(buffer, sizeof(buffer), PSTR(D_ERROR_UNKNOWN));
|
snprintf_P(buffer, sizeof(buffer), PSTR(D_ERROR_UNKNOWN));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(wifiReconnectCounter % 10 == 0)
|
if(wifiReconnectCounter++ % 5 == 0)
|
||||||
LOG_WARNING(TAG_WIFI, F("Disconnected from %s (Reason: %s [%d])"), ssid, buffer, reason);
|
LOG_WARNING(TAG_WIFI, F("Disconnected from %s (Reason: %s [%d])"), ssid, buffer, reason);
|
||||||
if(wifiReconnectCounter == 0) dispatch_exec(NULL, "/offline.cmd", TAG_WIFI);
|
|
||||||
if(wifiReconnectCounter != 0xFFFF) wifiReconnectCounter++;
|
if(!wifiOnline)
|
||||||
|
return; // we were not connected
|
||||||
|
else
|
||||||
|
wifiOnline = false; // now we are disconnected
|
||||||
|
|
||||||
|
dispatch_exec(NULL, "/offline.cmd", TAG_WIFI);
|
||||||
|
networkStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wifiSsidConnected(const char* ssid)
|
static void wifiSsidConnected(const char* ssid)
|
||||||
{
|
{
|
||||||
LOG_TRACE(TAG_WIFI, F(D_WIFI_CONNECTED_TO), ssid);
|
LOG_TRACE(TAG_WIFI, F(D_WIFI_CONNECTED_TO), ssid);
|
||||||
wifiReconnectCounter = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
@ -454,8 +458,8 @@ void wifiSetup()
|
|||||||
WiFi.setSleep(false);
|
WiFi.setSleep(false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
WiFi.setAutoReconnect(true);
|
|
||||||
wifiReconnect();
|
wifiReconnect();
|
||||||
|
WiFi.setAutoReconnect(false); // done in wifiEvery5Seconds
|
||||||
LOG_TRACE(TAG_WIFI, F(D_WIFI_CONNECTING_TO), wifiSsid);
|
LOG_TRACE(TAG_WIFI, F(D_WIFI_CONNECTING_TO), wifiSsid);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -474,15 +478,8 @@ bool wifiEvery5Seconds()
|
|||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// wifiReconnectCounter++;
|
|
||||||
// if(wifiReconnectCounter > 45) {
|
|
||||||
// LOG_ERROR(TAG_WIFI, F("Retries exceeded %d: Rebooting..."), wifiReconnectCounter);
|
|
||||||
// dispatch_reboot(false);
|
|
||||||
// }
|
|
||||||
LOG_WARNING(TAG_WIFI, F("No Connection... retry %d"), wifiReconnectCounter);
|
LOG_WARNING(TAG_WIFI, F("No Connection... retry %d"), wifiReconnectCounter);
|
||||||
// if(wifiReconnectCounter % 2 == 0) {
|
wifiReconnect();
|
||||||
// wifiReconnect();
|
|
||||||
// }
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user