mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
fix #99, mqtt reconnect after wifi drop
This commit is contained in:
@@ -106,13 +106,9 @@ class System {
|
|||||||
ethernet_connected_ = b;
|
ethernet_connected_ = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
void network_connected(bool b) {
|
|
||||||
network_connected_ = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool network_connected() {
|
bool network_connected() {
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
return network_connected_;
|
return (ethernet_connected() || WiFi.isConnected());
|
||||||
#else
|
#else
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
@@ -160,7 +156,6 @@ class System {
|
|||||||
uint32_t last_system_check_ = 0;
|
uint32_t last_system_check_ = 0;
|
||||||
bool upload_status_ = false; // true if we're in the middle of a OTA firmware upload
|
bool upload_status_ = false; // true if we're in the middle of a OTA firmware upload
|
||||||
bool ethernet_connected_ = false;
|
bool ethernet_connected_ = false;
|
||||||
bool network_connected_ = false;
|
|
||||||
uint16_t analog_;
|
uint16_t analog_;
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
|
|||||||
switch (event) {
|
switch (event) {
|
||||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||||
EMSESP::logger().info(F("WiFi Disconnected. Reason code=%d"), info.disconnected.reason);
|
EMSESP::logger().info(F("WiFi Disconnected. Reason code=%d"), info.disconnected.reason);
|
||||||
EMSESP::system_.network_connected(false);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SYSTEM_EVENT_STA_GOT_IP:
|
case SYSTEM_EVENT_STA_GOT_IP:
|
||||||
@@ -44,7 +43,6 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
|
|||||||
#endif
|
#endif
|
||||||
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
|
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
|
||||||
if (!networkSettings.enableIPv6) {
|
if (!networkSettings.enableIPv6) {
|
||||||
EMSESP::system_.network_connected(true);
|
|
||||||
EMSESP::system_.send_heartbeat();
|
EMSESP::system_.send_heartbeat();
|
||||||
EMSESP::system_.syslog_start();
|
EMSESP::system_.syslog_start();
|
||||||
}
|
}
|
||||||
@@ -64,7 +62,6 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
|
|||||||
#endif
|
#endif
|
||||||
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
|
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
|
||||||
if (!networkSettings.enableIPv6) {
|
if (!networkSettings.enableIPv6) {
|
||||||
EMSESP::system_.network_connected(true);
|
|
||||||
EMSESP::system_.send_heartbeat();
|
EMSESP::system_.send_heartbeat();
|
||||||
EMSESP::system_.syslog_start();
|
EMSESP::system_.syslog_start();
|
||||||
}
|
}
|
||||||
@@ -76,13 +73,11 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
|
|||||||
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
||||||
EMSESP::logger().info(F("Ethernet Disconnected"));
|
EMSESP::logger().info(F("Ethernet Disconnected"));
|
||||||
EMSESP::system_.ethernet_connected(false);
|
EMSESP::system_.ethernet_connected(false);
|
||||||
EMSESP::system_.network_connected(false);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SYSTEM_EVENT_ETH_STOP:
|
case SYSTEM_EVENT_ETH_STOP:
|
||||||
EMSESP::logger().info(F("Ethernet Stopped"));
|
EMSESP::logger().info(F("Ethernet Stopped"));
|
||||||
EMSESP::system_.ethernet_connected(false);
|
EMSESP::system_.ethernet_connected(false);
|
||||||
EMSESP::system_.network_connected(false);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
@@ -108,7 +103,6 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
|
|||||||
} else {
|
} else {
|
||||||
EMSESP::logger().info(F("WiFi Connected with IP=%s, hostname=%s"), WiFi.localIPv6().toString().c_str(), WiFi.getHostname());
|
EMSESP::logger().info(F("WiFi Connected with IP=%s, hostname=%s"), WiFi.localIPv6().toString().c_str(), WiFi.getHostname());
|
||||||
}
|
}
|
||||||
EMSESP::system_.network_connected(true);
|
|
||||||
EMSESP::system_.send_heartbeat();
|
EMSESP::system_.send_heartbeat();
|
||||||
EMSESP::system_.syslog_start();
|
EMSESP::system_.syslog_start();
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user