@@ -240,6 +240,18 @@ void ArduinoIoTCloudTCP::update()
240
240
#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
241
241
watchdog_reset ();
242
242
#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
243
255
}
244
256
245
257
int ArduinoIoTCloudTCP::connected ()
@@ -319,7 +331,15 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectMqttBroker()
319
331
320
332
ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected ()
321
333
{
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 ()))
323
343
{
324
344
return State::Disconnect;
325
345
}
@@ -338,16 +358,6 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
338
358
/* Call CloudDevice process to get configuration */
339
359
_device.update ();
340
360
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
-
351
361
352
362
if (_device.isAttached ()) {
353
363
/* Call CloudThing process to synchronize properties */
0 commit comments