This project demonstrates a Bluetooth door lock application using Silicon Labs development kits, SparkFun Micro OLED Breakout (Qwiic) board, Cap Touch 2 Click MikroE board, and BUZZ 2 click Mikroe board.
In this example, we use some security features of BLE such as pairing, bonding and setting up the attribute permissions for higher reliability.
The block diagram of this application is shown in the image below:
More detailed information can be found in the section How it works
This code example referred to the following code examples. More detailed information can be found here:
- SDK version
- Software Required
- Hardware Required
- Connections Required
- Setup
- How It Works
- Report Bugs & Get Support
- 1x Bluetooth Low Energy Explorer Kit. For example, BGM220-EK4314A
- 1x SparkFun Micro OLED Breakout (Qwiic)
- 1x Cap Touch 2 Click
- 1x BUZZ 2 click
- 1x smartphone running the 'Simplicity Connect' mobile app
The hardware connection is shown in the image below:
The SparkFun Micro OLED Breakout (Qwiic) board can be easily connected by using a Qwiic cable. Use jumper wires to connect the Explorer kit with the Cap touch board and Buzzer board.
The pin connection is shown in the image below:
To test this application, you can either create a project based on an example project or start with a "Bluetooth - SoC Empty" project based on your hardware. You should connect the BMG220 Explorer Kit Board to the PC using a MicroUSB cable.
Note
-
Make sure that the Third Party Hardware Drivers extension is installed as part of the SiSDK and the bluetooth_applications repository is added to Preferences > Simplicity Studio > External Repos.
-
SDK Extension must be enabled for the project to install the required components.
-
From the Launcher Home, add the BRD4314A to My Products, click on it, and click on the EXAMPLE PROJECTS & DEMOS tab. Find the example project filtering by 'door lock'.
-
Click Create button on the Bluetooth - Door Lock example. Example project creation dialog pops up -> click Create and Finish and Project should be generated.
-
Build and flash this example to the board.
-
Create a Bluetooth - SoC Empty project for your hardware using Simplicity Studio 5.
-
Copy the .c files 'src/app.c' to the following directory of the project root folder (overwriting the existing files).
-
Open the .slcp file. Select the SOFTWARE COMPONENTS tab and install the software components:
- [Services] → [Timers] → [Sleep Timer]
- [Bluetooth] → [Bluetooth Host (Stack)] → [Additional Features] → [NVM Support]
- [Services] → [IO Stream] → [IO Stream: EUSART] → default instance name: vcom
- [Application] → [Utility] → [Log]
- [Platform] → [Driver] → [GPIOINT]
- [Platform] → [Driver] → [I2C] → [I2CSPM] → default instance name: qwiic
- [Platform] → [Driver] → [PWM] → [PWM] → default instance name: mikroe
- [Platform] → [Driver] → [SPI] → [SPIDRV] → default instance name: mikroe
- [Platform] → [Driver] → [LED] → [Simple LED] → default instance name: led0
- [Third Party Hardware Drivers] → [Audio & Voice] → [CMT_8540S_SMT - Buzz 2 Click (Mikroe)]
- [Third Party Hardware Drivers] → [Display & LED] → [SSD1306 - Micro OLED Breakout (Sparkfun) - I2C]
- [Third Party Hardware Drivers] → [Services] → [GLIB - OLED Graphics Library]
- [Third Party Hardware Drivers] → [Human Machine Interface] → [CAP1166 - Capacitive Touch 2 Click (Mikroe)]
- [Bluetooth] → [OTA] → [In-Place OTA DFU] → uninstall
- [Platform] → [Bootloader Application Interface] → uninstall.
-
Import the GATT configuration:
- Open the .slcp file in the project again.
- Select the CONFIGURATION TOOLS tab and open the "Bluetooth GATT Configurator".
- Find the Import button and import the gatt_configuration.btconf file.
- Save the GATT configuration (ctrl-s).
-
Build and flash this project to the board.
The following diagram shows the main flowchart of this demo:
Once the password is entered, the buzzer plays a sound, and the OLED displays the password with the '*' character. The user should enter the password to unlock the door from the capacitive sensor. If the password is correct, the LED will turn on, the OLED will show Unlock for a few seconds. If it is wrong, it will display Lock and allow you to re-enter it from the beginning. Users can change the door unlock password over BLE, see the Change the door unlock password.
The application is based on the Bluetooth - SoC Empty example. Since the example already has the Bluetooth GATT server, advertising, and connection mechanisms, only minor changes are required.
The GATT changes were adding a new custom service using UUID 02AE647B-83B7-45AA-AA59-D3DDFEE325E9 that has a characteristic UUID 8AF6DEB2-B277-49F9-A4F2-14210C6766CF. The new_password characteristic only has a written property with permission level encrypted and bonded, which means that the characteristic can be written only on encrypted and bonded connections. This protects against password alteration by a third party. The new_password characteristic has a user data type and 6-bytes length.
The GATT should contain the following services and characteristics:
| Name | UUID |
|---|---|
| door_lock | 02AE647B-83B7-45AA-AA59-D3DDFEE325E9 |
Characteristic properties:
| Name | Value Type | UUID | Security | Properties | Comment |
|---|---|---|---|---|---|
| new_password | User data | 8AF6DEB2-B277-49F9-A4F2-14210C6766CF | Pairing and bonding required | Write | Write with a response. |
Follow the below steps to test the example with the Simplicity Connect application:
- Open the Simplicity Connect application on your smartphone and allow the permission request when opened for the first time.
- Click [Develop] -> [Browser] and you will see a list of nearby devices which are sending Bluetooth advertisements.
- Find the one named Door Lock and click the connect button on the right side. For iOS devices, enter the passkey
(passkey default as 123456)to confirm authentication for the pairing process for the first time. For Android devices, the user must accept a pairing request first and do as above. After that, wait for the connection to be established and the GATT database to be loaded.
Note
The pairing process on Android and iOS devices is different. For more information, refer to Bluetooth security.
The door unlock password and the passkey to connect with the mobile device will both be changed and will be the same as each other when updating the new_password characteristic.
To change both of them, the user must write a new password which has 6 bytes to the Ascii string field in the new_password characteristic. If the length of the new password is not 6 bytes then, an INVALID ATTRIBUTE VALUE LENGTH error will be thrown out. If the user writes to the new_password characteristic successfully, a new password will be updated in non-volatile memory. By contrast, the password will not be updated.
To report bugs in the Application Examples projects, please create a new "Issue" in the "Issues" section of bluetooth_applications repo. Please reference the board, project, and source files associated with the bug, and reference line numbers. If you are proposing a fix, also include information on the proposed fix. Since these examples are provided as-is, there is no guarantee that these examples will be updated to fix these issues.
Questions and comments related to these examples should be made by creating a new "Issue" in the "Issues" section of bluetooth_applications repo.