|
34 | 34 | #endif |
35 | 35 |
|
36 | 36 | #if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) |
37 | | -# include <algorithm> |
38 | 37 | # include "tls/utility/SHA256.h" |
39 | 38 | # include <stm32h7xx_hal_rtc_ex.h> |
40 | 39 | # include <WiFi.h> |
41 | 40 | #endif |
42 | 41 |
|
43 | 42 | #include "utility/ota/OTA.h" |
44 | 43 | #include "utility/ota/FlashSHA256.h" |
45 | | - |
| 44 | +#include <algorithm> |
46 | 45 | #include "cbor/CBOREncoder.h" |
47 | 46 |
|
48 | 47 | #include "utility/watchdog/Watchdog.h" |
@@ -516,7 +515,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected() |
516 | 515 | /* Clear the request flag. */ |
517 | 516 | _ota_req = false; |
518 | 517 | /* Transmit the cleared error and request flags to the cloud. */ |
519 | | - sendPropertiesToCloud(); |
| 518 | + sendOTAPropertiesToCloud(); |
520 | 519 | /* Call member function to handle OTA request. */ |
521 | 520 | onOTARequest(); |
522 | 521 | } |
@@ -581,6 +580,37 @@ void ArduinoIoTCloudTCP::sendPropertiesToCloud() |
581 | 580 | } |
582 | 581 | } |
583 | 582 |
|
| 583 | +void ArduinoIoTCloudTCP::sendOTAPropertiesToCloud() |
| 584 | +{ |
| 585 | + int bytes_encoded = 0; |
| 586 | + uint8_t data[MQTT_TRANSMIT_BUFFER_SIZE]; |
| 587 | + |
| 588 | + PropertyContainer ota_property_container; |
| 589 | + |
| 590 | + std::list<String> const ota_property_list {"OTA_CAP", "OTA_ERROR", "OTA_SHA256", "OTA_URL", "OTA_REQ"}; |
| 591 | + std::for_each(ota_property_list.cbegin(), |
| 592 | + ota_property_list.cend(), |
| 593 | + [this, &ota_property_container ] (String const & name) |
| 594 | + { |
| 595 | + Property* p = getProperty(this->_property_container, name); |
| 596 | + if(p != nullptr) |
| 597 | + addPropertyToContainer(ota_property_container, *p, p->name(), p->isWriteableByCloud() ? Permission::ReadWrite : Permission::Read); |
| 598 | + } |
| 599 | + ); |
| 600 | + |
| 601 | + if (CBOREncoder::encode(ota_property_container, data, sizeof(data), bytes_encoded, false) == CborNoError) |
| 602 | + if (bytes_encoded > 0) |
| 603 | + { |
| 604 | + /* If properties have been encoded store them in the back-up buffer |
| 605 | + * in order to allow retransmission in case of failure. |
| 606 | + */ |
| 607 | + _mqtt_data_len = bytes_encoded; |
| 608 | + memcpy(_mqtt_data_buf, data, _mqtt_data_len); |
| 609 | + /* Transmit the properties to the MQTT broker */ |
| 610 | + write(_dataTopicOut, _mqtt_data_buf, _mqtt_data_len); |
| 611 | + } |
| 612 | +} |
| 613 | + |
584 | 614 | void ArduinoIoTCloudTCP::requestLastValue() |
585 | 615 | { |
586 | 616 | // Send the getLastValues CBOR message to the cloud |
|
0 commit comments