My system is a BLE peripheral with 2 states. There is a characteristic that represents the state, and it can take 2 values: 0 and 1. You can read the state, write it (force the system to change state), or be notified (be informed when system state changes).
I understood how to set the initial value, and my handler gets called when there is a write. But what happens if I write "0x02" to the characteristic ? my write handler won't do anything as the state is not valid, but the characteristic will take "2" as the value !! How do I prevent that ? In other words, how should I synchronize my internal state and the characteristic's value ?
I tried to use attr_md.vloc = BLE_GATTS_VLOC_USER;
and I did attr_char_value.p_value = &my_internal_state
but that doesn't seem to help. What should be the correct way ?
Thanks
P.S Im using sdk 8.1