Skip to content

Commit 765012d

Browse files
authored
Merge pull request #289 from pennam/1.3.0-hotfix-lambda
Fix OTA properties synchronization
2 parents 4c3af93 + 052b30e commit 765012d

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/ArduinoIoTCloudTCP.cpp

+27-5
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@
3434
#endif
3535

3636
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
37-
# include <algorithm>
3837
# include "tls/utility/SHA256.h"
3938
# include <stm32h7xx_hal_rtc_ex.h>
4039
# include <WiFi.h>
4140
#endif
4241

4342
#include "utility/ota/OTA.h"
4443
#include "utility/ota/FlashSHA256.h"
45-
44+
#include <algorithm>
4645
#include "cbor/CBOREncoder.h"
4746

4847
#include "utility/watchdog/Watchdog.h"
@@ -516,7 +515,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
516515
/* Clear the request flag. */
517516
_ota_req = false;
518517
/* Transmit the cleared error and request flags to the cloud. */
519-
sendPropertiesToCloud();
518+
sendOTAPropertiesToCloud();
520519
/* Call member function to handle OTA request. */
521520
onOTARequest();
522521
}
@@ -563,12 +562,12 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
563562
}
564563
}
565564

566-
void ArduinoIoTCloudTCP::sendPropertiesToCloud()
565+
void ArduinoIoTCloudTCP::sendPropertyContainerToCloud(PropertyContainer & property_container)
567566
{
568567
int bytes_encoded = 0;
569568
uint8_t data[MQTT_TRANSMIT_BUFFER_SIZE];
570569

571-
if (CBOREncoder::encode(_property_container, data, sizeof(data), bytes_encoded, false) == CborNoError)
570+
if (CBOREncoder::encode(property_container, data, sizeof(data), bytes_encoded, false) == CborNoError)
572571
if (bytes_encoded > 0)
573572
{
574573
/* If properties have been encoded store them in the back-up buffer
@@ -581,6 +580,29 @@ void ArduinoIoTCloudTCP::sendPropertiesToCloud()
581580
}
582581
}
583582

583+
void ArduinoIoTCloudTCP::sendPropertiesToCloud()
584+
{
585+
sendPropertyContainerToCloud(_property_container);
586+
}
587+
588+
void ArduinoIoTCloudTCP::sendOTAPropertiesToCloud()
589+
{
590+
PropertyContainer ota_property_container;
591+
592+
std::list<String> const ota_property_list {"OTA_CAP", "OTA_ERROR", "OTA_SHA256", "OTA_URL", "OTA_REQ"};
593+
std::for_each(ota_property_list.cbegin(),
594+
ota_property_list.cend(),
595+
[this, &ota_property_container ] (String const & name)
596+
{
597+
Property* p = getProperty(this->_property_container, name);
598+
if(p != nullptr)
599+
addPropertyToContainer(ota_property_container, *p, p->name(), p->isWriteableByCloud() ? Permission::ReadWrite : Permission::Read);
600+
}
601+
);
602+
603+
sendPropertyContainerToCloud(ota_property_container);
604+
}
605+
584606
void ArduinoIoTCloudTCP::requestLastValue()
585607
{
586608
// Send the getLastValues CBOR message to the cloud

src/ArduinoIoTCloudTCP.h

+2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
164164

165165
static void onMessage(int length);
166166
void handleMessage(int length);
167+
void sendPropertyContainerToCloud(PropertyContainer & property_container);
167168
void sendPropertiesToCloud();
169+
void sendOTAPropertiesToCloud();
168170
void requestLastValue();
169171
int write(String const topic, byte const data[], int const length);
170172

0 commit comments

Comments
 (0)