Truncate all STRING-based Characteristics to 64 characters when adding to JSON

HAP default max length of STRING Characteristics is 64 characters
This commit is contained in:
Gregg 2024-01-12 21:21:42 -06:00
parent fe9e3d7942
commit 2d86ee4a25
2 changed files with 3 additions and 3 deletions

View File

@ -492,7 +492,7 @@ class SpanCharacteristic{
StatusCode loadUpdate(char *val, char *ev); // load updated val/ev from PUT /characteristic JSON request. Return intitial HAP status code (checks to see if characteristic is found, is writable, etc.)
String uvPrint(UVal &u){
char c[64];
char c[67]; // space for 64 characters + surrounding quotes + terminating null
switch(format){
case FORMAT::BOOL:
return(String(u.BOOL));
@ -512,7 +512,7 @@ class SpanCharacteristic{
return(String(c));
case FORMAT::STRING:
case FORMAT::DATA:
sprintf(c,"\"%.61s\"",u.STRING); // Truncating string to 61 chars.
sprintf(c,"\"%.64s\"",u.STRING); // Truncating string to 64 chars
return(String(c));
} // switch
return(String()); // included to prevent compiler warnings

View File

@ -48,7 +48,7 @@ void setup() {
new SpanAccessory();
new Service::AccessoryInformation();
new Characteristic::Identify();
char c[30];
char c[100];
sprintf(c,"Light-%d",i);
new Characteristic::Name(c);
new Service::LightBulb();