Only stop everything while updating for a minute
This commit is contained in:
parent
f1f18bb028
commit
eb3c5537ad
14
src/main.cpp
14
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))
|
||||
|
|
22
src/main.h
22
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue