- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is it possible to operate as a BLE Central and Peripheral simultaneously?
Whenever my design is in an active ADV state, or if the design has an active connection as a Peripheral (GATT Server), I am not able to connect to anything as a Central. I can initiate scanning and attempt a connection by calling wiced_bt_gatt_le_connect() but the connection never completes - I never get a GATT callback, ie, this callback never happens:
gatt_status = wiced_bt_gatt_register( sensortag_cloud_gatts_callback );
This used to work on previous SDK releases.
Solved! Go to Solution.
- Labels:
-
Wifi+Bluetooth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Closing this query
The use case works on AVNET kit (BCM94343W_AVN )board
As a summary to enable both BLE peripheral/Central on WICED SDK perform the following steps
Sequence for simultaneous BLE Central/Peripheral
- 1> Init the BT stack with a management callback
/* Register call back and configuration with stack */
wiced_bt_stack_init( hello_sensor_management_callback ,&wiced_bt_cfg_settings, wiced_bt_cfg_buf_pools );
- 2> In the management callback on receiving BTM_ENABLED, I register for GATT and then start adv , and then start scan
static wiced_result_t hello_sensor_management_callback( wiced_bt_management_evt_t event, wiced_bt_management_evt_data_t *p_event_data )
{
WPRINT_BT_APP_INFO(("hello_sensor_management_callback: %x\n", event ));
switch( event )
{
/* Bluetooth stack enabled */
case BTM_ENABLED_EVT:
// Register for GATT callback
// Start ADV
Regards
Prejith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Look at libraries/daemons/bt_internet_gateway/internal/big_stack_interface.c for "big_init_gatt_server_interface" & "big_add_gatt_client_interface"
The former establish an unique static structure "gatt_server_interface" which should work for the peripheral you desired.
And the latter is for central role connections.
You can find how BTM / GATT events are dispatched to according interface/connection in "big_stack_callback" & "big_gatt_callback"
They may not work perfectly for your purpose out of box.
And I don't see any sample code that runs peripheral & central at the same time.
It is very likely that some tweaks are needed.
Maybe Cypress team can make some comments about this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi andrew997
Can you share your app , so that we can review it , I am suspecting that you have registered the callback twice ?
Kindly check the below order
1> Init the stack once
2> Register the GATT callback only once [for server and client only one registration is required ]
3> initialize your gatt db and start adv
4> if you wish to scan use wiced_bt_ble_scan and pass a callback function
5> if a remote LE client connects to you , you will receive GATT_CONNECTION_STATUS_EVT , and to know if this connection was for client or server , you can use the parameter wiced_bt_gatt_connection_status_t.link_role : if Link role is 0 then you are slave meaning its a peripheral , and if link role is 1 then you are client
Regards
Prejith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've posted my app on the Avnet cloudconnectkits.org site:
Example App: Sensor-to-Cloud Using TI SensorTag and Watson IoT Quickstart | Avnet CloudConnectKits
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi andrew997
Can you increase the buffer pool for HCI and try it out , it worked for me , Since connection are dependent on HCI pool I increased pool number 2
const wiced_bt_cfg_buf_pool_t wiced_bt_cfg_buf_pools[WICED_BT_CFG_NUM_BUF_POOLS] =
{
/* { buf_size, buf_count } */
//{ 64, 4 }, /* Small Buffer Pool */
{ 64, 32 }, /* Small Buffer Pool */
// { 360, 4 }, /* Medium Buffer Pool (used for HCI & RFCOMM control messages, min recommended size is 360) */
{ 360, 8 }, /* Medium Buffer Pool (used for HCI & RFCOMM control messages, min recommended size is 360) */
{ 360, 4 }, /* Large Buffer Pool (used for HCI ACL messages) */
{ 360, 0 }, /* Extra Large Buffer Pool - Used for avdt media packets and miscellaneous (if not needed, set buf_count to 0) */
};
Regards
Prejith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Prejith,
This still doesn't seem to do it for me. I tried increasing the buffer pools as such:
const wiced_bt_cfg_buf_pool_t wiced_bt_cfg_buf_pools[WICED_BT_CFG_NUM_BUF_POOLS] =
{
/* { buf_size, buf_count } */
//{ 64, 4 }, /* Small Buffer Pool */
{ 64, 32 }, /* Small Buffer Pool */
// { 360, 4 }, /* Medium Buffer Pool (used for HCI & RFCOMM control messages, min recommended size is 360) */
{ 360, 16 }, /* Medium Buffer Pool (used for HCI & RFCOMM control messages, min recommended size is 360) */
{ 360, 4 }, /* Large Buffer Pool (used for HCI ACL messages) */
{ 360, 0 }, /* Extra Large Buffer Pool - Used for avdt media packets and miscellaneous (if not needed, set buf_count to 0) */
};
Is there an API that can keep track of available and/or when a buffer pool is requested?
Thanks!
Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Andrew
Its strange , can you tell me the exact version of the SDK you are using ? , are you using 3.7.0 ?
I shall take a look at this tomorrow and let you know
Can you enable the GLOBAL_DEFINES += ENABLE_BT_PROTOCOL_TRACES in your make file and send me the logs
Below was the behavior in my environment
1> device boots up and connects to MQTT and starts a BLE adv WICED Sense Kit
2> On Light blue i have created a virutal peripheral with a name CC2650
3> I press the user button on the avnet kit , adv stops and scan starts , on finding the device CC2650 , connection is issued
4> I also tried with peripheral connection , intiating a scan even then went through
Try to give me your logs with PROTOCOL_TRACES enabled , so that i can root cause the exact issue
Regards
Prejith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Prejith,
I'll try your suggestion but really quickly, I made some changes in my app to prevent it from advertising and scanning at the same time, at least until I can find a workaround for this. In the meantime, if you go to line ~408 and add the following, it will start scanning at the same time it's advertising:
// Test - start a scan |
wiced_gpio_output_high( WICED_LED1 );
wiced_bt_ble_scan( BTM_BLE_SCAN_TYPE_HIGH_DUTY, WICED_TRUE, sensortag_cloud_result_cback );
In this situation, what will happen is if it finds a Sensortag, it won't be able to successfully connect. That's why I put the other code in to make it stop advertising when you push the button.
Regards,
Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I added:
GLOBAL_DEFINES | += ENABLE_BT_PROTOCOL_TRACES |
..to the .mk file but this didn't generate any additional output to the console. Is there something else I need to enable?
When my app is programmed to stop advertising right before it starts scanning, here's the console output I get:
[MQTT] Opening connection...Client ID...d:quickstart:iotqs-sensor:6CADF8F0EDB6
Starting Advertising for Wi-Fi Config GATT service.
---->>> New ADV state: 3
---->>> New ADV state: 0
---->>> New ADV state: 0
---->>> New Scan state: 1
---->>> New ADV state: 0
Found BD_ADDR: B0B448CFAE04, CC2650 SensorTag, length 16
Found Sensor, Connection = 0, Type = 1, initiating connection
---->>> New Scan state: 0
Key retrieval failure
Key retrieval failure
wiced_bt_gatt_connect status 1
sensortag_cloud_gatts_connection_status_handler: connection UP! conn_id: 2, active_connections=1,link_role 0
write_rsp status:0x0
write_rsp status:0x0
write_rsp status:0x0
write_rsp status:0x0
write_rsp status:0x0
write_rsp status:0x0
write_rsp status:0x0
write_rsp status:0x0
write_rsp status:0x0
write_rsp status:0x0
write_rsp status:0x0
write_rsp status:0x0
write_rsp status:0x0
write_rsp status:0x0
write_rsp status:0x0
iot-2/evt/SensorTag_CF:AE:04/fmt/json, {"d":{"Accel_X":0.00,"Accel_Y":0.00,"Accel_Z":0.00}}
iot-2/evt/SensorTag_CF:AE:04/fmt/json, {"d":{"Accel_X":3.99,"Accel_Y":3.86,"Accel_Z":0.22}}
iot-2/evt/SensorTag_CF:AE:04/fmt/json, {"d":{"Accel_X":3.99,"Accel_Y":3.87,"Accel_Z":0.19}}
..... and so on and so on
When I enable scanning at the same time I'm advertising, here's what happens when the app attempts to connect to the SensorTag peripheral that was scanning:
[MQTT] Opening connection...Client ID...d:quickstart:iotqs-sensor:6CADF8F0EDB6
Starting Advertising for Wi-Fi Config GATT service.
---->>> New ADV state: 3
---->>> New Scan state: 1
Found BD_ADDR: B0B448D02203, CC2650 SensorTag, length 16
Found Sensor, Connection = 0, Type = 1, initiating connection
---->>> New Scan state: 0
Key retrieval failure
Key retrieval failure
wiced_bt_gatt_connect status 1
---->>> New Scan state: 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Closing this query
The use case works on AVNET kit (BCM94343W_AVN )board
As a summary to enable both BLE peripheral/Central on WICED SDK perform the following steps
Sequence for simultaneous BLE Central/Peripheral
- 1> Init the BT stack with a management callback
/* Register call back and configuration with stack */
wiced_bt_stack_init( hello_sensor_management_callback ,&wiced_bt_cfg_settings, wiced_bt_cfg_buf_pools );
- 2> In the management callback on receiving BTM_ENABLED, I register for GATT and then start adv , and then start scan
static wiced_result_t hello_sensor_management_callback( wiced_bt_management_evt_t event, wiced_bt_management_evt_data_t *p_event_data )
{
WPRINT_BT_APP_INFO(("hello_sensor_management_callback: %x\n", event ));
switch( event )
{
/* Bluetooth stack enabled */
case BTM_ENABLED_EVT:
// Register for GATT callback
// Start ADV
Regards
Prejith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for sharing this with the group prejithp
Adding the Avnet team as well since this is useful information for them as well: peter_fenn andrew997