@@ -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,23 @@ 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 error flag. */
311
+ _ota_error = static_cast <int >(OTAError::None);
312
+ /* Transmit the cleared error flag to the cloud. */
313
+ sendPropertiesToCloud ();
314
+ /* Clear the request flag. */
315
+ _ota_req = false ;
316
+ /* Call member function to handle OTA request. */
317
+ onOTARequest ();
318
+ }
319
+ #endif /* OTA_ENABLED */
320
+
304
321
return State::Connected;
305
322
}
306
323
}
@@ -374,48 +391,36 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l
374
391
}
375
392
376
393
#if OTA_ENABLED
377
- void ArduinoIoTCloudTCP::on_OTA_REQ_Update ()
378
- {
379
- ArduinoCloud.onOTARequest ();
380
- }
381
-
382
394
void ArduinoIoTCloudTCP::onOTARequest ()
383
395
{
384
- DBG_VERBOSE (F (" ArduinoIoTCloudTCP::%s _ota_req = %s" ), __FUNCTION__, _ota_req ? " true" : " false" );
385
396
DBG_VERBOSE (F (" ArduinoIoTCloudTCP::%s _ota_url = %s" ), __FUNCTION__, _ota_url.c_str ());
386
397
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 ;
398
+ /* Status flag to prevent the reset from being executed
399
+ * when HTTPS download is not supported.
400
+ */
401
+ bool ota_download_success = false ;
396
402
397
403
#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" );
404
+ /* Just to be safe delete any remains from previous updates. */
405
+ WiFiStorage.remove (" /fs/UPDATE.BIN.LZSS" );
406
+ WiFiStorage.remove (" /fs/UPDATE.BIN.LZSS.TMP" );
401
407
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
- }
408
+ /* Trigger direct download to nina module. */
409
+ uint8_t nina_ota_err_code = 0 ;
410
+ if (!WiFiStorage.downloadOTA (_ota_url.c_str (), &nina_ota_err_code))
411
+ {
412
+ DBG_ERROR (F (" ArduinoIoTCloudTCP::%s error download to nina: %d" ), __FUNCTION__, nina_ota_err_code);
413
+ _ota_error = static_cast <int >(OTAError::DownloadFailed);
414
+ return ;
415
+ }
410
416
411
- /* The download was a success. */
412
- ota_download_success = true ;
417
+ /* The download was a success. */
418
+ ota_download_success = true ;
413
419
#endif /* OTA_STORAGE_SNU */
414
420
415
- /* Perform the reset to reboot to SxU. */
416
- if (ota_download_success)
417
- NVIC_SystemReset ();
418
- }
421
+ /* Perform the reset to reboot to SxU. */
422
+ if (ota_download_success)
423
+ NVIC_SystemReset ();
419
424
}
420
425
#endif
421
426
0 commit comments