From 30c700113348c7874c31a38968ae2056f47f2dbc Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 19 Feb 2025 10:25:51 +0100 Subject: [PATCH] TCP: do not disconnect if ota client is connected --- src/ArduinoIoTCloudTCP.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index f3ca4c40..878a5c3b 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -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() @@ -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 */