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)
|
void reconnect(TimerHandle_t xTimer)
|
||||||
{
|
{
|
||||||
Serial.printf("%u Reconnect timer\n", xPortGetCoreID());
|
Serial.printf("%u Reconnect timer\n", xPortGetCoreID());
|
||||||
if (updateInProgress) return;
|
if (updateInProgress()) return;
|
||||||
if (Network.isConnected() && mqttClient.connected()) return;
|
if (Network.isConnected() && mqttClient.connected()) return;
|
||||||
|
|
||||||
if (reconnectTries++ > 50)
|
if (reconnectTries++ > 50)
|
||||||
|
@ -457,7 +457,7 @@ void reportTask(void *parameter)
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
while (updateInProgress || !mqttClient.connected())
|
while (updateInProgress() || !mqttClient.connected())
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
|
@ -516,9 +516,13 @@ void scanTask(void *parameter)
|
||||||
if (f->query())
|
if (f->query())
|
||||||
totalFpQueried++;
|
totalFpQueried++;
|
||||||
|
|
||||||
while (updateInProgress)
|
if (updateInProgress())
|
||||||
delay(1000);
|
{
|
||||||
|
fingerprints.setDisable(true);
|
||||||
|
while (updateInProgress())
|
||||||
|
delay(1000);
|
||||||
|
fingerprints.setDisable(false);
|
||||||
|
}
|
||||||
if (!pBLEScan->isScanning())
|
if (!pBLEScan->isScanning())
|
||||||
{
|
{
|
||||||
if (!pBLEScan->start(0, nullptr, true))
|
if (!pBLEScan->start(0, nullptr, true))
|
||||||
|
|
22
src/main.h
22
src/main.h
|
@ -38,8 +38,8 @@
|
||||||
TimerHandle_t reconnectTimer;
|
TimerHandle_t reconnectTimer;
|
||||||
TaskHandle_t scanTaskHandle, reportTaskHandle;
|
TaskHandle_t scanTaskHandle, reportTaskHandle;
|
||||||
|
|
||||||
bool updateInProgress = false;
|
unsigned long updateStartedMillis = 0;
|
||||||
unsigned long lastTeleMillis;
|
unsigned long lastTeleMillis = 0;
|
||||||
int reconnectTries = 0;
|
int reconnectTries = 0;
|
||||||
int teleFails = 0;
|
int teleFails = 0;
|
||||||
bool online = false; // Have we successfully sent status=online
|
bool online = false; // Have we successfully sent status=online
|
||||||
|
@ -55,6 +55,10 @@ bool discovery, activeScan, publishTele, publishRooms, publishDevices;
|
||||||
|
|
||||||
BleFingerprintCollection fingerprints;
|
BleFingerprintCollection fingerprints;
|
||||||
|
|
||||||
|
bool updateInProgress() {
|
||||||
|
return updateStartedMillis > 0 && millis() - updateStartedMillis < 60000;
|
||||||
|
}
|
||||||
|
|
||||||
String resetReason(RESET_REASON reason)
|
String resetReason(RESET_REASON reason)
|
||||||
{
|
{
|
||||||
#ifdef ARDUINO_ARCH_ESP32C3
|
#ifdef ARDUINO_ARCH_ESP32C3
|
||||||
|
@ -127,13 +131,11 @@ void configureOTA()
|
||||||
.onStart([]()
|
.onStart([]()
|
||||||
{
|
{
|
||||||
Serial.println("OTA Start");
|
Serial.println("OTA Start");
|
||||||
updateInProgress = true;
|
updateStartedMillis = millis();
|
||||||
fingerprints.setDisable(updateInProgress);
|
|
||||||
})
|
})
|
||||||
.onEnd([]()
|
.onEnd([]()
|
||||||
{
|
{
|
||||||
updateInProgress = false;
|
updateStartedMillis = 0;
|
||||||
fingerprints.setDisable(updateInProgress);
|
|
||||||
GUI::updateEnd();
|
GUI::updateEnd();
|
||||||
Serial.println("\n\rEnd");
|
Serial.println("\n\rEnd");
|
||||||
})
|
})
|
||||||
|
@ -154,7 +156,7 @@ void configureOTA()
|
||||||
Serial.println("Receive Failed");
|
Serial.println("Receive Failed");
|
||||||
else if (error == OTA_END_ERROR)
|
else if (error == OTA_END_ERROR)
|
||||||
Serial.println("End Failed");
|
Serial.println("End Failed");
|
||||||
updateInProgress = false;
|
updateStartedMillis = 0;
|
||||||
});
|
});
|
||||||
ArduinoOTA.setHostname(WiFi.getHostname());
|
ArduinoOTA.setHostname(WiFi.getHostname());
|
||||||
ArduinoOTA.setPort(3232);
|
ArduinoOTA.setPort(3232);
|
||||||
|
@ -197,10 +199,9 @@ void firmwareUpdate()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
updateInProgress = true;
|
updateStartedMillis = millis();
|
||||||
mqttClient.disconnect();
|
mqttClient.disconnect();
|
||||||
NimBLEDevice::getScan()->stop();
|
NimBLEDevice::getScan()->stop();
|
||||||
fingerprints.setDisable(updateInProgress);
|
|
||||||
GUI::updateStart();
|
GUI::updateStart();
|
||||||
httpUpdate.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
|
httpUpdate.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
|
||||||
httpUpdate.onProgress([](int progress, int total)
|
httpUpdate.onProgress([](int progress, int total)
|
||||||
|
@ -225,8 +226,7 @@ void firmwareUpdate()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateInProgress = false;
|
updateStartedMillis = 0;
|
||||||
fingerprints.setDisable(updateInProgress);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue