|
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,38 @@ 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 to_property_container; |
| 589 | + PropertyContainer from_property_container = _property_container; |
| 590 | + |
| 591 | + std::list<String> ota_property_list {"OTA_CAP", "OTA_ERROR", "OTA_SHA256", "OTA_URL", "OTA_REQ"}; |
| 592 | + std::for_each(ota_property_list.begin(), |
| 593 | + ota_property_list.end(), |
| 594 | + [&from_property_container, &to_property_container ] (String const & name) |
| 595 | + { |
| 596 | + Property* p = getProperty(from_property_container, name); |
| 597 | + if(p != nullptr) |
| 598 | + addPropertyToContainer(to_property_container, *p, p->name(), p->isWriteableByCloud() ? Permission::ReadWrite : Permission::Read); |
| 599 | + } |
| 600 | + ); |
| 601 | + |
| 602 | + if (CBOREncoder::encode(to_property_container, data, sizeof(data), bytes_encoded, false) == CborNoError) |
| 603 | + if (bytes_encoded > 0) |
| 604 | + { |
| 605 | + /* If properties have been encoded store them in the back-up buffer |
| 606 | + * in order to allow retransmission in case of failure. |
| 607 | + */ |
| 608 | + _mqtt_data_len = bytes_encoded; |
| 609 | + memcpy(_mqtt_data_buf, data, _mqtt_data_len); |
| 610 | + /* Transmit the properties to the MQTT broker */ |
| 611 | + write(_dataTopicOut, _mqtt_data_buf, _mqtt_data_len); |
| 612 | + } |
| 613 | +} |
| 614 | + |
584 | 615 | void ArduinoIoTCloudTCP::requestLastValue()
|
585 | 616 | {
|
586 | 617 | // Send the getLastValues CBOR message to the cloud
|
|
0 commit comments