Page 1 of 1

How do I list clients/connections in NimBLE?

Posted: Sun Apr 24, 2022 9:34 pm
by nicklasb
Hi everybody!

New to this, and I need help. With hope to be able to give back at some point.

Anyway. I have looked all over on how to try to list, and then iterate over, any active connections to my peripheral/BLE server.
To no avail.

The ble_store seems to be empty regardless of object type (while the server is in full swing communicating with a client). ble_hs_conn_find() only seems to iterate over ble_hs_conns, and ble_hs_conn seems to be internal or something.
And I can't find much in the GAP stuff.
Yet it would be really weird if there can be a max connections setting and no list of connections to iterate over.

My goal is to not have to implement my own connection management and handle all those corner cases.

Anyone have any idea on how to enumerate connected clients/connections?

(my stuff is based on the https://github.com/espressif/esp-idf/tr ... oth/nimble examples)

Re: How do I list clients/connections in NimBLE?

Posted: Tue May 03, 2022 10:36 pm
by nicklasb
As per usual in these cases; I feel dumb as a post.

First, I didn't get that the peripheral examples didn't populate a peer list.
I had mashed the peripheral and central examples together into one and obscured that fact to myself.
Next, I made some mistakes in the code and misunderstood the SLIST_ macros.

But anyway, here is a working example on how to loop the list of peers implemented in peer.c:

Code: Select all

	struct peer *curr_peer;
        SLIST_FOREACH(curr_peer, &peers, next) {
            ESP_LOGI(task_tag, "Peer connection handle: %i", curr_peer->conn_handle); 
        }
Actually I had almost, and quite labouriously implemented my own connection tracking when this all dawned upon me.

So let's never talk about this again. :)