Skip to content

Commit

Permalink
fix #99, mqtt reconnect after wifi drop
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Aug 18, 2021
1 parent 7421f3e commit 165dd3b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
7 changes: 1 addition & 6 deletions src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,9 @@ class System {
ethernet_connected_ = b;
}

void network_connected(bool b) {
network_connected_ = b;
}

bool network_connected() {
#ifndef EMSESP_STANDALONE
return network_connected_;
return (ethernet_connected() || WiFi.isConnected());
#else
return true;
#endif
Expand Down Expand Up @@ -160,7 +156,6 @@ class System {
uint32_t last_system_check_ = 0;
bool upload_status_ = false; // true if we're in the middle of a OTA firmware upload
bool ethernet_connected_ = false;
bool network_connected_ = false;
uint16_t analog_;

// settings
Expand Down
6 changes: 0 additions & 6 deletions src/web/WebStatusService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
switch (event) {
case SYSTEM_EVENT_STA_DISCONNECTED:
EMSESP::logger().info(F("WiFi Disconnected. Reason code=%d"), info.disconnected.reason);
EMSESP::system_.network_connected(false);
break;

case SYSTEM_EVENT_STA_GOT_IP:
Expand All @@ -44,7 +43,6 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
#endif
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
if (!networkSettings.enableIPv6) {
EMSESP::system_.network_connected(true);
EMSESP::system_.send_heartbeat();
EMSESP::system_.syslog_start();
}
Expand All @@ -64,7 +62,6 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
#endif
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
if (!networkSettings.enableIPv6) {
EMSESP::system_.network_connected(true);
EMSESP::system_.send_heartbeat();
EMSESP::system_.syslog_start();
}
Expand All @@ -76,13 +73,11 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
case SYSTEM_EVENT_ETH_DISCONNECTED:
EMSESP::logger().info(F("Ethernet Disconnected"));
EMSESP::system_.ethernet_connected(false);
EMSESP::system_.network_connected(false);
break;

case SYSTEM_EVENT_ETH_STOP:
EMSESP::logger().info(F("Ethernet Stopped"));
EMSESP::system_.ethernet_connected(false);
EMSESP::system_.network_connected(false);
break;

#ifndef EMSESP_STANDALONE
Expand All @@ -108,7 +103,6 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
} else {
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_.syslog_start();
break;
Expand Down

0 comments on commit 165dd3b

Please sign in to comment.