@@ -240,6 +240,24 @@ 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
+
255
+ if (_get_ota_confirmation != nullptr &&
256
+ _ota.getState () == OTACloudProcessInterface::State::OtaAvailable &&
257
+ _get_ota_confirmation ()) {
258
+ _ota.approveOta ();
259
+ }
260
+ #endif // OTA_ENABLED
243
261
}
244
262
245
263
int ArduinoIoTCloudTCP::connected ()
@@ -319,7 +337,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectMqttBroker()
319
337
320
338
ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected ()
321
339
{
322
- if (!_mqttClient.connected () || !_thing.connected () || !_device.connected ())
340
+ if (( !_mqttClient.connected () || !_thing.connected () || !_device.connected () ))
323
341
{
324
342
return State::Disconnect;
325
343
}
@@ -338,16 +356,6 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
338
356
/* Call CloudDevice process to get configuration */
339
357
_device.update ();
340
358
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
359
352
360
if (_device.isAttached ()) {
353
361
/* Call CloudThing process to synchronize properties */
0 commit comments