Skip to content

Commit fd039b1

Browse files
Bluetooth Applications v2.0.3
1 parent a357528 commit fd039b1

16 files changed

+577
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# Silicon Labs Bluetooth Applications #
1515

16-
[![Version Badge](https://img.shields.io/badge/-v2.0.2-green)](https://github.com/SiliconLabs/bluetooth_applications/releases)
16+
[![Version Badge](https://img.shields.io/badge/-v2.0.3-green)](https://github.com/SiliconLabs/bluetooth_applications/releases)
1717
[![GSDK Badge](https://img.shields.io/badge/GSDK-v4.4.0-green)](https://github.com/SiliconLabs/gecko_sdk/releases)
1818
[![TPHD Version Badge](https://img.shields.io/badge/TPHD-v2.0.0+-green)](https://github.com/SiliconLabs/third_party_hw_drivers_extension/releases)
1919
![License badge](https://img.shields.io/badge/License-Zlib-green)
@@ -83,6 +83,7 @@ This repository provides both SLCP projects (as External Repositories) and SLS p
8383
| 55 | Bluetooth - HID Multiple Reports | [Click Here](./bluetooth_hid_multiple_reports/) |
8484
| 56 | Bluetooth - ESL Tag with E-Paper display 1,54inch 200x200 dots from Mikroe | [Click Here](./bluetooth_esl_tag_mikroe_eink154_e_paper_display) |
8585
| 56 | Bluetooth - RSSI - based position estimation for PEPS | [Click Here](./bluetooth_rssi_positioning_for_peps) |
86+
| 57 | Bluetooth - BTHome v2 - PIR Alarm | [Click Here](./bluetooth_bthome_v2_pir_alarm/) |
8687

8788
## Requirements ##
8889

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Bluetooth - BTHome v2 - PIR Alarm #
2+
3+
![Type badge](https://img.shields.io/badge/dynamic/json?url=https://raw.githubusercontent.com/SiliconLabs/application_examples_ci/master/bluetooth_applications/bluetooth_bthome_v2_pir_alarm_common.json&label=Type&query=type&color=green)
4+
![Technology badge](https://img.shields.io/badge/dynamic/json?url=https://raw.githubusercontent.com/SiliconLabs/application_examples_ci/master/bluetooth_applications/bluetooth_bthome_v2_pir_alarm_common.json&label=Technology&query=technology&color=green)
5+
![License badge](https://img.shields.io/badge/dynamic/json?url=https://raw.githubusercontent.com/SiliconLabs/application_examples_ci/master/bluetooth_applications/bluetooth_bthome_v2_pir_alarm_common.json&label=License&query=license&color=green)
6+
![SDK badge](https://img.shields.io/badge/dynamic/json?url=https://raw.githubusercontent.com/SiliconLabs/application_examples_ci/master/bluetooth_applications/bluetooth_bthome_v2_pir_alarm_common.json&label=SDK&query=sdk&color=green)
7+
[![Required board](https://img.shields.io/badge/Mikroe--green)](https://www.mikroe.com/pir-click)
8+
![Build badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/SiliconLabs/application_examples_ci/master/bluetooth_applications/bluetooth_bthome_v2_pir_alarm_build_status.json)
9+
![Flash badge](https://img.shields.io/badge/dynamic/json?url=https://raw.githubusercontent.com/SiliconLabs/application_examples_ci/master/bluetooth_applications/bluetooth_bthome_v2_pir_alarm_common.json&label=Flash&query=flash&color=blue)
10+
![RAM badge](https://img.shields.io/badge/dynamic/json?url=https://raw.githubusercontent.com/SiliconLabs/application_examples_ci/master/bluetooth_applications/bluetooth_bthome_v2_pir_alarm_common.json&label=RAM&query=ram&color=blue)
11+
## Overview ##
12+
13+
This project aims to implement a BTHome v2 compatible PIR alarm. The device reads the PIR sensor value and sends the motion information to the BTHome Server, which notifies the user if motion is detected.
14+
15+
The Home Assistant OS is installed and running on a Raspberry Pi 4 device, which scans for BTHome v2 devices. The Home Assistant application of your smartphone can communicate with the Raspberry Pi 4 (RPi 4). RPi4 receives advertisement packages from the BTHome v2 PIR alarm device and detects the movement.
16+
17+
## Gecko SDK Suite version ##
18+
19+
- GSDK v4.4.2
20+
21+
## Software requirements ##
22+
23+
- [Third Party Hardware Drivers v2.0.1](https://github.com/SiliconLabs/third_party_hw_drivers_extension)
24+
25+
- Home Assistant OS v12.3
26+
27+
## Hardware Required ##
28+
29+
- [**BGM220-EK4314A** BGM220 Bluetooth Module Explorer Kit](https://www.silabs.com/development-tools/wireless/bluetooth/bgm220-explorer-kit)
30+
31+
- [MikroE - PIR Click](https://www.mikroe.com/pir-click)
32+
33+
- Raspberry Pi 4 runs Home Assistant OS
34+
35+
**NOTE:**
36+
Tested boards for working with this example:
37+
38+
| Board ID | Description |
39+
| -------- | ------ |
40+
| BRD4314A | [BGM220 Bluetooth Module Explorer Kit - BGM220-EK4314A](https://www.silabs.com/development-tools/wireless/bluetooth/bgm220-explorer-kit?tab=overview) |
41+
| BRD2703A | [EFR32xG24 Explorer Kit - xG24-EK2703A ](https://www.silabs.com/development-tools/wireless/efr32xg24-explorer-kit?tab=overview) |
42+
| BRD4108A | [EFR32BG22 Explorer Kit - BG22-EK4108A](https://www.silabs.com/development-tools/wireless/bluetooth/bg22-explorer-kit?tab=overview) |
43+
44+
## Connections Required ##
45+
46+
The following picture shows the connection for this application:
47+
48+
![overview](image/overview.png)
49+
50+
51+
## Setup ##
52+
53+
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.
54+
55+
### Create a project based on an example project ###
56+
57+
1. From the Launcher Home, add your product name to My Products, click on it, and click on the **EXAMPLE PROJECTS & DEMOS** tab. Find the example project filtering by "bthome" and "pir".
58+
59+
2. Click the **Create** button on **Bluetooth - BTHome v2 - PIR Alarm** example. Example project creation dialog pops up -> click Create and Finish and the project should be generated.
60+
![create_project](image/create_project.png)
61+
62+
1. Build and flash this example to the board.
63+
64+
### Start with a "Bluetooth - SoC Empty" project ###
65+
66+
1. Create a **Bluetooth - SoC Empty** project for your hardware using Simplicity Studio 5.
67+
68+
2. Copy the `src/app.c` file into the project root folder (overwriting the existing file).
69+
3. Install the software components:
70+
71+
3.1 Open the .slcp file in the project
72+
73+
3.2 Select the SOFTWARE COMPONENTS tab
74+
75+
3.3 Install the following components:
76+
77+
- [Services][IO Stream][Driver][IO Stream: USART] → default instance name: vcom
78+
79+
- [Application][Utility][Log]
80+
81+
- [Third-Party Hardware Drivers][Services][BTHome v2]
82+
83+
- [Third-Party Hardware Drivers][Sensors][PL-N823-01 - PIR Click (Mikroe)]
84+
85+
4. Build and flash the project to your device.
86+
87+
**Note:**
88+
89+
- Make sure that the [Third Party Hardware Drivers extension](https://github.com/SiliconLabs/third_party_hw_drivers_extension) is added to the required SDK: [Preferences > Simplicity Studio > SDKs](https://github.com/SiliconLabs/third_party_hw_drivers_extension/blob/master/README.md#how-to-add-to-simplicity-studio-ide).
90+
91+
- SDK Extension must be enabled for the project to install **BTHOME v2** component.
92+
93+
- Do not forget to flash a bootloader to your board, see [Bootloader](https://github.com/SiliconLabs/bluetooth_applications/blob/master/README.md#bootloader) for more information.
94+
95+
## How It Works ##
96+
97+
### Application Initialization ###
98+
99+
![application_initialization](image/application_init.png)
100+
101+
### Motion detection ###
102+
103+
![motion_detection](image/motion_detection.png)
104+
105+
## Testing ##
106+
107+
To test this application and monitor the switch changes, you need the following materials:
108+
109+
- Raspberry Pi 4 runs Home Assistant OS
110+
111+
- Home Assistant application on your smartphone
112+
113+
- [BGM220 Bluetooth Module Explorer Kit](https://www.silabs.com/development-tools/wireless/bluetooth/bgm220-explorer-kit) runs the **Bluetooth - BTHome v2 - PIR Alarm** example
114+
115+
To test this example, you should follow the below steps:
116+
117+
1. Power on Raspberry Pi 4 and BTHome PIR alarm device. After that, the microcontroller reads the output of the sensor in millivolts (mV) periodically. If the value is lower than the configured threshold, then the microcontroller sends the updated advertisement packet. The advertisement packet contains information about the movement.
118+
119+
You can launch Console, which is integrated into Simplicity Studio or you can use a third-party terminal tool like Tera Term to receive the data. Data is coming from the UART COM port. A screenshot of the console output is shown in the figure below.
120+
121+
![console_log](image/console_log.png)
122+
123+
2. Open the Home Assistant application on your smartphone, select [Settings][Devices and Services][Add Integration]
124+
![add_device](image/add_device.png)
125+
126+
3. **Add Integration** with the name "BTHome". You can see the list of devices, which are advertising in BTHome v2 format. Choose your device with the correct name, for example **PIRAlarm 571E**, and submit the bindkey. Bindkey is defined in the firmware of the BTHome PIR device.
127+
128+
- The name of the device is `PIRAlarm`
129+
130+
- The bindkey is `11112222333344445555666677778888`
131+
132+
**Note:** To be able to find your switch device with the Home Assistant application, you need to use the same network on both Raspberry Pi 4 and your smartphone.
133+
![configure_device](image/configure_device.png)
134+
135+
4. After adding your switch device successfully with the bindkey, select a suitable area where your device is located.
136+
![device_information](image/device_information.png)
137+
138+
Now it is visible that the sensor device has already been added to the Home Assistant system. If you move in front of the sensor, the motion change is visible in the **Sensors** section.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Silicon Labs Project Configuration Tools: slcp, v0, Component selection file.
2+
project_name: bluetooth_bthome_v2_pir_alarm
3+
label: Bluetooth - BTHome v2 - PIR Alarm
4+
description: |
5+
This project aims to implement a BTHome v2 compatible PIR alarm, the device is reading the PIR sensor value and sends motion detected signal once the measured value is below of the configured threshold.
6+
7+
category: Bluetooth Examples
8+
9+
filter:
10+
- name: Device Type
11+
value: [SoC]
12+
- name: Project Difficulty
13+
value: [Advanced]
14+
- name: Wireless Technology
15+
value: [Bluetooth]
16+
17+
package: Bluetooth
18+
19+
quality: experimental
20+
21+
readme:
22+
- path: ../README.md
23+
24+
source:
25+
- path: ../src/main.c
26+
- path: ../src/app.c
27+
28+
include:
29+
- path: ../inc/
30+
file_list:
31+
- path: ../inc/app.h
32+
33+
component:
34+
- id: bluetooth_stack
35+
- id: gatt_configuration
36+
- id: gatt_service_device_information
37+
- id: bluetooth_feature_legacy_advertiser
38+
- id: bluetooth_feature_connection
39+
- id: bluetooth_feature_gatt
40+
- id: bluetooth_feature_gatt_server
41+
- id: bluetooth_feature_system
42+
- id: bluetooth_feature_sm
43+
- id: rail_util_pti
44+
- id: mpu
45+
- id: bt_post_build
46+
- id: sl_system
47+
- id: device_init
48+
- id: app_assert
49+
- id: app_log
50+
- id: component_catalog
51+
- id: sleeptimer
52+
- id: iostream_usart
53+
instance: [vcom]
54+
- id: services_bthome_v2
55+
from: third_party_hw_drivers
56+
- id: mikroe_pir_pl_n823_01
57+
from: third_party_hw_drivers
58+
- id: i2cspm
59+
instance: [mikroe]
60+
61+
config_file:
62+
- override:
63+
component: gatt_configuration
64+
file_id: gatt_configuration_file_id
65+
path: "../config/btconf/gatt_configuration.btconf"
66+
directory: "btconf"
67+
68+
other_file:
69+
- path: ../image/add_device.png
70+
directory: "image"
71+
- path: ../image/application_init.png
72+
directory: "image"
73+
- path: ../image/create_project.png
74+
directory: "image"
75+
- path: ../image/motion_detection.png
76+
directory: "image"
77+
- path: ../image/overview.png
78+
directory: "image"
79+
- path: ../image/console_log.png
80+
directory: "image"
81+
- path: ../image/configure_device.png
82+
directory: "image"
83+
- path: ../image/device_information.png
84+
directory: "image"
85+
86+
define:
87+
- name: DEBUG_EFM
88+
89+
configuration:
90+
- name: SL_STACK_SIZE
91+
value: '2752'
92+
- name: SL_HEAP_SIZE
93+
value: '9200'
94+
- condition: [psa_crypto]
95+
name: SL_PSA_KEY_USER_SLOT_COUNT
96+
value: '0'
97+
98+
tag:
99+
- hardware:rf:band:2400
100+
101+
sdk_extension:
102+
- id: third_party_hw_drivers
103+
version: 2.0.1
104+
105+
ui_hints:
106+
highlight:
107+
- path: config/btconf/gatt_configuration.btconf
108+
- path: README.md
109+
focus: true
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project>
3+
<gatt generic_attribute_service="true" header="gatt_db.h" name="Custom BLE GATT" out="gatt_db.c" prefix="gattdb_">
4+
<service advertise="false" name="Generic Access" requirement="mandatory" sourceId="org.bluetooth.service.generic_access" type="primary" uuid="1800">
5+
<informativeText>Abstract: The generic_access service contains generic information about the device. All available Characteristics are readonly. </informativeText>
6+
<characteristic id="device_name" name="Device Name" sourceId="org.bluetooth.characteristic.gap.device_name" uuid="2A00">
7+
<informativeText/>
8+
<value length="13" type="utf-8" variable_length="false">Empty Example</value>
9+
<properties read="true" read_requirement="optional" write="true" write_requirement="optional"/>
10+
</characteristic>
11+
<characteristic name="Appearance" sourceId="org.bluetooth.characteristic.gap.appearance" uuid="2A01">
12+
<informativeText>Abstract: The external appearance of this device. The values are composed of a category (10-bits) and sub-categories (6-bits). </informativeText>
13+
<value length="2" type="hex" variable_length="false">0000</value>
14+
<properties const="true" const_requirement="optional" read="true" read_requirement="optional"/>
15+
</characteristic>
16+
</service>
17+
<service advertise="false" id="device_information" name="Device Information" requirement="mandatory" sourceId="org.bluetooth.service.device_information" type="primary" uuid="180A">
18+
<informativeText>Abstract: The Device Information Service exposes manufacturer and/or vendor information about a device. Summary: This service exposes manufacturer information about a device. The Device Information Service is instantiated as a Primary Service. Only one instance of the Device Information Service is exposed on a device.</informativeText>
19+
<characteristic const="true" id="manufacturer_name_string" name="Manufacturer Name String" sourceId="org.bluetooth.characteristic.manufacturer_name_string" uuid="2A29">
20+
<informativeText>Abstract: The value of this characteristic is a UTF-8 string representing the name of the manufacturer of the device.</informativeText>
21+
<value length="12" type="utf-8" variable_length="false">Silicon Labs</value>
22+
<properties const="true" read="true">
23+
<read authenticated="false" bonded="false" encrypted="false"/>
24+
</properties>
25+
</characteristic>
26+
<characteristic id="model_number_string" name="Model Number String" sourceId="org.bluetooth.characteristic.model_number_string" uuid="2A24">
27+
<informativeText>Abstract: The value of this characteristic is a UTF-8 string representing the model number assigned by the device vendor.</informativeText>
28+
<value length="8" type="utf-8" variable_length="false">00000000</value>
29+
<properties read="true" read_requirement="mandatory"/>
30+
</characteristic>
31+
<characteristic id="hardware_revision_string" name="Hardware Revision String" sourceId="org.bluetooth.characteristic.hardware_revision_string" uuid="2A27">
32+
<informativeText>Summary: The value of this characteristic is a UTF-8 string representing the hardware revision for the hardware within the device.</informativeText>
33+
<value length="3" type="utf-8" variable_length="false">000</value>
34+
<properties read="true" read_requirement="mandatory"/>
35+
</characteristic>
36+
<characteristic id="firmware_revision_string" name="Firmware Revision String" sourceId="org.bluetooth.characteristic.firmware_revision_string" uuid="2A26">
37+
<informativeText>Summary: The value of this characteristic is a UTF-8 string representing the firmware revision for the firmware within the device.</informativeText>
38+
<value length="5" type="utf-8" variable_length="false">0.0.0</value>
39+
<properties read="true" read_requirement="mandatory"/>
40+
</characteristic>
41+
<characteristic const="false" id="system_id" name="System ID" sourceId="org.bluetooth.characteristic.system_id" uuid="2A23">
42+
<informativeText>Abstract: The SYSTEM ID characteristic consists of a structure with two fields. The first field are the LSOs and the second field contains the MSOs. This is a 64-bit structure which consists of a 40-bit manufacturer-defined identifier concatenated with a 24 bit unique Organizationally Unique Identifier (OUI). The OUI is issued by the IEEE Registration Authority (http://standards.ieee.org/regauth/index.html) and is required to be used in accordance with IEEE Standard 802-2001.6 while the least significant 40 bits are manufacturer defined. If System ID generated based on a Bluetooth Device Address, it is required to be done as follows. System ID and the Bluetooth Device Address have a very similar structure: a Bluetooth Device Address is 48 bits in length and consists of a 24 bit Company Assigned Identifier (manufacturer defined identifier) concatenated with a 24 bit Company Identifier (OUI). In order to encapsulate a Bluetooth Device Address as System ID, the Company Identifier is concatenated with 0xFFFE followed by the Company Assigned Identifier of the Bluetooth Address. For more guidelines related to EUI-64, refer to http://standards.ieee.org/develop/regauth/tut/eui64.pdf. Examples: If the system ID is based of a Bluetooth Device Address with a Company Identifier (OUI) is 0x123456 and the Company Assigned Identifier is 0x9ABCDE, then the System Identifier is required to be 0x123456FFFE9ABCDE.</informativeText>
43+
<value length="8" type="hex" variable_length="false"/>
44+
<properties read="true" read_requirement="mandatory"/>
45+
</characteristic>
46+
</service>
47+
</gatt>
48+
</project>
219 KB
Loading
21.8 KB
Loading
48 KB
Loading
20.6 KB
Loading
57.8 KB
Loading
123 KB
Loading

0 commit comments

Comments
 (0)