@@ -250,6 +250,7 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
250
250
_deviceTopicOut = getTopic_deviceout ();
251
251
_deviceTopicIn = getTopic_devicein ();
252
252
253
+ addPropertyReal (_lib_version, _device_property_container, " LIB_VERSION" , Permission::Read);
253
254
#if OTA_ENABLED
254
255
addPropertyReal (_ota_cap, _device_property_container, " OTA_CAP" , Permission::Read);
255
256
addPropertyReal (_ota_error, _device_property_container, " OTA_ERROR" , Permission::Read);
@@ -260,7 +261,6 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
260
261
261
262
addPropertyReal (_tz_offset, _thing_property_container, " tz_offset" , Permission::ReadWrite).onSync (CLOUD_WINS).onUpdate (updateTimezoneInfo);
262
263
addPropertyReal (_tz_dst_until, _thing_property_container, " tz_dst_until" , Permission::ReadWrite).onSync (CLOUD_WINS).onUpdate (updateTimezoneInfo);
263
-
264
264
addPropertyReal (_thing_id, _device_property_container, " thing_id" , Permission::ReadWrite).onUpdate (setThingIdOutdated);
265
265
266
266
#if OTA_STORAGE_PORTENTA_QSPI
@@ -428,9 +428,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SendDeviceProperties()
428
428
429
429
DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s" , __FUNCTION__);
430
430
431
- #if OTA_ENABLED
432
- sendOTAPropertiesToCloud ();
433
- #endif
431
+ sendDevicePropertiesToCloud ();
434
432
return State::SubscribeDeviceTopic;
435
433
}
436
434
@@ -653,18 +651,20 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
653
651
_ota_error = static_cast <int >(OTAError::None);
654
652
/* Clear the request flag. */
655
653
_ota_req = false ;
656
- /* Transmit the cleared error and request flags to the cloud. */
657
- sendOTAPropertiesToCloud ();
654
+ /* Transmit the cleared request flags to the cloud. */
655
+ sendClearedOTARequestToCloud ();
658
656
/* Call member function to handle OTA request. */
659
657
onOTARequest ();
658
+ /* If something fails send the OTA error to the cloud */
659
+ sendOTAErrorToCloud ();
660
660
}
661
661
}
662
662
#endif /* OTA_ENABLED */
663
663
664
664
/* Check if any properties need encoding and send them to
665
665
* the cloud if necessary.
666
666
*/
667
- sendPropertiesToCloud ();
667
+ sendThingPropertiesToCloud ();
668
668
669
669
unsigned long const internal_posix_time = _time_service.getTime ();
670
670
if (internal_posix_time < _tz_dst_until) {
@@ -700,7 +700,7 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
700
700
701
701
/* Topic for OTA properties and device configuration */
702
702
if (_deviceTopicIn == topic) {
703
- CBORDecoder::decode (_device_property_container, (uint8_t *)bytes, length);
703
+ CBORDecoder::decode (_device_property_container, (uint8_t *)bytes, length, true );
704
704
DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s [%d] device configuration or OTA message received" , __FUNCTION__, millis ());
705
705
_last_device_subscribe_cnt = 0 ;
706
706
_next_device_subscribe_attempt_tick = 0 ;
@@ -716,7 +716,6 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
716
716
{
717
717
DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s [%d] last values received" , __FUNCTION__, millis ());
718
718
CBORDecoder::decode (_thing_property_container, (uint8_t *)bytes, length, true );
719
- sendPropertiesToCloud ();
720
719
_time_service.setTimeZoneData (_tz_offset, _tz_dst_until);
721
720
execCloudEventCallback (ArduinoIoTCloudEvent::SYNC);
722
721
_last_sync_request_cnt = 0 ;
@@ -744,19 +743,53 @@ void ArduinoIoTCloudTCP::sendPropertyContainerToCloud(String const topic, Proper
744
743
}
745
744
}
746
745
747
- void ArduinoIoTCloudTCP::sendPropertiesToCloud ()
746
+ void ArduinoIoTCloudTCP::sendThingPropertiesToCloud ()
748
747
{
749
748
sendPropertyContainerToCloud (_dataTopicOut, _thing_property_container);
750
749
}
751
750
751
+ void ArduinoIoTCloudTCP::sendDevicePropertiesToCloud ()
752
+ {
753
+ PropertyContainer ro_device_property_container;
754
+
755
+ std::list<String> ro_device_property_list {" LIB_VERSION" , " OTA_CAP" , " OTA_ERROR" , " OTA_SHA256" };
756
+ std::for_each (ro_device_property_list.begin (),
757
+ ro_device_property_list.end (),
758
+ [this , &ro_device_property_container ] (String const & name)
759
+ {
760
+ Property* p = getProperty (this ->_device_property_container , name);
761
+ if (p != nullptr )
762
+ addPropertyToContainer (ro_device_property_container, *p, p->name (), p->isWriteableByCloud () ? Permission::ReadWrite : Permission::Read);
763
+ }
764
+ );
765
+
766
+ sendPropertyContainerToCloud (_deviceTopicOut, ro_device_property_container);
767
+ }
768
+
752
769
#if OTA_ENABLED
753
- void ArduinoIoTCloudTCP::sendOTAPropertiesToCloud (bool include_ota_req)
770
+ void ArduinoIoTCloudTCP::sendClearedOTARequestToCloud ()
771
+ {
772
+ PropertyContainer ota_property_container;
773
+
774
+ std::list<String> ota_property_list {" OTA_REQ" };
775
+ std::for_each (ota_property_list.begin (),
776
+ ota_property_list.end (),
777
+ [this , &ota_property_container ] (String const & name)
778
+ {
779
+ Property* p = getProperty (this ->_device_property_container , name);
780
+ if (p != nullptr )
781
+ addPropertyToContainer (ota_property_container, *p, p->name (), p->isWriteableByCloud () ? Permission::ReadWrite : Permission::Read);
782
+ }
783
+ );
784
+
785
+ sendPropertyContainerToCloud (_deviceTopicOut, ota_property_container);
786
+ }
787
+
788
+ void ArduinoIoTCloudTCP::sendOTAErrorToCloud ()
754
789
{
755
790
PropertyContainer ota_property_container;
756
791
757
- std::list<String> ota_property_list {" OTA_CAP" , " OTA_ERROR" , " OTA_SHA256" };
758
- if (include_ota_req)
759
- ota_property_list.push_back (" OTA_REQ" );
792
+ std::list<String> ota_property_list {" OTA_ERROR" };
760
793
std::for_each (ota_property_list.begin (),
761
794
ota_property_list.end (),
762
795
[this , &ota_property_container ] (String const & name)
0 commit comments