Add extra check for missing price updates

This commit is contained in:
Djuri Baars 2024-03-17 23:16:15 +01:00
parent 3e00f1b4a6
commit 37c57b7d97
3 changed files with 18 additions and 3 deletions

View File

@ -105,6 +105,10 @@ void onWebsocketPriceMessage(esp_websocket_event_data_t *event_data) {
} }
} }
uint getLastPriceUpdate() {
return lastPriceUpdate;
}
uint getPrice() { return currentPrice; } uint getPrice() { return currentPrice; }
void setPrice(uint newPrice) { currentPrice = newPrice; } void setPrice(uint newPrice) { currentPrice = newPrice; }

View File

@ -19,4 +19,5 @@ void setPrice(uint newPrice);
bool isPriceNotifyConnected(); bool isPriceNotifyConnected();
void stopPriceNotify(); void stopPriceNotify();
bool getPriceNotifyInit(); bool getPriceNotifyInit();
uint getLastPriceUpdate();

View File

@ -39,13 +39,15 @@ extern "C" void app_main() {
if (eventSourceTaskHandle != NULL) if (eventSourceTaskHandle != NULL)
xTaskNotifyGive(eventSourceTaskHandle); xTaskNotifyGive(eventSourceTaskHandle);
int64_t currentUptime = esp_timer_get_time() / 1000000;;
if (!WiFi.isConnected()) { if (!WiFi.isConnected()) {
if (!wifiLostConnection) { if (!wifiLostConnection) {
wifiLostConnection = esp_timer_get_time() / 1000000; wifiLostConnection = currentUptime;
Serial.println("Lost WiFi connection, trying to reconnect..."); Serial.println("Lost WiFi connection, trying to reconnect...");
} }
if (((esp_timer_get_time() / 1000000) - wifiLostConnection) > 600) { if ((currentUptime - wifiLostConnection) > 600) {
Serial.println("Still no connection after 10 minutes, restarting..."); Serial.println("Still no connection after 10 minutes, restarting...");
delay(2000); delay(2000);
ESP.restart(); ESP.restart();
@ -85,6 +87,14 @@ extern "C" void app_main() {
priceNotifyLostConnection = 0; priceNotifyLostConnection = 0;
} }
// if more than 5 price updates are missed, there is probably something wrong, reconnect
if ((getLastPriceUpdate() - currentUptime) > (preferences.getUInt("minSecPriceUpd", DEFAULT_SECONDS_BETWEEN_PRICE_UPDATE)*5)) {
stopPriceNotify();
setupPriceNotify();
priceNotifyLostConnection = 0;
}
vTaskDelay(pdMS_TO_TICKS(5000)); vTaskDelay(pdMS_TO_TICKS(5000));
} }
} }