BGX-to-BGX and BGX-to-Phone Smart Light Demo
Overview
Bluetooth Xpress supports Bluetooth 5 features including the coded PHY, 2M PHY, and multi-set advertising. With these features, a design can take advantage of the extended range enabled by the coded PHY when connecting to other Bluetooth Xpress modules, as well as the higher throughput provided by smart phones with 2M PHY capability. Multi-set advertising bridges these two use cases, enabling both a smart phone scanning for devices using the 1M PHY and a Bluetooth Xpress module scanning for devices using the coded PHY to discover the same peripheral.
This demo exercises these features and more to create a BLE-enabled light and switch. The light can be discovered using either a smart phone or another Bluetooth Xpress module operating as a light switch. The project also demonstrates how to enforce security through pairing controls by requiring that the user hold down a button during first-time connections.
Bluetooth Xpress Firmware Update
Note: this demo requires Bluetooth Xpress firmware version 1.1.1229.0 or higher. Silicon Labs provides a number of options for updating Bluetooth Xpress modules. For the purposes of this demo, users should download the BGX Commander mobile app and use its firmware update feature. The mobile app is available in both iOS and Android . Go here for more information about firmware update options.
Demo Setup
The BGX-to-phone connectivity portion of this demo requires a single Wireless Xpress BGX device and an EFM8UB1 Starter Kit.
If using a pair of EFM8UB1+BGX devices, the BGX-to-BGX features of the demo can also be tested, where one EFM8UB1 functions as a light and the second functions as the switch controlling the light.
Wireless Xpress BGX13P Starter Kit
This Wireless Xpress Starter Kit includes the Bluetooth Xpress BGX13P module and serves as a starting point to build applications for BGX. The BGX demo makes use of the starter kit's expansion header allowing for communication between the two starter kits. More guidance on this starter kit can be found in the User Guide , the BGX13P Data Sheet , and the BGX Development App Note .
EFM8UB1 Starter Kit
This MCU Starter Kit can serve as a starting point for host application development. The BGX demo makes use of the starter kit's push buttons, temp sensor, and expansion header. More guidance on this starter kit can be found in the User Guide , the Data Sheet , and the Schematic .
Downloading and Building
To get started, clone or download the Wireless Xpress Github directory here .
The demo firmware can be found at https://github.com/SiliconLabs/wireless-xpress/tree/master/products/BGX13/demos/longrangedemo .
To open the project and run it on an EFM8UB1, first make sure you've installed Simplicity Studio which can be found here .
Run Simplicity Studio and open the Simplicity IDE. Once opened, right click in the Project Explorer window and choose Import Project.
In the dialog that appears, navigate to the following directory:
../EFM8UB1_LongRangeDemo_BGX/SimplicityStudio
Make sure that the 8051 SDK has been selected as the SDK used by the project. Click 'Next' and 'Finish' to import the project. Connect the BGX13P EXP board to the EFM8UB1 board, and then connect USB to the EFM8UB1 board. Once connected, download code using the download and debug button in Simplicity IDE.
Once the download finishes, run the code by clicking the run button.
Demo Features
After initializing the Bluetooth Xpress module and MCU peripherals, the project allows users to select 'light' mode or 'switch'. Making a selection with the STK's push buttons causes the firmware to enter either of these modes for the remainder of runtime. To get back to this screen, simply press the reset button on the STK. Resetting the STK will reset the Bluetooth Xpress module and return the demo back to the startup screen.
Light Mode Operation
Light mode accepts commands from a connected Bluetooth Xpress module or a smart phone to control the state of an LED on the STK. The screen shows connection status (none/LR PHY/1/2M PHY) and whether bonding is enabled.
Holding down PB1 enables bonding during pairing, and PB0 clears all bond information stored on the Bluetooth Xpress module.
Once a Bluetooth Xpress module or smartphone has connected to the light, firmware adjusts the color and on/off state of the RBG LED on the STK when it receives switching commands.
Switch Mode Operation
When in switch mode, the firmware scans on the coded 'long range' PHY to discover advertising lights. When the user selects switch mode, the firmware immediately goes into a loop that scans for lights, displays scan results, and attempts to connect to the light the user selects.
The demo also exposes controls to clear bond information stored on the scanning Bluetooth Xpress module.
Once connected, the LCD shows controls available to adjust the color and on/off state of the connected light.
Advertising on Multiple PHYs
In this demo, 'switch' mode Bluetooth Xpress modules scan on the 125K coded 'long range' PHY, while smart phones running BGX Commander use the 1M PHY to scan and connect. Bluetooth Xpress can be configured to advertise on both of these PHYs, automatically switching between the two PHYs and responding upon discovery. Note that Bluetooth Xpress modules support one connection at a time, and advertising on all PHYs stops once a connection is established.
Firmware configures these features in the void Light_configureBGX(void) function, found in light.c in the demo source code.
Firmware enables this feature by setting the BLE PHY multiplex variable to 1:
> BGX_Write("set bl p m 1\r\n");
Bluetooth Xpress modules can advertise on the 125K coded PHY. Upon connection, the module can be switched to use the 500K coded PHY if necessary. This demo uses the 125K coded PHY both the light and switch modes during BGX-to-BGX communication. This selection is made using the BLE PHY preference variable .
> BGX_Write("set bl p p 125k\r\n");
Coded PHY Communication
When the demo enters switch mode in scanning.c, the initialization routine Scanning_configureBGX() configures the Bluetooth Xpress module to use the 125K coded PHY.
> BGX_Write("set bl p p 125k\r\n");
The demo calls into scanning control functions in bgx.c to start and stop the scan, as well as a function to read scan results from the module. Within those functions, firmware initiates scans with this call to the Bluetooth Xpress module.
> BGX_Write("scan\r\n");
Pairing Control
Bluetooth Xpress modules require encrypted communication to access the Xpress Streaming Service and enter stream mode. Because establishing an encrypted link requires a successful pairing between the central and peripheral, access to a Bluetooth Xpress's stream can be protected by disabling pairing.
The demo shows a method of controlling access by disabling pairing unless a user holds down a button on the light mode STK when a switch mode STK or smart phone attempts a connection.
Pairing is controlled with the BLE encryption pairing mode variable Firmware enables pairing when the user holds down PB1 in the light.c function called Light_BGXenablePairing(void).
> BGX_Write("set bl e p any\r\n");
Any time PB1 is not pressed on the STK running in light mode, the Light_BGXdisablePairing(void) function disables pairing.
> BGX_Write("set bl e p off\r\n");
The demo configures the Bluetooth Xpress modules to save bond information during pairing when possible. This is the default setting for the encryption bondable mode and so this firmware leaves that setting at its default.
After bonding information is successfully stored, bonded Bluetooth Xpress modules and smart phones can connect without pairing again. In this demo, modules and phones can connect without the need to hold down PB1 again once paired and bonded, until bonding information is cleared on either the light mode STK, the switch mode STK, or the smart phone.
Connection Failure and Recovery
Attempting a connection to a light mode STK without first bonding and with pairing disabled will result in a failed connection due to 'security mismatch'. Users will also see a security mismatch during connection if bond information is cleared on either side of the connection link.
The connection command description goes over different connection result behaviors in detail. This demo enables users to see these different connection failures by offering bond-clearing controls in both light and switch modes.
Recovery mechanisms for failed connection attempts with Bluetooth Xpress usually consist of clearing bond information and attempting to connect again, as can be seen in the connection loop section of Scanning_main(void) in scanning.c. The demo clears bond information with the clear bond command , as shown below:
> BGX_Write("clrb\r\n");