Skip to content

Commit 3b3e82c

Browse files
pennamandreagilardoni
authored andcommitted
TCP: do not disconnect if ota client is connected
1 parent 6d388e7 commit 3b3e82c

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/ArduinoIoTCloudTCP.cpp

+19-11
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,24 @@ 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+
255+
if(_get_ota_confirmation != nullptr &&
256+
_ota.getState() == OTACloudProcessInterface::State::OtaAvailable &&
257+
_get_ota_confirmation()) {
258+
_ota.approveOta();
259+
}
260+
#endif // OTA_ENABLED
243261
}
244262

245263
int ArduinoIoTCloudTCP::connected()
@@ -319,7 +337,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectMqttBroker()
319337

320338
ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
321339
{
322-
if (!_mqttClient.connected() || !_thing.connected() || !_device.connected())
340+
if ((!_mqttClient.connected() || !_thing.connected() || !_device.connected()))
323341
{
324342
return State::Disconnect;
325343
}
@@ -338,16 +356,6 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
338356
/* Call CloudDevice process to get configuration */
339357
_device.update();
340358

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-
351359

352360
if (_device.isAttached()) {
353361
/* Call CloudThing process to synchronize properties */

0 commit comments

Comments
 (0)