Add Wifi Link Connection Count

Add Wifi Link Connection (Retry) count to state message. Always starts with 1 being the initial connection.
This commit is contained in:
Theo Arends 2019-02-18 15:41:41 +01:00
parent a6c7e3b5f4
commit e898dc03e7
3 changed files with 12 additions and 3 deletions

View File

@ -89,6 +89,7 @@
#define D_JSON_INFRARED "Infrared" #define D_JSON_INFRARED "Infrared"
#define D_JSON_UNKNOWN "Unknown" #define D_JSON_UNKNOWN "Unknown"
#define D_JSON_LIGHT "Light" #define D_JSON_LIGHT "Light"
#define D_JSON_LINK_DOWN "LinkCount"
#define D_JSON_LOCAL_TIME "Local" #define D_JSON_LOCAL_TIME "Local"
#define D_JSON_LOW "Low" #define D_JSON_LOW "Low"
#define D_JSON_MAC "Mac" #define D_JSON_MAC "Mac"

View File

@ -1775,8 +1775,8 @@ void MqttShowState(void)
MqttShowPWMState(); 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}}"), 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())); 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) bool MqttShowSensor(void)

View File

@ -49,6 +49,7 @@ using namespace axTLS;
*/ */
#include <ESP8266WiFi.h> // Wifi, MQTT, Ota, WifiManager #include <ESP8266WiFi.h> // Wifi, MQTT, Ota, WifiManager
uint32_t wifi_link_down = 0;
uint8_t wifi_counter; uint8_t wifi_counter;
uint8_t wifi_retry_init; uint8_t wifi_retry_init;
uint8_t wifi_retry; uint8_t wifi_retry;
@ -222,7 +223,8 @@ void WifiBegin(uint8_t flag, uint8_t channel)
delay(200); delay(200);
WiFi.mode(WIFI_STA); // Disable AP mode WiFi.mode(WIFI_STA); // Disable AP mode
WiFiSetSleepMode(); 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); } if (!WiFi.getAutoConnect()) { WiFi.setAutoConnect(true); }
// WiFi.setAutoReconnect(true); // WiFi.setAutoReconnect(true);
switch (flag) { switch (flag) {
@ -339,6 +341,11 @@ void WifiBeginAfterScan()
} }
} }
uint32_t WifiLinkDown()
{
return wifi_link_down;
}
void WifiSetState(uint8_t state) void WifiSetState(uint8_t state)
{ {
if (state == global_state.wifi_down) { if (state == global_state.wifi_down) {
@ -346,6 +353,7 @@ void WifiSetState(uint8_t state)
rules_flag.wifi_connected = 1; rules_flag.wifi_connected = 1;
} else { } else {
rules_flag.wifi_disconnected = 1; rules_flag.wifi_disconnected = 1;
wifi_link_down++;
} }
} }
global_state.wifi_down = state ^1; global_state.wifi_down = state ^1;