Add extra check for missing price updates
This commit is contained in:
parent
3e00f1b4a6
commit
37c57b7d97
3 changed files with 18 additions and 3 deletions
|
@ -105,6 +105,10 @@ void onWebsocketPriceMessage(esp_websocket_event_data_t *event_data) {
|
|||
}
|
||||
}
|
||||
|
||||
uint getLastPriceUpdate() {
|
||||
return lastPriceUpdate;
|
||||
}
|
||||
|
||||
uint getPrice() { return currentPrice; }
|
||||
|
||||
void setPrice(uint newPrice) { currentPrice = newPrice; }
|
||||
|
|
|
@ -20,3 +20,4 @@ void setPrice(uint newPrice);
|
|||
bool isPriceNotifyConnected();
|
||||
void stopPriceNotify();
|
||||
bool getPriceNotifyInit();
|
||||
uint getLastPriceUpdate();
|
14
src/main.cpp
14
src/main.cpp
|
@ -39,13 +39,15 @@ extern "C" void app_main() {
|
|||
if (eventSourceTaskHandle != NULL)
|
||||
xTaskNotifyGive(eventSourceTaskHandle);
|
||||
|
||||
int64_t currentUptime = esp_timer_get_time() / 1000000;;
|
||||
|
||||
if (!WiFi.isConnected()) {
|
||||
if (!wifiLostConnection) {
|
||||
wifiLostConnection = esp_timer_get_time() / 1000000;
|
||||
wifiLostConnection = currentUptime;
|
||||
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...");
|
||||
delay(2000);
|
||||
ESP.restart();
|
||||
|
@ -85,6 +87,14 @@ extern "C" void app_main() {
|
|||
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));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue