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

How to return invalid value size

Hi, I want to write a characteristic, the value size is fixed, for example the size is 4 bytes. When I try to wirte 6 bytes from the client, the first 4 bytes is writed succesfully and the last 2 bytes is droped.I want users know the value size is invalid. How can I return the message of size invalid to the client? Is there any example in the SDK? Thanks.

  • You can do that, but why bother reporting error if you are proceeding with 4 bytes anyway?

    You can return error NRF_ERROR_DATA_SIZE, that is, error number 12.

  • Thanks. If the user write the charactreistic with right size value, nothing need to report.But if the user write more than the max size of the characteristic, I want send a massage to let the user know the error. Which function I can use to send the message or response to inform the user app that the error data size has inputted?

  • Are you interested in sending status code in bluetooth? You may need to write this up and define the error codes. I was looking at ble_dfu.h and there are some hints in implementing this kind of tricks. If you look at this enum ble_dfu_resp_val_t, it is sent using ble_dfu_response_send function when a status needs to be reported to user.