@@ -95,6 +95,8 @@ ArduinoIoTCloudTCP::ArduinoIoTCloudTCP()
95
95
, _ota_img_sha256{" Inv." }
96
96
, _ota_url{" " }
97
97
, _ota_req{false }
98
+ , _ask_user_before_executing_ota{false }
99
+ , _get_ota_confirmation{nullptr }
98
100
#endif /* OTA_ENABLED */
99
101
{
100
102
@@ -238,8 +240,8 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
238
240
addPropertyReal (_ota_cap, " OTA_CAP" , Permission::Read);
239
241
addPropertyReal (_ota_error, " OTA_ERROR" , Permission::Read);
240
242
addPropertyReal (_ota_img_sha256, " OTA_SHA256" , Permission::Read);
241
- addPropertyReal (_ota_url, " OTA_URL" , Permission::ReadWrite).onSync (DEVICE_WINS );
242
- addPropertyReal (_ota_req, " OTA_REQ" , Permission::ReadWrite).onSync (DEVICE_WINS );
243
+ addPropertyReal (_ota_url, " OTA_URL" , Permission::ReadWrite).onSync (CLOUD_WINS );
244
+ addPropertyReal (_ota_req, " OTA_REQ" , Permission::ReadWrite).onSync (CLOUD_WINS );
243
245
#endif /* OTA_ENABLED */
244
246
245
247
#if OTA_STORAGE_PORTENTA_QSPI
@@ -499,29 +501,33 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
499
501
_mqtt_data_request_retransmit = false ;
500
502
}
501
503
502
- /* Check if any properties need encoding and send them to
503
- * the cloud if necessary.
504
- */
505
- sendPropertiesToCloud ();
506
-
507
504
#if OTA_ENABLED
508
505
/* Request a OTA download if the hidden property
509
506
* OTA request has been set.
510
507
*/
511
508
512
509
if (_ota_req)
513
510
{
514
- /* Clear the error flag. */
515
- _ota_error = static_cast <int >(OTAError::None);
516
- /* Transmit the cleared error flag to the cloud. */
517
- sendPropertiesToCloud ();
518
- /* Clear the request flag. */
519
- _ota_req = false ;
520
- /* Call member function to handle OTA request. */
521
- onOTARequest ();
511
+ bool const ota_execution_allowed_by_user = (_get_ota_confirmation != nullptr && _get_ota_confirmation ());
512
+ bool const perform_ota_now = ota_execution_allowed_by_user || !_ask_user_before_executing_ota;
513
+ if (perform_ota_now) {
514
+ /* Clear the error flag. */
515
+ _ota_error = static_cast <int >(OTAError::None);
516
+ /* Clear the request flag. */
517
+ _ota_req = false ;
518
+ /* Transmit the cleared error and request flags to the cloud. */
519
+ sendPropertiesToCloud ();
520
+ /* Call member function to handle OTA request. */
521
+ onOTARequest ();
522
+ }
522
523
}
523
524
#endif /* OTA_ENABLED */
524
525
526
+ /* Check if any properties need encoding and send them to
527
+ * the cloud if necessary.
528
+ */
529
+ sendPropertiesToCloud ();
530
+
525
531
return State::Connected;
526
532
}
527
533
}
0 commit comments