2323 ******************************************************************************/
2424
2525#include < Arduino.h>
26+ #include " AIoTC_Config.h"
2627#include " CloudWrapperBase.h"
28+ #include < Arduino_DebugUtils.h>
2729
2830/* *****************************************************************************
2931 CLASS DECLARATION
@@ -50,7 +52,32 @@ class CloudWrapperString : public CloudWrapperBase {
5052 _cloud_value = _primitive_value;
5153 }
5254 virtual CborError appendAttributesToCloud (CborEncoder *encoder) {
53- return appendAttribute (_primitive_value, " " , encoder);
55+ // check that the string fits mqtt tx buffer
56+ if (_name.length () > STRING_PROPERTY_MAX_SIZE) {
57+ DEBUG_WARNING (
58+ " [WARNING] %s:%s String property name exceedes transmit buffer size, unable to send property" ,
59+ __FILE__, __LINE__);
60+
61+ /*
62+ * If your reached this line it means that you set a preperty name that exceeded the current maximum capabilities
63+ * of transmission buffer size. You can either change the buiffer size or the property name can be shortened.
64+ * Look below for raising the buffer size
65+ */
66+
67+ return CborErrorOutOfMemory;
68+ } else if (_primitive_value.length () + _name.length () > STRING_PROPERTY_MAX_SIZE) {
69+ DEBUG_WARNING (" [WARNING] %s:%s String property exceedes transmit buffer size" , __FILE__, __LINE__);
70+
71+ /*
72+ * If your reached this line it means that the value and the property name exceed the current maximum capabilities
73+ * of transmission buffer size. to fix this you can raise the size of the buffer.
74+ * you can raise the size of the buffer by setting #define MQTT_TX_BUFFER_SIZE <VALUE> at the beginning of the file
75+ */
76+
77+ return appendAttribute (" ERROR_PROPERTY_TOO_LONG" , " " , encoder);
78+ } else {
79+ return appendAttribute (_primitive_value, " " , encoder);
80+ }
5481 }
5582 virtual void setAttributesFromCloud () {
5683 setAttribute (_cloud_value, " " );
0 commit comments