Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 */
Expand Down
Loading