From eb3c5537adf7e32790614152ca387c700112a883 Mon Sep 17 00:00:00 2001
From: DTTerastar
Date: Fri, 8 Jul 2022 18:39:38 -0400
Subject: [PATCH] Only stop everything while updating for a minute
---
src/main.cpp | 14 +++++++++-----
src/main.h | 22 +++++++++++-----------
2 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/src/main.cpp b/src/main.cpp
index 4f661c4..1225647 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -381,7 +381,7 @@ void onMqttMessage(char *topic, char *payload, AsyncMqttClientMessageProperties
void reconnect(TimerHandle_t xTimer)
{
Serial.printf("%u Reconnect timer\n", xPortGetCoreID());
- if (updateInProgress) return;
+ if (updateInProgress()) return;
if (Network.isConnected() && mqttClient.connected()) return;
if (reconnectTries++ > 50)
@@ -457,7 +457,7 @@ void reportTask(void *parameter)
while (true)
{
- while (updateInProgress || !mqttClient.connected())
+ while (updateInProgress() || !mqttClient.connected())
delay(1000);
yield();
@@ -516,9 +516,13 @@ void scanTask(void *parameter)
if (f->query())
totalFpQueried++;
- while (updateInProgress)
- delay(1000);
-
+ if (updateInProgress())
+ {
+ fingerprints.setDisable(true);
+ while (updateInProgress())
+ delay(1000);
+ fingerprints.setDisable(false);
+ }
if (!pBLEScan->isScanning())
{
if (!pBLEScan->start(0, nullptr, true))
diff --git a/src/main.h b/src/main.h
index 2021caa..b908527 100644
--- a/src/main.h
+++ b/src/main.h
@@ -38,8 +38,8 @@
TimerHandle_t reconnectTimer;
TaskHandle_t scanTaskHandle, reportTaskHandle;
-bool updateInProgress = false;
-unsigned long lastTeleMillis;
+unsigned long updateStartedMillis = 0;
+unsigned long lastTeleMillis = 0;
int reconnectTries = 0;
int teleFails = 0;
bool online = false; // Have we successfully sent status=online
@@ -55,6 +55,10 @@ bool discovery, activeScan, publishTele, publishRooms, publishDevices;
BleFingerprintCollection fingerprints;
+bool updateInProgress() {
+ return updateStartedMillis > 0 && millis() - updateStartedMillis < 60000;
+}
+
String resetReason(RESET_REASON reason)
{
#ifdef ARDUINO_ARCH_ESP32C3
@@ -127,13 +131,11 @@ void configureOTA()
.onStart([]()
{
Serial.println("OTA Start");
- updateInProgress = true;
- fingerprints.setDisable(updateInProgress);
+ updateStartedMillis = millis();
})
.onEnd([]()
{
- updateInProgress = false;
- fingerprints.setDisable(updateInProgress);
+ updateStartedMillis = 0;
GUI::updateEnd();
Serial.println("\n\rEnd");
})
@@ -154,7 +156,7 @@ void configureOTA()
Serial.println("Receive Failed");
else if (error == OTA_END_ERROR)
Serial.println("End Failed");
- updateInProgress = false;
+ updateStartedMillis = 0;
});
ArduinoOTA.setHostname(WiFi.getHostname());
ArduinoOTA.setPort(3232);
@@ -197,10 +199,9 @@ void firmwareUpdate()
}
#endif
- updateInProgress = true;
+ updateStartedMillis = millis();
mqttClient.disconnect();
NimBLEDevice::getScan()->stop();
- fingerprints.setDisable(updateInProgress);
GUI::updateStart();
httpUpdate.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
httpUpdate.onProgress([](int progress, int total)
@@ -225,8 +226,7 @@ void firmwareUpdate()
break;
}
- updateInProgress = false;
- fingerprints.setDisable(updateInProgress);
+ updateStartedMillis = 0;
#endif
}