diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index 6ac511cba..4d4f86b9d 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -34,7 +34,6 @@ #endif #if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) -# include # include "tls/utility/SHA256.h" # include # include @@ -42,7 +41,7 @@ #include "utility/ota/OTA.h" #include "utility/ota/FlashSHA256.h" - +#include #include "cbor/CBOREncoder.h" #include "utility/watchdog/Watchdog.h" @@ -516,7 +515,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected() /* Clear the request flag. */ _ota_req = false; /* Transmit the cleared error and request flags to the cloud. */ - sendPropertiesToCloud(); + sendOTAPropertiesToCloud(); /* Call member function to handle OTA request. */ onOTARequest(); } @@ -563,12 +562,12 @@ void ArduinoIoTCloudTCP::handleMessage(int length) } } -void ArduinoIoTCloudTCP::sendPropertiesToCloud() +void ArduinoIoTCloudTCP::sendPropertyContainerToCloud(PropertyContainer & property_container) { int bytes_encoded = 0; uint8_t data[MQTT_TRANSMIT_BUFFER_SIZE]; - if (CBOREncoder::encode(_property_container, data, sizeof(data), bytes_encoded, false) == CborNoError) + if (CBOREncoder::encode(property_container, data, sizeof(data), bytes_encoded, false) == CborNoError) if (bytes_encoded > 0) { /* If properties have been encoded store them in the back-up buffer @@ -581,6 +580,29 @@ void ArduinoIoTCloudTCP::sendPropertiesToCloud() } } +void ArduinoIoTCloudTCP::sendPropertiesToCloud() +{ + sendPropertyContainerToCloud(_property_container); +} + +void ArduinoIoTCloudTCP::sendOTAPropertiesToCloud() +{ + PropertyContainer ota_property_container; + + std::list const ota_property_list {"OTA_CAP", "OTA_ERROR", "OTA_SHA256", "OTA_URL", "OTA_REQ"}; + std::for_each(ota_property_list.cbegin(), + ota_property_list.cend(), + [this, &ota_property_container ] (String const & name) + { + Property* p = getProperty(this->_property_container, name); + if(p != nullptr) + addPropertyToContainer(ota_property_container, *p, p->name(), p->isWriteableByCloud() ? Permission::ReadWrite : Permission::Read); + } + ); + + sendPropertyContainerToCloud(ota_property_container); +} + void ArduinoIoTCloudTCP::requestLastValue() { // Send the getLastValues CBOR message to the cloud diff --git a/src/ArduinoIoTCloudTCP.h b/src/ArduinoIoTCloudTCP.h index fa04a6e33..21063c29f 100644 --- a/src/ArduinoIoTCloudTCP.h +++ b/src/ArduinoIoTCloudTCP.h @@ -164,7 +164,9 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass static void onMessage(int length); void handleMessage(int length); + void sendPropertyContainerToCloud(PropertyContainer & property_container); void sendPropertiesToCloud(); + void sendOTAPropertiesToCloud(); void requestLastValue(); int write(String const topic, byte const data[], int const length);