Closed mrvanes closed 7 years ago
@mrvanes that's why there's 2 constructors, one is for "C strings" the other for "byte buffers". If you think something is unclear in the API documentation, please submit a pull request with a suggestion.
https://github.com/sandeepmistry/arduino-BLEPeripheral/blob/master/API.md
Here's what's in there now:
BLECharacteristic
Contructor
BLECharacteristic(const char* uuid, unsigned char properties, unsigned char valueSize);
BLECharacteristic(const char* uuid, unsigned char properties, const char* value);
uuid - UUID of characteristic
properties - combination of (|'ed):
BLEBroadcast
BLERead
BLEWriteWithoutResponse
BLEWrite
BLENotify
BLEIndicate
Choice of:
valueSize - size of characteristic in bytes (max: 20 characters on nRF8001 and nRF51822)
or
value - string value (max: 20 characters on nRF8001 and nRF51822)
I have a BLEFixedLengthCharacteristic that has several 0's in the characteristic value which caused me some headache on constructing and updating using the char prototype as the length of the characteristic value gets calculated from strlen instead of sizeof. I now use the constructor giving the length and setValue using the char value[] and length prototype, but it took me some time before I understood what went wrong using the char prototype.
I tried fixing it using sizeof in BLECharacteristic.cpp and it works for the constructor, but setValue char prototype is a no-go, since sizeof char always returns 4 (the pointer) instead of the size of the array and there is no way to get the sizeof the original array since it's calculated compile-time.
I'm not that literate in C to solve this problem, but maybe you have an idea to alleviate this potential brain breaker for future victims? Maybe a solution would be to deprecate the char* prototype and require the length to always be set, this is how the BLE Nano BLE API works IIRC.