@@ -141,7 +141,7 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
141141 addPropertyReal (_ota_error, " OTA_ERROR" , Permission::Read);
142142 addPropertyReal (_ota_img_sha256, " OTA_SHA256" , Permission::Read);
143143 addPropertyReal (_ota_url, " OTA_URL" , Permission::ReadWrite).onSync (DEVICE_WINS);
144- addPropertyReal (_ota_req, " OTA_REQ" , Permission::ReadWrite).onSync (DEVICE_WINS). onUpdate (ArduinoIoTCloudTCP::on_OTA_REQ_Update) ;
144+ addPropertyReal (_ota_req, " OTA_REQ" , Permission::ReadWrite).onSync (DEVICE_WINS);
145145#endif /* OTA_ENABLED */
146146
147147#if OTA_STORAGE_SNU
@@ -301,6 +301,19 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
301301 */
302302 sendPropertiesToCloud ();
303303
304+ #if OTA_ENABLED
305+ /* Request a OTA download if the hidden property
306+ * OTA request has been set.
307+ */
308+ if (_ota_req)
309+ {
310+ /* Clear the request flag. */
311+ _ota_req = false ;
312+ /* Call member function to handle OTA request. */
313+ onOTARequest ();
314+ }
315+ #endif /* OTA_ENABLED */
316+
304317 return State::Connected;
305318 }
306319}
@@ -374,48 +387,36 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l
374387}
375388
376389#if OTA_ENABLED
377- void ArduinoIoTCloudTCP::on_OTA_REQ_Update ()
378- {
379- ArduinoCloud.onOTARequest ();
380- }
381-
382390void ArduinoIoTCloudTCP::onOTARequest ()
383391{
384- DBG_VERBOSE (F (" ArduinoIoTCloudTCP::%s _ota_req = %s" ), __FUNCTION__, _ota_req ? " true" : " false" );
385392 DBG_VERBOSE (F (" ArduinoIoTCloudTCP::%s _ota_url = %s" ), __FUNCTION__, _ota_url.c_str ());
386393
387- if (_ota_req)
388- {
389- /* Clear the request flag. */
390- _ota_req = false ;
391-
392- /* Status flag to prevent the reset from being executed
393- * when HTTPS download is not supported.
394- */
395- bool ota_download_success = false ;
394+ /* Status flag to prevent the reset from being executed
395+ * when HTTPS download is not supported.
396+ */
397+ bool ota_download_success = false ;
396398
397399#if OTA_STORAGE_SNU
398- /* Just to be safe delete any remains from previous updates. */
399- WiFiStorage.remove (" /fs/UPDATE.BIN.LZSS" );
400- WiFiStorage.remove (" /fs/UPDATE.BIN.LZSS.TMP" );
400+ /* Just to be safe delete any remains from previous updates. */
401+ WiFiStorage.remove (" /fs/UPDATE.BIN.LZSS" );
402+ WiFiStorage.remove (" /fs/UPDATE.BIN.LZSS.TMP" );
401403
402- /* Trigger direct download to nina module. */
403- uint8_t nina_ota_err_code = 0 ;
404- if (!WiFiStorage.downloadOTA (_ota_url.c_str (), &nina_ota_err_code))
405- {
406- DBG_ERROR (F (" ArduinoIoTCloudTCP::%s error download to nina: %d" ), __FUNCTION__, nina_ota_err_code);
407- _ota_error = static_cast <int >(OTAError::DownloadFailed);
408- return ;
409- }
404+ /* Trigger direct download to nina module. */
405+ uint8_t nina_ota_err_code = 0 ;
406+ if (!WiFiStorage.downloadOTA (_ota_url.c_str (), &nina_ota_err_code))
407+ {
408+ DBG_ERROR (F (" ArduinoIoTCloudTCP::%s error download to nina: %d" ), __FUNCTION__, nina_ota_err_code);
409+ _ota_error = static_cast <int >(OTAError::DownloadFailed);
410+ return ;
411+ }
410412
411- /* The download was a success. */
412- ota_download_success = true ;
413+ /* The download was a success. */
414+ ota_download_success = true ;
413415#endif /* OTA_STORAGE_SNU */
414416
415- /* Perform the reset to reboot to SxU. */
416- if (ota_download_success)
417- NVIC_SystemReset ();
418- }
417+ /* Perform the reset to reboot to SxU. */
418+ if (ota_download_success)
419+ NVIC_SystemReset ();
419420}
420421#endif
421422
0 commit comments