Add LinkCount and MqttCount

* Add property LinkCount to state and status 11 message representing number of Wifi Link re-connections
 * Add property MqttCount to status 6 message representing number of Mqtt re-connections
This commit is contained in:
Theo Arends 2019-02-18 17:05:25 +01:00
parent 0658ae1959
commit 4884a94b6d
5 changed files with 19 additions and 9 deletions

View File

@ -5,6 +5,8 @@
* Add rule expression enabled by define USE_EXPRESSION in my_user_config.h (#5210)
* Add Configure Template menu option to GUI (#5222)
* Remove command SetOption62 as it's functionality is replaced by user changing the device template (#5255)
* Add property LinkCount to state and status 11 message representing number of Wifi Link re-connections
* Add property MqttCount to status 6 message representing number of Mqtt re-connections
*
* 6.4.1.16 20190211
* Initial support for online template change using command Template or GUI Configure Other (#5177)

View File

@ -89,13 +89,14 @@
#define D_JSON_INFRARED "Infrared"
#define D_JSON_UNKNOWN "Unknown"
#define D_JSON_LIGHT "Light"
#define D_JSON_LINK_DOWN "LinkCount"
#define D_JSON_LINK_COUNT "LinkCount"
#define D_JSON_LOCAL_TIME "Local"
#define D_JSON_LOW "Low"
#define D_JSON_MAC "Mac"
#define D_JSON_MASK "Mask"
#define D_JSON_MINIMAL "minimal"
#define D_JSON_MODEL "Model"
#define D_JSON_MQTT_COUNT "MqttCount"
#define D_JSON_NO "No"
#define D_JSON_NOISE "Noise"
#define D_JSON_NONE "None"

View File

@ -1682,8 +1682,8 @@ void PublishStatus(uint8_t payload)
}
if (((0 == payload) || (6 == payload)) && Settings.flag.mqtt_enabled) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS D_STATUS6_MQTT "\":{\"" D_CMND_MQTTHOST "\":\"%s\",\"" D_CMND_MQTTPORT "\":%d,\"" D_CMND_MQTTCLIENT D_JSON_MASK "\":\"%s\",\"" D_CMND_MQTTCLIENT "\":\"%s\",\"" D_CMND_MQTTUSER "\":\"%s\",\"MqttType\":%d,\"MAX_PACKET_SIZE\":%d,\"KEEPALIVE\":%d}}"),
Settings.mqtt_host, Settings.mqtt_port, Settings.mqtt_client, mqtt_client, Settings.mqtt_user, MqttLibraryType(), MQTT_MAX_PACKET_SIZE, MQTT_KEEPALIVE);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS D_STATUS6_MQTT "\":{\"" D_CMND_MQTTHOST "\":\"%s\",\"" D_CMND_MQTTPORT "\":%d,\"" D_CMND_MQTTCLIENT D_JSON_MASK "\":\"%s\",\"" D_CMND_MQTTCLIENT "\":\"%s\",\"" D_CMND_MQTTUSER "\":\"%s\",\"MqttType\":%d,\"" D_JSON_MQTT_COUNT "\":%d,\"MAX_PACKET_SIZE\":%d,\"KEEPALIVE\":%d}}"),
Settings.mqtt_host, Settings.mqtt_port, Settings.mqtt_client, mqtt_client, Settings.mqtt_user, MqttLibraryType(), MqttConnectCount(), MQTT_MAX_PACKET_SIZE, MQTT_KEEPALIVE);
MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "6"));
}
@ -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,\"" 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());
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_COUNT "\":%d}}"),
mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.BSSIDstr().c_str(), WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI()), WifiLinkCount());
}
bool MqttShowSensor(void)

View File

@ -49,7 +49,7 @@ using namespace axTLS;
*/
#include <ESP8266WiFi.h> // Wifi, MQTT, Ota, WifiManager
uint32_t wifi_link_down = 0;
uint16_t wifi_link_count = 0;
uint8_t wifi_counter;
uint8_t wifi_retry_init;
uint8_t wifi_retry;
@ -341,9 +341,9 @@ void WifiBeginAfterScan()
}
}
uint32_t WifiLinkDown()
uint16_t WifiLinkCount()
{
return wifi_link_down;
return wifi_link_count;
}
void WifiSetState(uint8_t state)
@ -351,9 +351,9 @@ void WifiSetState(uint8_t state)
if (state == global_state.wifi_down) {
if (state) {
rules_flag.wifi_connected = 1;
wifi_link_count++;
} else {
rules_flag.wifi_disconnected = 1;
wifi_link_down++;
}
}
global_state.wifi_down = state ^1;

View File

@ -73,6 +73,7 @@ const char kMqttCommands[] PROGMEM =
D_CMND_MQTTUSER "|" D_CMND_MQTTPASSWORD "|" D_CMND_FULLTOPIC "|" D_CMND_PREFIX "|" D_CMND_GROUPTOPIC "|" D_CMND_TOPIC "|" D_CMND_PUBLISH "|"
D_CMND_BUTTONTOPIC "|" D_CMND_SWITCHTOPIC "|" D_CMND_BUTTONRETAIN "|" D_CMND_SWITCHRETAIN "|" D_CMND_POWERRETAIN "|" D_CMND_SENSORRETAIN ;
uint16_t mqtt_connect_count = 0; // MQTT re-connect count
uint16_t mqtt_retry_counter = 1; // MQTT connection retry counter
uint8_t mqtt_initial_connection_state = 2; // MQTT connection messages state
bool mqtt_connected = false; // MQTT virtual connection status
@ -379,6 +380,11 @@ void MqttPublishPowerBlinkState(uint8_t device)
/*********************************************************************************************/
uint16_t MqttConnectCount()
{
return mqtt_connect_count;
}
void MqttDisconnected(int state)
{
mqtt_connected = false;
@ -398,6 +404,7 @@ void MqttConnected(void)
AddLog_P(LOG_LEVEL_INFO, S_LOG_MQTT, PSTR(D_CONNECTED));
mqtt_connected = true;
mqtt_retry_counter = 0;
mqtt_connect_count++;
GetTopic_P(stopic, TELE, mqtt_topic, S_LWT);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR(D_ONLINE));