Using K_timer in Zephyr NCS 1.8.0 to initiate a BLE disconnection on Central

Hello,

I am using nRF Connect SDK 1.8.0 on the nRF52840.  I want to limit the amount of time that a peripheral can connect to my central 52840.  On connection start I initiate a timer following the K_timer convention set by zephyr and it times out properly.  I want to use the timeout handler function to call

int bt_conn_disconnect(struct bt_conn *conn, uint8_t reason)
 

I have used asynchronous functions to handle the connection and disconnection events but I had to register their callbacks using the struct 

static struct bt_conn_cb connection_callbacks
.  

Since there is no BLE event I'm timing out with, I wasn't sure how to get the bt_conn object to the timer's timeout handling function.  I assume that the on_connected or on_disconnected events are receiving the bt_conn object through the event handler, but I was not sure about this.  I tried to make the bt_conn object a static global var within the file, but in the timer handler the bt_conn_disconnect function fails with ENOTCONN (-128) so it seems it isn't accepting the bt_conn object correctly.

What would be the best way to correctly give the bt_conn object to the timer's timeout handling function here?

Thanks!

Parents
  • After looking further into this I found the 

    BT_LE_CONN_PARAM there is a supervision timeout.  Based on: https://docs.zephyrproject.org/2.6.0/reference/bluetooth/connection_mgmt.html
    the supervision timeout is the last parameter with N * 10 ms duration.  So if I understand correctly, setting this parameter to 3000 will cause the gateway to initiate a disconnection if 30 seconds pass without receiving anything from the sensor?
    This may accomplish what I want, but I'm worried about a case where the sensor is in an error state continuously sending data, this would cause the supervision timeout to never occur right?  Is there a way to timeout the connection within the BLE API or do I need to use a time as outlined in my original post?
    Thanks
Reply
  • After looking further into this I found the 

    BT_LE_CONN_PARAM there is a supervision timeout.  Based on: https://docs.zephyrproject.org/2.6.0/reference/bluetooth/connection_mgmt.html
    the supervision timeout is the last parameter with N * 10 ms duration.  So if I understand correctly, setting this parameter to 3000 will cause the gateway to initiate a disconnection if 30 seconds pass without receiving anything from the sensor?
    This may accomplish what I want, but I'm worried about a case where the sensor is in an error state continuously sending data, this would cause the supervision timeout to never occur right?  Is there a way to timeout the connection within the BLE API or do I need to use a time as outlined in my original post?
    Thanks
Children
No Data
Related