From e898dc03e7d2ea09454817f2353ae6948bbd0774 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 18 Feb 2019 15:41:41 +0100 Subject: [PATCH] Add Wifi Link Connection Count Add Wifi Link Connection (Retry) count to state message. Always starts with 1 being the initial connection. --- sonoff/i18n.h | 1 + sonoff/sonoff.ino | 4 ++-- sonoff/support_wifi.ino | 10 +++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sonoff/i18n.h b/sonoff/i18n.h index a35161433..b5a7f7697 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -89,6 +89,7 @@ #define D_JSON_INFRARED "Infrared" #define D_JSON_UNKNOWN "Unknown" #define D_JSON_LIGHT "Light" +#define D_JSON_LINK_DOWN "LinkCount" #define D_JSON_LOCAL_TIME "Local" #define D_JSON_LOW "Low" #define D_JSON_MAC "Mac" diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 4a62d5c88..9e0f4530e 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -1775,8 +1775,8 @@ void MqttShowState(void) MqttShowPWMState(); } - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_BSSID "\":\"%s\",\"" D_JSON_CHANNEL "\":%d,\"" D_JSON_RSSI "\":%d}}"), - mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.BSSIDstr().c_str(), WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI())); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_BSSID "\":\"%s\",\"" D_JSON_CHANNEL "\":%d,\"" D_JSON_RSSI "\":%d,\"" D_JSON_LINK_DOWN "\":%d}}"), + mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.BSSIDstr().c_str(), WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI()), WifiLinkDown()); } bool MqttShowSensor(void) diff --git a/sonoff/support_wifi.ino b/sonoff/support_wifi.ino index 90f0584b7..138768138 100644 --- a/sonoff/support_wifi.ino +++ b/sonoff/support_wifi.ino @@ -49,6 +49,7 @@ using namespace axTLS; */ #include // Wifi, MQTT, Ota, WifiManager +uint32_t wifi_link_down = 0; uint8_t wifi_counter; uint8_t wifi_retry_init; uint8_t wifi_retry; @@ -222,7 +223,8 @@ void WifiBegin(uint8_t flag, uint8_t channel) delay(200); WiFi.mode(WIFI_STA); // Disable AP mode WiFiSetSleepMode(); -// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { WiFi.setPhyMode(WIFI_PHY_MODE_11N); } +// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { WiFi.setPhyMode(WIFI_PHY_MODE_11N); } // B/G/N +// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11G) { WiFi.setPhyMode(WIFI_PHY_MODE_11G); } // B/G if (!WiFi.getAutoConnect()) { WiFi.setAutoConnect(true); } // WiFi.setAutoReconnect(true); switch (flag) { @@ -339,6 +341,11 @@ void WifiBeginAfterScan() } } +uint32_t WifiLinkDown() +{ + return wifi_link_down; +} + void WifiSetState(uint8_t state) { if (state == global_state.wifi_down) { @@ -346,6 +353,7 @@ void WifiSetState(uint8_t state) rules_flag.wifi_connected = 1; } else { rules_flag.wifi_disconnected = 1; + wifi_link_down++; } } global_state.wifi_down = state ^1;