mirror of
https://github.com/btclock/btclock_v3.git
synced 2024-11-19 06:30:02 +01:00
Add extra check for missing price updates
This commit is contained in:
parent
3e00f1b4a6
commit
37c57b7d97
@ -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; }
|
||||||
|
@ -20,3 +20,4 @@ void setPrice(uint newPrice);
|
|||||||
bool isPriceNotifyConnected();
|
bool isPriceNotifyConnected();
|
||||||
void stopPriceNotify();
|
void stopPriceNotify();
|
||||||
bool getPriceNotifyInit();
|
bool getPriceNotifyInit();
|
||||||
|
uint getLastPriceUpdate();
|
14
src/main.cpp
14
src/main.cpp
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user