Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
count # TCP dropouts - #217
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Oct 21, 2019
1 parent aefceea commit cdfd995
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
27 changes: 26 additions & 1 deletion src/MyESP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ union system_rtcmem_t {
uint8_t stability_counter;
uint8_t reset_reason;
uint8_t boot_status;
uint8_t _reserved_;
uint8_t dropout_counter;
} parts;
uint32_t value;
};
Expand Down Expand Up @@ -294,6 +294,7 @@ void MyESP::_wifiCallback(justwifi_messages_t code, char * parameter) {

if (code == MESSAGE_DISCONNECTED) {
myDebug_P(PSTR("[WIFI] Disconnected"));
_increaseSystemDropoutCounter(); // +1 to number of disconnects
_wifi_connected = false;
}

Expand Down Expand Up @@ -457,6 +458,7 @@ void MyESP::_mqtt_setup() {
mqttClient.onDisconnect([this](AsyncMqttClientDisconnectReason reason) {
if (reason == AsyncMqttClientDisconnectReason::TCP_DISCONNECTED) {
myDebug_P(PSTR("[MQTT] TCP Disconnected"));
_increaseSystemDropoutCounter(); // +1 to number of disconnects
(_mqtt_callback_f)(MQTT_DISCONNECT_EVENT, nullptr, nullptr); // call callback with disconnect
}
if (reason == AsyncMqttClientDisconnectReason::MQTT_IDENTIFIER_REJECTED) {
Expand Down Expand Up @@ -1068,13 +1070,33 @@ uint8_t MyESP::_getSystemStabilityCounter() {
return data.parts.stability_counter;
}

uint8_t MyESP::_getSystemDropoutCounter() {
system_rtcmem_t data;
data.value = Rtcmem->sys;
return data.parts.dropout_counter;
}

void MyESP::_setSystemStabilityCounter(uint8_t counter) {
system_rtcmem_t data;
data.value = Rtcmem->sys;
data.parts.stability_counter = counter;
Rtcmem->sys = data.value;
}

void MyESP::_setSystemDropoutCounter(uint8_t counter) {
system_rtcmem_t data;
data.value = Rtcmem->sys;
data.parts.dropout_counter = counter;
Rtcmem->sys = data.value;
}

void MyESP::_increaseSystemDropoutCounter() {
system_rtcmem_t data;
data.value = Rtcmem->sys;
data.parts.dropout_counter++;
Rtcmem->sys = data.value;
}

uint8_t MyESP::_getSystemResetReason() {
system_rtcmem_t data;
data.value = Rtcmem->sys;
Expand Down Expand Up @@ -1302,6 +1324,7 @@ void MyESP::showSystemStats() {
myDebug_P(PSTR(" [SYSTEM] Last reset info: %s"), (char *)ESP.getResetInfo().c_str());
}
myDebug_P(PSTR(" [SYSTEM] Restart count: %d"), _getSystemStabilityCounter());
myDebug_P(PSTR(" [SYSTEM] # TCP disconnects: %d"), _getSystemDropoutCounter());

myDebug_P(PSTR(" [SYSTEM] rtcmem status: blocks:%u addr:0x%p"), RtcmemSize, Rtcmem);
for (uint8_t block = 0; block < RtcmemSize; ++block) {
Expand Down Expand Up @@ -2918,6 +2941,8 @@ void MyESP::begin(const char * app_hostname, const char * app_name, const char *
_setSystemCheck(false); // reset system check
_heartbeatCheck(true); // force heartbeat

_setSystemDropoutCounter(0); // reset # TCP dropouts

SerialAndTelnet.flush();
}

Expand Down
4 changes: 4 additions & 0 deletions src/MyESP.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ class MyESP {
uint8_t _getSystemStabilityCounter();
void _setSystemStabilityCounter(uint8_t counter);

uint8_t _getSystemDropoutCounter();
void _setSystemDropoutCounter(uint8_t counter);
void _increaseSystemDropoutCounter();

void _setSystemResetReason(uint8_t reason);
uint8_t _getCustomResetReason();
void _setCustomResetReason(uint8_t reason);
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define APP_VERSION "1.9.3b1"
#define APP_VERSION "1.9.3b2"

0 comments on commit cdfd995

Please sign in to comment.