Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 8 months ago.
Writing values via GattServer: should the value buffers be static?
This applies to read and write GATT characteristic classes/templates, also both to constructors and the read/write methods: basically, do these methods copy the value, or should the value that we pass to these methods be static in our apps?
Suppose I have a simple read-only characteristic. This is how I update it:
void updateValue() { MyValue value = {/* initialize value */}; _ble.gattServer().write(_myCharacteristic.getValueHandle(), (const uint8_t*)&value, sizeof(value)); }
I.e. the value itself is local in the function. Is the above acceptable or not? The inline documentation doesn't seem to mention it at all (whereas it absolutely should!).
Similar question applies to GattCharacteristic family constructors that receive initial values.
1 Answer
7 years, 8 months ago.
Hi Hovik,
The value passed in the member function GattServer::write are copied. Your code is correct.
Similar question applies to GattCharacteristic family constructors that receive initial values.
The value in the GattCharacteristic will be copied by GattServer::addService, after the service has been added into the GattServer, values of the Characteristic are not accessed through the GattCharacteristic,