This project aims to implement a thermostat system using Silabs development kits and external sensors integrated with the BLE wireless stack.
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:
- GSDK v4.4.0
- Third Party Hardware Drivers v2.0.0.0
The hardware connection is shown in the image below:
The I2C connection is made from the BGM220 Bluetooth Module Explorer Kit to the Humidity Sensor board and the Micro OLED Breakout by using the Qwiic cable.
To test this application, you can either create a project based on an example project or start with an empty example project.
-
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 with the filter "thermostat".
-
Click Create button on Bluetooth - Thermostat project. Example project creation dialog pops up -> click Create and Finish and source code should be generated.
-
Build and flash this example to your board.
-
Create a Bluetooth - SoC Empty project for your hardware using Simplicity Studio 5.
-
Copy all attached files in
inc
andsrc
folders into the project root folder (overwriting the existing files). -
Import the GATT configuration:
-
Open the .slcp file in the project.
-
Select the CONFIGURATION TOOLS tab and open the Bluetooth GATT Configurator.
-
Find the Import button and import the attached
config/btconf/gatt_configuration.btconf
file. -
Save the GATT configuration (ctrl-s).
-
-
Open the .slcp file. Select the SOFTWARE COMPONENTS tab and install the software components:
- [Services] → [Timers] → [Sleep Timer]
- [Services] → [NVM3] → [NVM3 Core]
- [Services] → [NVM3] → NVM3 Default Instance
- [Services] → [IO Stream] → [IO Stream: USART] → default instance name: vcom
- [Application] → [Utility] → [Log]
- [Application] → [Utility] → [Assert]
- [Third Party] → [Tiny printf]
- [Platform] → [Driver] → [Button] → [Simple Button] → default instance name: btn0
- [Platform] → [Driver] → [LED] → [Simple LED] → default instance name: led0
- [Platform] → [Driver] → [PWM] → [PWM] → default instance name: "mikroe".
- [Third Party Hardware Drivers] → [Display & LED] → [SSD1306 - Micro OLED Breakout (Sparkfun) - I2C]
- [Third Party Hardware Drivers] → [Audio & Voice] → [CMT_8540S_SMT - Buzz 2 Click (Mikroe)]
- [Third Party Hardware Drivers] → [Sensors] → [SHTC3 - Temp&Hum 9 Click (Mikroe)]
- [Third Party Hardware Drivers] → [Service] → [GLIB - OLED Graphics Library]
-
Build and flash the project to your device.
Note:
-
Make sure that the Third Party Hardware Drivers extension is added to the required SDK: Preferences > Simplicity Studio > SDKs.
-
SDK Extension must be enabled for the project to install components.
-
Do not forget to flash a bootloader to your board, see Bootloader for more information.
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 (Thermostat ) which are 8 characteristics:
-
Mode:
-
[Readable] - Get mode value
-
[Writable] - Set mode value - mode (0 - heat, 1 - cool)
-
-
Setpoint (SV):
-
[Readable] - Get setpoint value
-
[Writable] - Set setpoint value - setpoint (e.g.: 2500 => 25.0 °C, limits: -35 °C ↔ + 120 °C, -3500 ↔ 12000)
-
-
Temperature (PV):
- [Readable] - Get current averaged temperature value (e.g.: 2500 => 25.0 °C)
-
Humidity:
- [Readable] - Get current averaged humidity value (e.g.: 2500 => 25.0 %)
-
Hysteresis (HYS):
-
[Readable] - Get hysteresis value
-
[Writable] - Set hysteresis value - hysteresis (e.g.: 2500 => 25.0 °C, limits: 0 ↔ (HIGH-LOW) thresholds)
-
-
Lower threshold:
-
[Readable] - Get a lower threshold value
-
[Writable] - Set lower threshold value - lower_threshold (-3500 <= VAL < Upper threshold value)
-
-
Upper threshold:
-
[Readable] - Get upper threshold value
-
[Writable] - Set upper threshold value - upper_threshold (-3500 <= VAL < Upper threshold value)
-
-
Threshold alarm status:
-
[Readable] - Get threshold alarm status (0 - disabled, 1 - enabled, 2 - alarm active)
-
[Writable] - Set threshold alarm status - is_alarm_active (0 - disabled or 1 - enabled )
-
-
Initialize the peripherals, the Bluetooth stack
-
Initialize and load the NVM3 configurations
-
Wait for the sensor to be booted and initialize the sensor with the configurations from NVM3:
-
Initialize the OLED display.
-
Start a periodic timer with a period of 1000ms, The timer callback will fire an external event to BLE stack and the event handler will display people counting data from the result of the counting algorithm calculation.
-
After the sl_bt_evt_system_boot_id event arrives, App sets up the security manager and starts advertising.
-
Handle GATT event to help the user configure the Use EFR Connect Mobile Application and get the result from the algorithm calculation over the EFR32 connect mobile app
-
When the button is released, it checks the alarm feature status, and buzzer state in accordance with the flowchart below.
The Silicon Labs EFR Connect application utilizes the Bluetooth adapter on your phone/tablet to scan, connect and interact with BLE devices. To run this example, an iOS or Android smartphone with the EFR Connect app installed is required.
Open the EFR 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 Thermostat
and click the connect button on the right side.
After connected:
The parameters of this example application can be easily configured via BLE characteristics. Values for the characteristics are handled by the application as ASCII strings. Tap on the main service to see the available characteristics. Please refer GATT Configurator to choose the correct characteristic.
Read Push read button to request the value of a characteristic. (See ASCII fields.)
Write For setting a parameter select a characteristic and tap on its write button. Type a new value in the ASCII field and push the Send button.
Characteristics | Read | Write |
---|---|---|
Mode | - Read to get mode value | - Write to set mode value - mode (0 - heat, 1 - cool) |
Setpoint | - Read to get setpoint value | - Write to set setpoint value - setpoint (e.g.: 2500 => 25.0 °C, limits: -35 °C ↔ + 120 °C, -3500 ↔ 12000) |
Temperature(SV) | - Read to get current averaged temperature value (e.g.: 2500 => 25.0 °C) | |
Humidity (PV) | - Read to get current averaged humidity value (e.g.: 2500 => 25.0 %) | |
Hysteresis | - Read to get hysteresis value | - Write to set hysteresis value - hysteresis (e.g.: 2500 => 25.0 °C, limits: 0 ↔ (HIGH-LOW) thresholds) |
Lower threshold | - Read to get lower threshold value | - Write to set lower threshold value - lower_threshold (-3500 <= VAL < Upper threshold value) |
Upper threshold | - Read to get upper threshold value | - Write to set upper threshold value - upper_threshold (-3500 <= VAL < Upper threshold value) |
Threshold alarm status | - Read to get threshold alarm status (0 - disabled, 1 - enabled, 2 - alarm active). | - Write to set threshold alarm status - is_alarm_active (0 - disabled or 1 - enabled) |
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.