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