Close
Objective:
This blog post discusses implementation of BLE Proximity Profile in CYW20819 using the device configurator tool in ModusToolBox IDE.
Requirment:
Tool: ModusToolBox 1.1 or above, Serial Terminal (Example: TeraTerm, CoolTerm)
Programming Language: C
Associated Parts: CYW20819
Related Hardware: CYW920819EVB-02 Board (2 boards required)
Proximity Profile:
The purpose of proximity profile is to keep an eye on the BLE Connection link between two devices and trigger an alert when the link is weakened as path loss increases. This profile supports two roles:
The proximity profile must include the Link Loss Service. It may optionally include Tx Power Service and Immediate alert service also. Link Loss Service: The GATT DB of the link loss service has the “Alert Level” characteristic which may be written by the proximity client. This indicates the level of alert to be triggered in the server when the disconnection happens.Tx power Service: The proximity client may anytime know the Transmitter Power level of the server. This is enabled by reading the Tx Power level characteristic included in the Tx power service.Immediate Alert Service: The proximity monitor may keep calculating the path loss as follows:
Path Loss = Tx Power Level – RSSI
If the path loss exceeds a certain threshold, the monitor may write the Alert Level characteristic of the IAS, thereby prompting the user to perform appropriate action to avoid disconnection.
Block Diagram:
Using the Device Configurator to generate Proximity Server project:
We can use the Device Configurator Tool in ModusToolBox IDE to generate the GATT DB and an outline code for the firmware. For more details on using the Device Configurator, refer to the Bluetooth Designer Guide in WICED Studio SDK. The GATT DB of the Proximity Server has 3 different services. It is easy to generate the GATT DB and a skeleton code using the Bluetooth Device Configurator Tool.
3. Using the “Add Service” Option, different services are selected.
4. Add the characteristics as shown above and save the configuration to obtain the skeleton project. The files will be
Firmware: This example contains two projects – The proximity server and the proximity client. Proximity Server: A skeleton code of the proximity server can be generated using the above steps. Certain key features need to be added to the skeleton code to make the server project complete. According to the specification, a proximity reporter has to advertise with the UUID of Link Loss Service. So, the advertisement data should be modified as follows
:/* Set Advertisement Data */
void proximityserver_set_advertisement_data( void )
{ wiced_bt_ble_advert_elem_t adv_elem[3] = { 0 };
uint8_t adv_flag = BTM_BLE_GENERAL_DISCOVERABLE_FLAG | BTM_BLE_BREDR_NOT_SUPPORTED;
uint8_t num_elem = 0;
/* Advertisement Element for Flags */
adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_FLAG;
adv_elem[num_elem].len = sizeof(uint8_t);
adv_elem[num_elem].p_data = &adv_flag;
num_elem++;
adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_16SRV_COMPLETE;
adv_elem[num_elem].len = sizeof(lls_uuid);
adv_elem[num_elem].p_data = ( uint8_t* )lls_uuid;
num_elem++;
/* Advertisement Element for Name */
adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_NAME_COMPLETE;
adv_elem[num_elem].len = strlen((const char*)BT_LOCAL_NAME);
adv_elem[num_elem].p_data = BT_LOCAL_NAME;
num_elem++;
/* Set Raw Advertisement Data */
wiced_bt_ble_set_raw_advertisement_data(num_elem, adv_elem);
}
Where lls_uuid is declared and initialized as:
/* Link Loss service UUID */
const uint8_t lls_uuid[2] = {(uint8_t)UUID_SERVICE_LINK_LOSS & 0xFF, (uint8_t)(UUID_SERVICE_LINK_LOSS >> 😎 };
The proximity server receives Link Loss and IAS Alerts in the form of writes. The IAS Alert is triggered instantaneously whereas the link loss alert happens when there is a disconnection. The Alerts are indicated by the LEDs. Proximity Client: This is a central / client device that performs read / write operations with the GATT DB of the server. The central starts scanning for peripherals that advertise with a Link Loss Service UUID, upon a GPIO button press and initiates the connection. Then it begins to discover all the three services of the proximity profile in the server, one by one and saves the handles of the attributes. Following this, the TX power characteristic of the server is read. Now the client periodically calculates the RSSI every 100 mS and thus the average path loss. If the path loss reaches beyond certain thresholds, the client writes to the Immediate alert characteristics of the server, resulting in an immediate trigger. The thresholds are as follows: MILD ALERT: Path loss above 90 dB HIGH ALERT: Path loss above 100 dBThe Link loss alert can be written to the server by pressing the GPIO Interrupts on the client Eval Board. Every time the GPIO is pressed, a different LL alert value is written to the server.
Programming and Testing:
Path Loss Vs Distance:
For a Tx Power of 4 dBm in CYW20819, the path loss Vs Distance values are observed as below in an office environment
Related Documents:
The below table lists all relevant application notes, code examples, knowledge base articles, device datasheets, and Component / user module datasheets.
Document |
Title |
Comment |
002-25684 |
AN225684 - Getting Started with CYW20819 |
The Getting Started Guide can be downloaded from here. |
002-26340 |
CYW920819EVB-02 Evaluation Kit User Guide |
This Evaluation Kit User Guide can be downloaded from here. |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.