diff --git a/src/AIoTC_Config.h b/src/AIoTC_Config.h index eb2750b49..a4fa84fd4 100644 --- a/src/AIoTC_Config.h +++ b/src/AIoTC_Config.h @@ -156,6 +156,21 @@ #define HAS_TCP #endif +#ifdef HAS_TCP + #ifndef MQTT_TX_BUFFER_SIZE + #define MQTT_TX_BUFFER_SIZE 256 + #endif // MQTT_TX_BUFFER_SIZE + + #ifndef STRING_PROPERTY_MAX_SIZE + // 6 represents the expected overhead of a string property inside a cbor + #define STRING_PROPERTY_MAX_SIZE MQTT_TX_BUFFER_SIZE - 6 + #endif // STRING_PROPERTY_MAX_SIZE +#else + #ifndef STRING_PROPERTY_MAX_SIZE + #define STRING_PROPERTY_MAX_SIZE 50 + #endif // STRING_PROPERTY_MAX_SIZE +#endif // HAS_TCP + /****************************************************************************** * CONSTANTS ******************************************************************************/ diff --git a/src/ArduinoIoTCloudTCP.h b/src/ArduinoIoTCloudTCP.h index e50f9a076..f5770c731 100644 --- a/src/ArduinoIoTCloudTCP.h +++ b/src/ArduinoIoTCloudTCP.h @@ -106,7 +106,7 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass #endif private: - static const int MQTT_TRANSMIT_BUFFER_SIZE = 256; + static const int MQTT_TRANSMIT_BUFFER_SIZE = MQTT_TX_BUFFER_SIZE; enum class State { diff --git a/src/property/types/CloudWrapperString.h b/src/property/types/CloudWrapperString.h index 7c75db0db..79d8e5d51 100644 --- a/src/property/types/CloudWrapperString.h +++ b/src/property/types/CloudWrapperString.h @@ -23,7 +23,9 @@ ******************************************************************************/ #include +#include "AIoTC_Config.h" #include "CloudWrapperBase.h" +#include /****************************************************************************** CLASS DECLARATION @@ -50,7 +52,32 @@ class CloudWrapperString : public CloudWrapperBase { _cloud_value = _primitive_value; } virtual CborError appendAttributesToCloud(CborEncoder *encoder) { - return appendAttribute(_primitive_value, "", encoder); + // check that the string fits mqtt tx buffer + if(_name.length() > STRING_PROPERTY_MAX_SIZE) { + DEBUG_WARNING( + "[WARNING] %s:%s String property name exceedes transmit buffer size, unable to send property", + __FILE__, __LINE__); + + /* + * If your reached this line it means that you set a preperty name that exceeded the current maximum capabilities + * of transmission buffer size. You can either change the buiffer size or the property name can be shortened. + * Look below for raising the buffer size + */ + + return CborErrorOutOfMemory; + } else if(_primitive_value.length() + _name.length() > STRING_PROPERTY_MAX_SIZE) { + DEBUG_WARNING("[WARNING] %s:%s String property exceedes transmit buffer size", __FILE__, __LINE__); + + /* + * If your reached this line it means that the value and the property name exceed the current maximum capabilities + * of transmission buffer size. to fix this you can raise the size of the buffer. + * you can raise the size of the buffer by setting #define MQTT_TX_BUFFER_SIZE at the beginning of the file + */ + + return appendAttribute("ERROR_PROPERTY_TOO_LONG", "", encoder); + } else { + return appendAttribute(_primitive_value, "", encoder); + } } virtual void setAttributesFromCloud() { setAttribute(_cloud_value, "");