@@ -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 ;
@@ -745,20 +749,75 @@ void ArduinoIoTCloudTCP::sendPropertyContainerToCloud(String const topic, Proper
745
749
}
746
750
}
747
751
748
- void ArduinoIoTCloudTCP::sendPropertiesToCloud ()
752
+ void ArduinoIoTCloudTCP::sendThingPropertiesToCloud ()
749
753
{
750
754
sendPropertyContainerToCloud (_dataTopicOut, _thing_property_container, _last_checked_property_index);
751
755
}
752
756
757
+ void ArduinoIoTCloudTCP::sendDevicePropertiesToCloud ()
758
+ {
759
+ PropertyContainer ro_device_property_container;
760
+ unsigned int last_device_property_index = 0 ;
761
+
762
+ std::list<String> ro_device_property_list {" LIB_VERSION" , " OTA_CAP" , " OTA_ERROR" , " OTA_SHA256" };
763
+ std::for_each (ro_device_property_list.begin (),
764
+ ro_device_property_list.end (),
765
+ [this , &ro_device_property_container ] (String const & name)
766
+ {
767
+ Property* p = getProperty (this ->_device_property_container , name);
768
+ if (p != nullptr )
769
+ addPropertyToContainer (ro_device_property_container, *p, p->name (), p->isWriteableByCloud () ? Permission::ReadWrite : Permission::Read);
770
+ }
771
+ );
772
+
773
+ sendPropertyContainerToCloud (_deviceTopicOut, ro_device_property_container, last_device_property_index);
774
+ }
775
+
753
776
#if OTA_ENABLED
754
- void ArduinoIoTCloudTCP::sendOTAPropertiesToCloud (bool include_ota_req)
777
+ void ArduinoIoTCloudTCP::sendClearedOTARequestToCloud ()
778
+ {
779
+ PropertyContainer ota_property_container;
780
+ unsigned int last_ota_property_index = 0 ;
781
+
782
+ std::list<String> ota_property_list {" OTA_REQ" };
783
+ std::for_each (ota_property_list.begin (),
784
+ ota_property_list.end (),
785
+ [this , &ota_property_container ] (String const & name)
786
+ {
787
+ Property* p = getProperty (this ->_device_property_container , name);
788
+ if (p != nullptr )
789
+ addPropertyToContainer (ota_property_container, *p, p->name (), p->isWriteableByCloud () ? Permission::ReadWrite : Permission::Read);
790
+ }
791
+ );
792
+
793
+ sendPropertyContainerToCloud (_deviceTopicOut, ota_property_container, last_ota_property_index);
794
+ }
795
+
796
+ void ArduinoIoTCloudTCP::sendOTAErrorToCloud ()
797
+ {
798
+ PropertyContainer ota_property_container;
799
+ unsigned int last_ota_property_index = 0 ;
800
+
801
+ std::list<String> ota_property_list {" OTA_ERROR" };
802
+ std::for_each (ota_property_list.begin (),
803
+ ota_property_list.end (),
804
+ [this , &ota_property_container ] (String const & name)
805
+ {
806
+ Property* p = getProperty (this ->_device_property_container , name);
807
+ if (p != nullptr )
808
+ addPropertyToContainer (ota_property_container, *p, p->name (), p->isWriteableByCloud () ? Permission::ReadWrite : Permission::Read);
809
+ }
810
+ );
811
+
812
+ sendPropertyContainerToCloud (_deviceTopicOut, ota_property_container, last_ota_property_index);
813
+ }
814
+
815
+ void ArduinoIoTCloudTCP::sendOTAUrlToCloud ()
755
816
{
756
817
PropertyContainer ota_property_container;
757
818
unsigned int last_ota_property_index = 0 ;
758
819
759
- std::list<String> ota_property_list {" LIB_VERSION" , " OTA_CAP" , " OTA_ERROR" , " OTA_SHA256" };
760
- if (include_ota_req)
761
- ota_property_list.push_back (" OTA_REQ" );
820
+ std::list<String> ota_property_list {" OTA_URL" };
762
821
std::for_each (ota_property_list.begin (),
763
822
ota_property_list.end (),
764
823
[this , &ota_property_container ] (String const & name)
0 commit comments