KBA_BT_0508: Scanning BLE beacons in Bluetooth Mesh mode
07/192/2019 | 05:05 AM
Introduction
Bluetooth mesh is based on advertisements, meaning that under the hood the stack is scanning all the time. By default, the scan response events are not passed to the application but they are just consumed by the mesh stack and then silently discarded.
This article illustrated a way to scan BLE advertisements when the Bluetooth mesh stack is running. It uses advertising event filter which allows you to configure which type of events you want to have exposed to the application. It can be used to scan mesh nodes and possibly report the advertisements found to a master node which processes the data.
Implementation
Step1: Configure the advertising event filter by adding this in your boot event handler. For more details about the command refer the Bluetooth Mesh Software API reference manual.
0x7: Enabled advertising packet type mask. This indicates the advertisement could be Connectable undirected, Scannable undirected or, Non connectable undirected advertising.
Step 2: Handle the scan response event by adding following case to the handle_gecko_event() function:
case gecko_evt_le_gap_scan_response_id:
print_scan_resp(&(evt->data.evt_le_gap_scan_response));
break;
Step 3: Add a function that handles the BLE scan responses, here's a sample:
static void print_scan_resp(struct gecko_msg_le_gap_scan_response_evt_t *pResp)
{
// decoding advertising packets is done here. The list of AD types can be found
// at: https://www.bluetooth.com/specifications/assigned-numbers/Generic-Access-Profile
// example of adv data including proxy service data:020106030328180c16281800f03f4f79774c65a2
// (UUID 0x1828)
// 020106-03032818-0c16281800f03f4f79774c65a2
const uint8 proxy_UUID[2] = {0x28, 0x18};
int i = 0;
int ad_match_found = 0;
int ad_len;
int ad_type;
while (i < (pResp->data.len - 1))
{
ad_len = pResp->data.data[i];
ad_type = pResp->data.data[i+1];
if (ad_type == 0x03)
{
// type 0x03= Complete List of 16-bit Service Class UUIDs
if(memcmp(proxy_UUID, &(pResp->data.data[i+2]),2) == 0)
{
ad_match_found = 1;
}
}
//jump to next AD record
i = i + ad_len + 1;
}
if(ad_match_found)
{
for(i=5;i>=0;i--)
{
printf("%2.2x", pResp->address.addr[i]);
}
printf(", RSSI: %d\r\n", pResp->rssi);
}
}
The above code looks through advertising data in scan response events and searches for the mesh proxy UUID 0x1828. If a proxy advertisement is found, the address of the sender and RSSI are printed to debug output.
Testing
In Simplicity Studio, select your radio board, select the latest Bluetooth Mesh SDK and create soc-btmesh-light example project for your device.
Copy and replace the attached file (app.c) into your project.
Compile and flash to your radio board.
Open serial console and observe the print statements.
On another radio board, flash any Bluetooth mesh application consisting of the Mesh Proxy service with UUID 0x1828 and provision it.
This functionality was tested with two BGM13P22 radio boards and v1.4.3 of the Silabs Bluetooth Mesh stack.
KBA_BT_0508: Scanning BLE beacons in Bluetooth Mesh mode
Introduction
Bluetooth mesh is based on advertisements, meaning that under the hood the stack is scanning all the time. By default, the scan response events are not passed to the application but they are just consumed by the mesh stack and then silently discarded.
This article illustrated a way to scan BLE advertisements when the Bluetooth mesh stack is running. It uses advertising event filter which allows you to configure which type of events you want to have exposed to the application. It can be used to scan mesh nodes and possibly report the advertisements found to a master node which processes the data.
Implementation
Step1: Configure the advertising event filter by adding this in your boot event handler. For more details about the command refer the Bluetooth Mesh Software API reference manual.
0x7: Enabled advertising packet type mask. This indicates the advertisement could be Connectable undirected, Scannable undirected or, Non connectable undirected advertising.
Step 2: Handle the scan response event by adding following case to the handle_gecko_event() function:
Step 3: Add a function that handles the BLE scan responses, here's a sample:
The above code looks through advertising data in scan response events and searches for the mesh proxy UUID 0x1828. If a proxy advertisement is found, the address of the sender and RSSI are printed to debug output.
Testing
In Simplicity Studio, select your radio board, select the latest Bluetooth Mesh SDK and create soc-btmesh-light example project for your device.
Copy and replace the attached file (app.c) into your project.
Compile and flash to your radio board.
Open serial console and observe the print statements.
On another radio board, flash any Bluetooth mesh application consisting of the Mesh Proxy service with UUID 0x1828 and provision it.
This functionality was tested with two BGM13P22 radio boards and v1.4.3 of the Silabs Bluetooth Mesh stack.