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

Validating characteristic write before it's actually written?

Hi,

Is it possible to validate the value of a characteristic write operation and ignore it if it's not within my set parameters?

I.e. in the BLE_GATTS_EVT_WRITE event, I'd like to do some validation checking on the received write value and ignore it if I don't like it.

Right now whenever a write comes through and then I do a read, it immediately shows the new value.

I thought that's what ble_add_char_params_t.is_value_user true would do, but that also updates the buffer immediately on a write.

SDK 17.0.2 on a nRF52840

Thanks.

  • Hello,

    Is it possible to validate the value of a characteristic write operation and ignore it if it's not within my set parameters?

    Could you elaborate what you mean by this? Would you like the peripheral to check the value written to a characteristic (seeing if it is within a certain range, for example) before updating the value of the characteristic?
    If so, you may not do this by using the write operation. The SoftDevice will update the characteristic when the write is received.
    If you would like to run application layer logic before updating the value you will need to pass 
    You could use a second characteristic for this. So, if you have a read-only characteristic A representing a status of some kind, and a writable characteristic B which can be written to initiate a state-change. Then, you could in your application layer check the value written to B whenever that happens, and see if it should trigger an update of characteristic A, for example.

    If this is not the functionality you were looking for, or in the case that I have misunderstood your question, please elaborate on your intended functionality.

    Best regards,
    Karl

  • Would an authorized write work for this use case?

    At least for reads the authorized version works just like this, you get a chance to run application code and decide whether to allow the read. I haven't used the authorized write myself but I thought it works the same way.

Related