Skip to content

Commit 052b30e

Browse files
committed
Added generic function ArduinoIoTCloudTCP::sendPropertyContainerToCloud
1 parent 4d1a0d6 commit 052b30e

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/ArduinoIoTCloudTCP.cpp

+8-16
Original file line numberDiff line numberDiff line change
@@ -562,12 +562,12 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
562562
}
563563
}
564564

565-
void ArduinoIoTCloudTCP::sendPropertiesToCloud()
565+
void ArduinoIoTCloudTCP::sendPropertyContainerToCloud(PropertyContainer & property_container)
566566
{
567567
int bytes_encoded = 0;
568568
uint8_t data[MQTT_TRANSMIT_BUFFER_SIZE];
569569

570-
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)
571571
if (bytes_encoded > 0)
572572
{
573573
/* If properties have been encoded store them in the back-up buffer
@@ -580,11 +580,13 @@ void ArduinoIoTCloudTCP::sendPropertiesToCloud()
580580
}
581581
}
582582

583-
void ArduinoIoTCloudTCP::sendOTAPropertiesToCloud()
583+
void ArduinoIoTCloudTCP::sendPropertiesToCloud()
584584
{
585-
int bytes_encoded = 0;
586-
uint8_t data[MQTT_TRANSMIT_BUFFER_SIZE];
585+
sendPropertyContainerToCloud(_property_container);
586+
}
587587

588+
void ArduinoIoTCloudTCP::sendOTAPropertiesToCloud()
589+
{
588590
PropertyContainer ota_property_container;
589591

590592
std::list<String> const ota_property_list {"OTA_CAP", "OTA_ERROR", "OTA_SHA256", "OTA_URL", "OTA_REQ"};
@@ -598,17 +600,7 @@ void ArduinoIoTCloudTCP::sendOTAPropertiesToCloud()
598600
}
599601
);
600602

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-
}
603+
sendPropertyContainerToCloud(ota_property_container);
612604
}
613605

614606
void ArduinoIoTCloudTCP::requestLastValue()

src/ArduinoIoTCloudTCP.h

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ 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();
168169
void sendOTAPropertiesToCloud();
169170
void requestLastValue();

0 commit comments

Comments
 (0)