@@ -270,6 +270,12 @@ void ArduinoIoTCloudTCP::update()
270270 }
271271 _state = next_state;
272272
273+ #if OTA_ENABLED
274+ if (_state > State::SubscribeDeviceTopic && _state <= State::Connected) {
275+ checkOTAreq ();
276+ }
277+ #endif /* OTA_ENABLED */
278+
273279 /* This watchdog feed is actually needed only by the RP2040 Connect because its
274280 * maximum watchdog window is 8389 ms; despite this we feed it for all
275281 * supported ARCH to keep code aligned.
@@ -568,36 +574,6 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
568574 _mqtt_data_request_retransmit = false ;
569575 }
570576
571- #if OTA_ENABLED
572- /* Request a OTA download if the hidden property
573- * OTA request has been set.
574- */
575-
576- if (_ota_req)
577- {
578- bool const ota_execution_allowed_by_user = (_get_ota_confirmation != nullptr && _get_ota_confirmation ());
579- bool const perform_ota_now = ota_execution_allowed_by_user || !_ask_user_before_executing_ota;
580- if (perform_ota_now) {
581- /* Clear the error flag. */
582- _ota_error = static_cast <int >(OTAError::None);
583- /* Clear the request flag. */
584- _ota_req = false ;
585- /* Transmit the cleared request flags to the cloud. */
586- sendDevicePropertyToCloud (" OTA_REQ" );
587- /* Call member function to handle OTA request. */
588- _ota_error = OTA::onRequest (_ota_url, _connection->getInterface ());
589- /* If something fails send the OTA error to the cloud */
590- sendDevicePropertyToCloud (" OTA_ERROR" );
591- }
592- }
593-
594- /* Check if we have received the OTA_URL property and provide
595- * echo to the cloud.
596- */
597- sendDevicePropertyToCloud (" OTA_URL" );
598-
599- #endif /* OTA_ENABLED */
600-
601577 /* Check if any properties need encoding and send them to
602578 * the cloud if necessary.
603579 */
@@ -612,6 +588,37 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
612588 }
613589}
614590
591+ #if OTA_ENABLED
592+ void ArduinoIoTCloudTCP::checkOTAreq () {
593+ /* Request a OTA download if the hidden property
594+ * OTA request has been set.
595+ */
596+
597+ if (_ota_req)
598+ {
599+ bool const ota_execution_allowed_by_user = (_get_ota_confirmation != nullptr && _get_ota_confirmation ());
600+ bool const perform_ota_now = ota_execution_allowed_by_user || !_ask_user_before_executing_ota;
601+ if (perform_ota_now) {
602+ /* Clear the error flag. */
603+ _ota_error = static_cast <int >(OTAError::None);
604+ /* Clear the request flag. */
605+ _ota_req = false ;
606+ /* Transmit the cleared request flags to the cloud. */
607+ sendDevicePropertyToCloud (" OTA_REQ" );
608+ /* Call member function to handle OTA request. */
609+ _ota_error = OTA::onRequest (_ota_url, _connection->getInterface ());
610+ /* If something fails send the OTA error to the cloud */
611+ sendDevicePropertyToCloud (" OTA_ERROR" );
612+ }
613+ }
614+
615+ /* Check if we have received the OTA_URL property and provide
616+ * echo to the cloud.
617+ */
618+ sendDevicePropertyToCloud (" OTA_URL" );
619+ }
620+ #endif /* OTA_ENABLED */
621+
615622ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Disconnect ()
616623{
617624 DEBUG_ERROR (" ArduinoIoTCloudTCP::%s MQTT client connection lost" , __FUNCTION__);
0 commit comments