NimBLE-Arduino icon indicating copy to clipboard operation
NimBLE-Arduino copied to clipboard

SetValue not matching Function to call when update from 1.3.8 to 1.4.0

Open SosaL08 opened this issue 2 years ago • 5 comments

I used to set the value of my characteristics directly using a char array variable at the SetValue() function. Now, once I updated to 1.4.0 version of the library, the code can't compile cause the variable I use it's not in a valid format. How do I have to reference or address my char array variable to be compatible with this version?

SosaL08 avatar Aug 03 '22 08:08 SosaL08

Can you share the code you're using?

h2zero avatar Aug 03 '22 13:08 h2zero

NimBLECharacteristic *pReadCharacteristic;
pReadCharacteristic = pBleService->createCharacteristic("A002", NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY);
pReadCharacteristic->setCallbacks(&chrCallbacks);
char buffer_response[jsonWiFi.length() + 1];
jsonWiFi.toCharArray(buffer_response, jsonWiFi.length() + 1);
pReadCharacteristic->setValue(buffer_response);
pReadCharacteristic->notify();

I can't share the entire code but this is the part that gives me trouble. When I run it with version 1.3.8 it works perfectly, yet, updating to 1.4.0 gives me an error with the SetValue function. It says the value I'm providing its not correctly expressed, as I can't set it directly from my char array.

SosaL08 avatar Aug 03 '22 13:08 SosaL08

Thank you for the report and sharing the code to reproduce this. The templates do not seem to be handling this use case properly at the moment, I will look into this further for the next release. For now you can workaround the problem by casting your array to uint8_t*.

pReadCharacteristic->setValue((uint8_t*)buffer_response);

h2zero avatar Aug 03 '22 15:08 h2zero

Thanks! I'll try that out to see if it works correctly with my code

SosaL08 avatar Aug 04 '22 06:08 SosaL08

I had this same problem upgrading from 1.3.7 to 1.4.1 and simply casting the char * to (uint8_t*) worked in the setValue call. Thanks.

HankLloydRight avatar Dec 30 '22 21:12 HankLloydRight