This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to prevent a client from writing an invalid value into a GATT characteristic?

Hello,

What is the best way to prevent a client from writing wrong values into a characteristic? For example, I created a writable uint8 characteristic on a nRF52832 that affects the duty cycle of a PWM in %. The Client that writes to the characteristic and therefore controls the duty cycle on the nRF52832 is at least a Bluetooth 4.2 smartphone. The valid values of the uint8 characteristic are between 5 to 100. I know I can specify the limits in the Smartphone App, too. But I would prefer to prevent clients from writing wrong values (e.g. 2, 123, ...) into the characteristic. How can I limit the valid range? I know there is a Valid Range Descriptor but as far as I understand this is only to inform the client about the valid range.

I found the following possibility to solve my problem but I'm wondering if this is still the recommended solution. If authorization is still the best solution which error code in response to a write request is recommended if a client tries to write an invalid characteristic value?

https://devzone.nordicsemi.com/f/nordic-q-a/4053/ble_gatts_evt_write---value-limit-control

Used SoC: nRF52832 

Used SD: S132 V6.1

Thanks.

Best regards,

Christian

Related