@@ -262,7 +262,6 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
262
262
263
263
addPropertyReal (_tz_offset, _thing_property_container, " tz_offset" , Permission::ReadWrite).onSync (CLOUD_WINS).onUpdate (updateTimezoneInfo);
264
264
addPropertyReal (_tz_dst_until, _thing_property_container, " tz_dst_until" , Permission::ReadWrite).onSync (CLOUD_WINS).onUpdate (updateTimezoneInfo);
265
-
266
265
addPropertyReal (_thing_id, _device_property_container, " thing_id" , Permission::ReadWrite).onUpdate (setThingIdOutdated);
267
266
268
267
#if OTA_STORAGE_PORTENTA_QSPI
@@ -426,9 +425,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SendDeviceProperties()
426
425
return State::Disconnect;
427
426
}
428
427
429
- #if OTA_ENABLED
430
- sendOTAPropertiesToCloud ();
431
- #endif
428
+ sendDevicePropertiesToCloud ();
432
429
return State::SubscribeDeviceTopic;
433
430
}
434
431
@@ -663,18 +660,26 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
663
660
_ota_error = static_cast <int >(OTAError::None);
664
661
/* Clear the request flag. */
665
662
_ota_req = false ;
666
- /* Transmit the cleared error and request flags to the cloud. */
667
- sendOTAPropertiesToCloud ();
663
+ /* Transmit the cleared request flags to the cloud. */
664
+ sendClearedOTARequestToCloud ();
668
665
/* Call member function to handle OTA request. */
669
666
onOTARequest ();
667
+ /* If something fails send the OTA error to the cloud */
668
+ sendOTAErrorToCloud ();
670
669
}
671
670
}
671
+
672
+ /* Check if we have received the OTA_URL property and provide
673
+ * echo to the cloud.
674
+ */
675
+ sendOTAUrlToCloud ();
676
+
672
677
#endif /* OTA_ENABLED */
673
678
674
679
/* Check if any properties need encoding and send them to
675
680
* the cloud if necessary.
676
681
*/
677
- sendPropertiesToCloud ();
682
+ sendThingPropertiesToCloud ();
678
683
679
684
unsigned long const internal_posix_time = _time_service.getTime ();
680
685
if (internal_posix_time < _tz_dst_until) {
@@ -725,7 +730,6 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
725
730
{
726
731
DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s [%d] last values received" , __FUNCTION__, millis ());
727
732
CBORDecoder::decode (_thing_property_container, (uint8_t *)bytes, length, true );
728
- sendPropertiesToCloud ();
729
733
_time_service.setTimeZoneData (_tz_offset, _tz_dst_until);
730
734
execCloudEventCallback (ArduinoIoTCloudEvent::SYNC);
731
735
_last_sync_request_cnt = 0 ;
@@ -753,20 +757,75 @@ void ArduinoIoTCloudTCP::sendPropertyContainerToCloud(String const topic, Proper
753
757
}
754
758
}
755
759
756
- void ArduinoIoTCloudTCP::sendPropertiesToCloud ()
760
+ void ArduinoIoTCloudTCP::sendThingPropertiesToCloud ()
757
761
{
758
762
sendPropertyContainerToCloud (_dataTopicOut, _thing_property_container, _last_checked_property_index);
759
763
}
760
764
765
+ void ArduinoIoTCloudTCP::sendDevicePropertiesToCloud ()
766
+ {
767
+ PropertyContainer ro_device_property_container;
768
+ unsigned int last_device_property_index = 0 ;
769
+
770
+ std::list<String> ro_device_property_list {" LIB_VERSION" , " OTA_CAP" , " OTA_ERROR" , " OTA_SHA256" };
771
+ std::for_each (ro_device_property_list.begin (),
772
+ ro_device_property_list.end (),
773
+ [this , &ro_device_property_container ] (String const & name)
774
+ {
775
+ Property* p = getProperty (this ->_device_property_container , name);
776
+ if (p != nullptr )
777
+ addPropertyToContainer (ro_device_property_container, *p, p->name (), p->isWriteableByCloud () ? Permission::ReadWrite : Permission::Read);
778
+ }
779
+ );
780
+
781
+ sendPropertyContainerToCloud (_deviceTopicOut, ro_device_property_container, last_device_property_index);
782
+ }
783
+
761
784
#if OTA_ENABLED
762
- void ArduinoIoTCloudTCP::sendOTAPropertiesToCloud (bool include_ota_req)
785
+ void ArduinoIoTCloudTCP::sendClearedOTARequestToCloud ()
786
+ {
787
+ PropertyContainer ota_property_container;
788
+ unsigned int last_ota_property_index = 0 ;
789
+
790
+ std::list<String> ota_property_list {" OTA_REQ" };
791
+ std::for_each (ota_property_list.begin (),
792
+ ota_property_list.end (),
793
+ [this , &ota_property_container ] (String const & name)
794
+ {
795
+ Property* p = getProperty (this ->_device_property_container , name);
796
+ if (p != nullptr )
797
+ addPropertyToContainer (ota_property_container, *p, p->name (), p->isWriteableByCloud () ? Permission::ReadWrite : Permission::Read);
798
+ }
799
+ );
800
+
801
+ sendPropertyContainerToCloud (_deviceTopicOut, ota_property_container, last_ota_property_index);
802
+ }
803
+
804
+ void ArduinoIoTCloudTCP::sendOTAErrorToCloud ()
805
+ {
806
+ PropertyContainer ota_property_container;
807
+ unsigned int last_ota_property_index = 0 ;
808
+
809
+ std::list<String> ota_property_list {" OTA_ERROR" };
810
+ std::for_each (ota_property_list.begin (),
811
+ ota_property_list.end (),
812
+ [this , &ota_property_container ] (String const & name)
813
+ {
814
+ Property* p = getProperty (this ->_device_property_container , name);
815
+ if (p != nullptr )
816
+ addPropertyToContainer (ota_property_container, *p, p->name (), p->isWriteableByCloud () ? Permission::ReadWrite : Permission::Read);
817
+ }
818
+ );
819
+
820
+ sendPropertyContainerToCloud (_deviceTopicOut, ota_property_container, last_ota_property_index);
821
+ }
822
+
823
+ void ArduinoIoTCloudTCP::sendOTAUrlToCloud ()
763
824
{
764
825
PropertyContainer ota_property_container;
765
826
unsigned int last_ota_property_index = 0 ;
766
827
767
- std::list<String> ota_property_list {" LIB_VERSION" , " OTA_CAP" , " OTA_ERROR" , " OTA_SHA256" };
768
- if (include_ota_req)
769
- ota_property_list.push_back (" OTA_REQ" );
828
+ std::list<String> ota_property_list {" OTA_URL" };
770
829
std::for_each (ota_property_list.begin (),
771
830
ota_property_list.end (),
772
831
[this , &ota_property_container ] (String const & name)
0 commit comments