Zephyr: How to get active Bluetooth connections

I can see all the options i have in the Bluetooth connection management but what I can't figure out is how to retrieve the bt_conn objects for the active connections. 
https://docs.zephyrproject.org/latest/connectivity/bluetooth/api/connection_mgmt.html

What I'm trying to do is see if there is something like:

main(){ 

while(1) { 

     if(BT_Connected){   // This is what I can't figure out, is there a handle for this? 

        power up sensor and read 

        send notification 

    } else{

        LOG_INF("no bluetooth connection") 
    }

wait 5 seconds

}


This must be something super simple but i'm running out of novel google queries to try. 

Parents
  • Would this make the most sense to pass as a callback to foreach? Or is there a more elegant way to accomplish this? 

    void connect_active(struct bt_conn *conn, void *data) {
    
        if (bt_conn_state(conn) == BT_CONN_CONNECTED) {
    
            //power up sensor 
             //send notificaiton 
             //power down sensor 
    
        }else{
    
            printk("Bluetooth connection is not established\n");
    
        }
    
    }
    
    
    void main(){
    
        bt_conn_foreach(connect_active, NULL);
    
        k_sleep(K_SECONDS(5));
    }

Reply
  • Would this make the most sense to pass as a callback to foreach? Or is there a more elegant way to accomplish this? 

    void connect_active(struct bt_conn *conn, void *data) {
    
        if (bt_conn_state(conn) == BT_CONN_CONNECTED) {
    
            //power up sensor 
             //send notificaiton 
             //power down sensor 
    
        }else{
    
            printk("Bluetooth connection is not established\n");
    
        }
    
    }
    
    
    void main(){
    
        bt_conn_foreach(connect_active, NULL);
    
        k_sleep(K_SECONDS(5));
    }

Children
No Data
Related