Skip to content

String property limits #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/AIoTC_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
******************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion src/ArduinoIoTCloudTCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
29 changes: 28 additions & 1 deletion src/property/types/CloudWrapperString.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
******************************************************************************/

#include <Arduino.h>
#include "AIoTC_Config.h"
#include "CloudWrapperBase.h"
#include <Arduino_DebugUtils.h>

/******************************************************************************
CLASS DECLARATION
Expand All @@ -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 <VALUE> 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, "");
Expand Down