Skip to content

Commit

Permalink
Merge pull request #532 from pennam/check-ota-before-disconnect
Browse files Browse the repository at this point in the history
TCP: do not disconnect if ota client is connected
  • Loading branch information
pennam authored Feb 25, 2025
2 parents 6d388e7 + 30c7001 commit 86f52c7
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,24 @@ void ArduinoIoTCloudTCP::update()
#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
watchdog_reset();
#endif

#if OTA_ENABLED
/* OTA FSM needs to reach the Idle state before being able to run independently from
* the mqttClient. The state can be reached only after the mqttClient is connected to
* the broker.
*/
if((_ota.getState() != OTACloudProcessInterface::Resume &&
_ota.getState() != OTACloudProcessInterface::OtaBegin) ||
_mqttClient.connected()) {
_ota.update();
}

if(_get_ota_confirmation != nullptr &&
_ota.getState() == OTACloudProcessInterface::State::OtaAvailable &&
_get_ota_confirmation()) {
_ota.approveOta();
}
#endif // OTA_ENABLED
}

int ArduinoIoTCloudTCP::connected()
Expand Down Expand Up @@ -338,16 +356,6 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
/* Call CloudDevice process to get configuration */
_device.update();

#if OTA_ENABLED
if(_get_ota_confirmation != nullptr &&
_ota.getState() == OTACloudProcessInterface::State::OtaAvailable &&
_get_ota_confirmation()) {
_ota.approveOta();
}

_ota.update();
#endif // OTA_ENABLED


if (_device.isAttached()) {
/* Call CloudThing process to synchronize properties */
Expand Down

0 comments on commit 86f52c7

Please sign in to comment.