Skip to content

Commit

Permalink
checking string property size during encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
andreagilardoni committed Jan 17, 2024
1 parent f9946bb commit 8d7ebac
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/property/types/CloudWrapperString.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
******************************************************************************/

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

/******************************************************************************
Expand Down Expand Up @@ -50,7 +51,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) {
Serial.print(__FILE__); Serial.print(__LINE__);
Serial.println("[WARNING] String property name exceedes transmit buffer size, unable to send property");

/*
* 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) {
Serial.print(__FILE__); Serial.print(__LINE__);
Serial.println("[WARNING] String property exceedes transmit buffer size");

/*
* 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

0 comments on commit 8d7ebac

Please sign in to comment.