This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

disconnect if wrong characteristic should be written

Hi guys,

i have a service with more characteristics and more states. Not every characteristic should be available in each state. Thus there are services which are just allowed in one specific state.

If a device wants to write the wrong characteristic in a state, i just want to disconnect the connection (during the write operation). Is that allowed or is there a good way to disconnect during the write operation?

Like:

if ((p_evt_write->handle == p_ps->char_handle.value_handle) &&
    (p_evt_write->len < MAX_DATA_LENGTH) &&
    (p_ps->handler_char != NULL))
{
     if(incorrectState) { sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); }

}

Thanks in advance! greetings

Parents
  • You should force the central to do a service change operation to ensure that the services/characteristics are updates. It's possible to do so and that way make sure that the cached information about the peripheral is deleted and a new service discovery is done. Also, since you are moving through different states I would recommend that you disable the services you don't need. Worst case you can disconnect as you suggest.

  • Hi Asbjørn,

    thanks for our answer. So you would group all characteristics to services, and just enable thous which are allowed to write in the current state? If a service is not broadcasted, is it still possible to write it? (never tested it) :)

    The thing is, if i disconnect as i wrote in my question post, sometimes the connection hangs, and the peripheral do not disconnect. And i don't know where the problem is..

    Greetings

Reply
  • Hi Asbjørn,

    thanks for our answer. So you would group all characteristics to services, and just enable thous which are allowed to write in the current state? If a service is not broadcasted, is it still possible to write it? (never tested it) :)

    The thing is, if i disconnect as i wrote in my question post, sometimes the connection hangs, and the peripheral do not disconnect. And i don't know where the problem is..

    Greetings

Children
No Data
Related