@@ -654,18 +654,18 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
654654 /* Clear the request flag. */
655655 _ota_req = false ;
656656 /* Transmit the cleared request flags to the cloud. */
657- sendClearedOTARequestToCloud ( );
657+ sendDevicePropertyToCloud ( " OTA_REQ " );
658658 /* Call member function to handle OTA request. */
659659 onOTARequest ();
660660 /* If something fails send the OTA error to the cloud */
661- sendOTAErrorToCloud ( );
661+ sendDevicePropertyToCloud ( " OTA_ERROR " );
662662 }
663663 }
664664
665665 /* Check if we have received the OTA_URL property and provide
666666 * echo to the cloud.
667667 */
668- sendOTAUrlToCloud ( );
668+ sendDevicePropertyToCloud ( " OTA_URL " );
669669
670670#endif /* OTA_ENABLED */
671671
@@ -774,61 +774,17 @@ void ArduinoIoTCloudTCP::sendDevicePropertiesToCloud()
774774}
775775
776776#if OTA_ENABLED
777- void ArduinoIoTCloudTCP::sendClearedOTARequestToCloud ( )
777+ void ArduinoIoTCloudTCP::sendDevicePropertyToCloud (String const name )
778778{
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 ()
816- {
817- PropertyContainer ota_property_container;
818- unsigned int last_ota_property_index = 0 ;
819-
820- std::list<String> ota_property_list {" OTA_URL" };
821- std::for_each (ota_property_list.begin (),
822- ota_property_list.end (),
823- [this , &ota_property_container ] (String const & name)
824- {
825- Property* p = getProperty (this ->_device_property_container , name);
826- if (p != nullptr )
827- addPropertyToContainer (ota_property_container, *p, p->name (), p->isWriteableByCloud () ? Permission::ReadWrite : Permission::Read);
828- }
829- );
779+ PropertyContainer temp_device_property_container;
780+ unsigned int last_device_property_index = 0 ;
830781
831- sendPropertyContainerToCloud (_deviceTopicOut, ota_property_container, last_ota_property_index);
782+ Property* p = getProperty (this ->_device_property_container , name);
783+ if (p != nullptr )
784+ {
785+ addPropertyToContainer (temp_device_property_container, *p, p->name (), p->isWriteableByCloud () ? Permission::ReadWrite : Permission::Read);
786+ sendPropertyContainerToCloud (_deviceTopicOut, temp_device_property_container, last_device_property_index);
787+ }
832788}
833789#endif
834790
0 commit comments