How to to know the UUID device on connect

I have an application that must manage different ble connection with different device (and so different UUID services). For the scanning and connection I used the bt_scan_filter_add for every UUID to filter the device's UUIDs with the autoconnect if match. Now the application connect to every devices found with the UUIDs I want, but for every device I have different routine to call. Hence, on the device connection callback, how could I know what device (UUID) is? I have only the bt_conn structure in the callback.

Parents
  • Hello,

    The connection object only includes information about the connection, such as the BLE address. It does not include information about what was included in the advertisement payload. However, you can use your scan_filter_match() callback to check which UUID filter a given device matched with and map this to a connection object.

    Best regards,

    Vidar

  • Ok. But now I'm trying to read the UUID in the scan_filter_match() callback but I can't. My callback is like

    void scan_filter_match_cb( struct bt_scan_device_info *device_info, struct bt_scan_filter_match *filter_match, bool connectable )
    {
    	char addr[ BT_ADDR_LE_STR_LEN ];
        char uuid[ BT_UUID_STR_LEN ];
    
    	bt_addr_le_to_str( device_info->recv_info->addr, addr, sizeof( addr ) );
        bt_uuid_to_str( filter_match->uuid.uuid, uuid, sizeof( uuid ) );
        LOG_INF( "Filters matched. Address: %s connectable: %d uuid: %s", addr, connectable, uuid );
    }

    but the uuid string is null. I get

    Filters matched. Address: C3:73:08:D3:D5:36 (random) connectable: 0 uuid 

    Am I fetching the uuid in the right way?

Reply
  • Ok. But now I'm trying to read the UUID in the scan_filter_match() callback but I can't. My callback is like

    void scan_filter_match_cb( struct bt_scan_device_info *device_info, struct bt_scan_filter_match *filter_match, bool connectable )
    {
    	char addr[ BT_ADDR_LE_STR_LEN ];
        char uuid[ BT_UUID_STR_LEN ];
    
    	bt_addr_le_to_str( device_info->recv_info->addr, addr, sizeof( addr ) );
        bt_uuid_to_str( filter_match->uuid.uuid, uuid, sizeof( uuid ) );
        LOG_INF( "Filters matched. Address: %s connectable: %d uuid: %s", addr, connectable, uuid );
    }

    but the uuid string is null. I get

    Filters matched. Address: C3:73:08:D3:D5:36 (random) connectable: 0 uuid 

    Am I fetching the uuid in the right way?

Children
Related