@@ -240,6 +240,18 @@ void ArduinoIoTCloudTCP::update()
240240#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
241241 watchdog_reset ();
242242#endif
243+
244+ #if OTA_ENABLED
245+ /* OTA FSM needs to reach the Idle state before being able to run independently from
246+ * the mqttClient. The state can be reached only after the mqttClient is connected to
247+ * the broker.
248+ */
249+ if ((_ota.getState () != OTACloudProcessInterface::Resume &&
250+ _ota.getState () != OTACloudProcessInterface::OtaBegin) ||
251+ _mqttClient.connected ()) {
252+ _ota.update ();
253+ }
254+ #endif // OTA_ENABLED
243255}
244256
245257int ArduinoIoTCloudTCP::connected ()
@@ -319,7 +331,15 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectMqttBroker()
319331
320332ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected ()
321333{
322- if (!_mqttClient.connected () || !_thing.connected () || !_device.connected ())
334+ #if OTA_ENABLED
335+ if (_get_ota_confirmation != nullptr &&
336+ _ota.getState () == OTACloudProcessInterface::State::OtaAvailable &&
337+ _get_ota_confirmation ()) {
338+ _ota.approveOta ();
339+ }
340+ #endif // OTA_ENABLED
341+
342+ if ((!_mqttClient.connected () || !_thing.connected () || !_device.connected ()))
323343 {
324344 return State::Disconnect;
325345 }
@@ -338,16 +358,6 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
338358 /* Call CloudDevice process to get configuration */
339359 _device.update ();
340360
341- #if OTA_ENABLED
342- if (_get_ota_confirmation != nullptr &&
343- _ota.getState () == OTACloudProcessInterface::State::OtaAvailable &&
344- _get_ota_confirmation ()) {
345- _ota.approveOta ();
346- }
347-
348- _ota.update ();
349- #endif // OTA_ENABLED
350-
351361
352362 if (_device.isAttached ()) {
353363 /* Call CloudThing process to synchronize properties */
0 commit comments