Skip to content

Commit

Permalink
network/mqtt init fix emsesp#42
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Sep 9, 2022
1 parent 9ae8177 commit ce395f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
9 changes: 1 addition & 8 deletions lib/framework/MqttSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,10 @@ void MqttSettingsService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
switch (event) {
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
case ARDUINO_EVENT_ETH_GOT_IP:
emsesp::EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {

This comment has been minimized.

Copy link
@daviessm

daviessm Sep 9, 2022

With zero Arduino knowledge will this not stop a reconfigure when a v4 address is gained?

if (!networkSettings.enableIPv6 && _state.enabled) {
// emsesp::EMSESP::logger().info(F("IPv4 Network connection found, starting MQTT client"));
onConfigUpdated();
}
});
break;
case ARDUINO_EVENT_ETH_GOT_IP6:
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
if (_state.enabled) {
// emsesp::EMSESP::logger().info(F("IPv6 Network connection found, starting MQTT client"));

This comment has been minimized.

Copy link
@daviessm

daviessm Sep 9, 2022

Or does this event get fired for both v4 and v6 address changes? (in which case the commented code should probably say which)

This comment has been minimized.

Copy link
@MichaelDvP

MichaelDvP Sep 9, 2022

Author Owner

Now the reconfigure is triggert every time a ip, (v4 or v6) is changed.
GOT_IPV6 is only fired on v6 addresses, GOT_IP is fired for v4.

// emsesp::EMSESP::logger().info(F("IPv4 Network connection found, starting MQTT client"));
onConfigUpdated();
}
break;
Expand Down
22 changes: 7 additions & 15 deletions src/web/WebStatusService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,8 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
#ifndef EMSESP_STANDALONE
EMSESP::logger().info(F("WiFi connected with IP=%s, hostname=%s"), WiFi.localIP().toString().c_str(), WiFi.getHostname());
#endif
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
if (!networkSettings.enableIPv6) {
EMSESP::system_.send_heartbeat();
EMSESP::system_.syslog_init();
}
});
// EMSESP::system_.send_heartbeat(); // send from mqtt start
EMSESP::system_.syslog_init();
mDNS_start();
break;

Expand All @@ -70,12 +66,8 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
#ifndef EMSESP_STANDALONE
EMSESP::logger().info(F("Ethernet connected with IP=%s, speed %d Mbps"), ETH.localIP().toString().c_str(), ETH.linkSpeed());
#endif
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
if (!networkSettings.enableIPv6) {
EMSESP::system_.send_heartbeat();
EMSESP::system_.syslog_init();
}
});
// EMSESP::system_.send_heartbeat();
EMSESP::system_.syslog_init();
EMSESP::system_.ethernet_connected(true);
mDNS_start();
}
Expand Down Expand Up @@ -111,11 +103,11 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
case ARDUINO_EVENT_ETH_GOT_IP6:
if (EMSESP::system_.ethernet_connected()) {
EMSESP::logger().info(F("Ethernet connected with IP=%s, speed %d Mbps"), ETH.localIPv6().toString().c_str(), ETH.linkSpeed());
EMSESP::logger().info(F("Ethernet connected with IPv6=%s, speed %d Mbps"), ETH.localIPv6().toString().c_str(), ETH.linkSpeed());
} 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 IPv6=%s, hostname=%s"), WiFi.localIPv6().toString().c_str(), WiFi.getHostname());
}
EMSESP::system_.send_heartbeat();
// EMSESP::system_.send_heartbeat();
EMSESP::system_.syslog_init();
mDNS_start();
break;
Expand Down

0 comments on commit ce395f4

Please sign in to comment.