Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e51f540

Browse files
committedNov 11, 2021
Added generic function ArduinoIoTCloudTCP::sendPropertyContainerToCloud
1 parent 98484d2 commit e51f540

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed
 

‎src/ArduinoIoTCloudTCP.cpp

Lines changed: 8 additions & 16 deletions
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 to_property_container;
589591
PropertyContainer from_property_container = _property_container;
590592

@@ -599,17 +601,7 @@ void ArduinoIoTCloudTCP::sendOTAPropertiesToCloud()
599601
}
600602
);
601603

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-
}
604+
sendPropertyContainerToCloud(to_property_container);
613605
}
614606

615607
void ArduinoIoTCloudTCP::requestLastValue()

‎src/ArduinoIoTCloudTCP.h

Lines changed: 1 addition & 0 deletions
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)
Please sign in to comment.