Fix FOTA updates with smart sleep (#999)
This commit is contained in:
+22
-9
@@ -542,14 +542,6 @@ int8_t _sleep(const uint32_t sleepingMS, const bool smartSleep, const uint8_t in
|
||||
CORE_DEBUG(PSTR("MCO:SLP:MS=%" PRIu32 ",SMS=%" PRIu8 ",I1=%" PRIu8 ",M1=%" PRIu8 ",I2=%" PRIu8
|
||||
",M2=%" PRIu8 "\n"), sleepingMS, smartSleep,
|
||||
interrupt1, mode1, interrupt2, mode2);
|
||||
// OTA FW feature: do not sleep if FW update ongoing
|
||||
#if defined(MY_OTA_FIRMWARE_FEATURE)
|
||||
if (isFirmwareUpdateOngoing()) {
|
||||
CORE_DEBUG(PSTR("!MCO:SLP:FWUPD\n")); // sleeping not possible, FW update ongoing
|
||||
wait(sleepingMS);
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
#endif
|
||||
// repeater feature: sleeping not possible
|
||||
#if defined(MY_REPEATER_FEATURE)
|
||||
(void)smartSleep;
|
||||
@@ -583,15 +575,36 @@ int8_t _sleep(const uint32_t sleepingMS, const bool smartSleep, const uint8_t in
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
}
|
||||
// OTA FW feature: do not sleep if FW update ongoing
|
||||
#if defined(MY_OTA_FIRMWARE_FEATURE)
|
||||
while (isFirmwareUpdateOngoing() && sleepingTimeMS) {
|
||||
CORE_DEBUG(PSTR("!MCO:SLP:FWUPD\n")); // sleeping not possible, FW update ongoing
|
||||
wait(1000ul);
|
||||
sleepingTimeMS = sleepingTimeMS >= 1000ul ? sleepingTimeMS - 1000ul : 1000ul;
|
||||
}
|
||||
#endif // MY_OTA_FIRMWARE_FEATURE
|
||||
if (smartSleep) {
|
||||
// sleeping time left?
|
||||
if (sleepingTimeMS < ((uint32_t)MY_SMART_SLEEP_WAIT_DURATION_MS)) {
|
||||
wait(sleepingMS);
|
||||
CORE_DEBUG(PSTR("!MCO:SLP:NTL\n")); // sleeping not possible, no time left
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
// notify controller about going to sleep, payload indicates smartsleep waiting time in MS
|
||||
(void)_sendRoute(build(_msgTmp, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL,
|
||||
I_PRE_SLEEP_NOTIFICATION).set((uint32_t)MY_SMART_SLEEP_WAIT_DURATION_MS));
|
||||
wait(MY_SMART_SLEEP_WAIT_DURATION_MS); // listen for incoming messages
|
||||
#if defined(MY_OTA_FIRMWARE_FEATURE)
|
||||
// check if during smart sleep waiting period a FOTA request was received
|
||||
if (isFirmwareUpdateOngoing()) {
|
||||
CORE_DEBUG(PSTR("!MCO:SLP:FWUPD\n")); // sleeping not possible, FW update ongoing
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
#endif // MY_OTA_FIRMWARE_FEATURE
|
||||
}
|
||||
#else
|
||||
(void)smartSleep;
|
||||
#endif
|
||||
#endif // MY_SENSOR_NETWORK
|
||||
|
||||
#if defined(MY_SENSOR_NETWORK)
|
||||
transportDisable();
|
||||
|
||||
Reference in New Issue
Block a user