@@ -141,7 +141,7 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
141
141
addPropertyReal (_ota_error, " OTA_ERROR" , Permission::Read);
142
142
addPropertyReal (_ota_img_sha256, " OTA_SHA256" , Permission::Read);
143
143
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);
145
145
#endif /* OTA_ENABLED */
146
146
147
147
#if OTA_STORAGE_SNU
@@ -301,6 +301,19 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
301
301
*/
302
302
sendPropertiesToCloud ();
303
303
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
+
304
317
return State::Connected;
305
318
}
306
319
}
@@ -374,48 +387,36 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l
374
387
}
375
388
376
389
#if OTA_ENABLED
377
- void ArduinoIoTCloudTCP::on_OTA_REQ_Update ()
378
- {
379
- ArduinoCloud.onOTARequest ();
380
- }
381
-
382
390
void ArduinoIoTCloudTCP::onOTARequest ()
383
391
{
384
- DBG_VERBOSE (F (" ArduinoIoTCloudTCP::%s _ota_req = %s" ), __FUNCTION__, _ota_req ? " true" : " false" );
385
392
DBG_VERBOSE (F (" ArduinoIoTCloudTCP::%s _ota_url = %s" ), __FUNCTION__, _ota_url.c_str ());
386
393
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 ;
396
398
397
399
#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" );
401
403
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
+ }
410
412
411
- /* The download was a success. */
412
- ota_download_success = true ;
413
+ /* The download was a success. */
414
+ ota_download_success = true ;
413
415
#endif /* OTA_STORAGE_SNU */
414
416
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 ();
419
420
}
420
421
#endif
421
422
0 commit comments