Skip to content

Commit 8d7ebac

Browse files
checking string property size during encoding
1 parent f9946bb commit 8d7ebac

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/property/types/CloudWrapperString.h

+27-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
******************************************************************************/
2424

2525
#include <Arduino.h>
26+
#include "AIoTC_Config.h"
2627
#include "CloudWrapperBase.h"
2728

2829
/******************************************************************************
@@ -50,7 +51,32 @@ class CloudWrapperString : public CloudWrapperBase {
5051
_cloud_value = _primitive_value;
5152
}
5253
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
53-
return appendAttribute(_primitive_value, "", encoder);
54+
// check that the string fits mqtt tx buffer
55+
if(_name.length() > STRING_PROPERTY_MAX_SIZE) {
56+
Serial.print(__FILE__); Serial.print(__LINE__);
57+
Serial.println("[WARNING] String property name exceedes transmit buffer size, unable to send property");
58+
59+
/*
60+
* If your reached this line it means that you set a preperty name that exceeded the current maximum capabilities
61+
* of transmission buffer size. You can either change the buiffer size or the property name can be shortened.
62+
* Look below for raising the buffer size
63+
*/
64+
65+
return CborErrorOutOfMemory;
66+
} else if(_primitive_value.length() + _name.length() > STRING_PROPERTY_MAX_SIZE) {
67+
Serial.print(__FILE__); Serial.print(__LINE__);
68+
Serial.println("[WARNING] String property exceedes transmit buffer size");
69+
70+
/*
71+
* If your reached this line it means that the value and the property name exceed the current maximum capabilities
72+
* of transmission buffer size. to fix this you can raise the size of the buffer.
73+
* you can raise the size of the buffer by setting #define MQTT_TX_BUFFER_SIZE <VALUE> at the beginning of the file
74+
*/
75+
76+
return appendAttribute("ERROR_PROPERTY_TOO_LONG", "", encoder);
77+
} else {
78+
return appendAttribute(_primitive_value, "", encoder);
79+
}
5480
}
5581
virtual void setAttributesFromCloud() {
5682
setAttribute(_cloud_value, "");

0 commit comments

Comments
 (0)