This wireless thermostat application uses Bluetooth Low Energy 5.2 and Wi-Fi technology to collect real-time temperature data from two BLE sensor nodes. It allows users to easily set and control the temperature, creating a pleasant environment by adjusting the heating or cooling system to their desired level through an intuitive BLE central node acting as a wireless thermostat that connects to the end nodes over BLE and acts as the temperature control panel. The collected temperature is also streamed through the Wi-Fi Gateway node to the AWS IoT cloud for monitoring.
This solution includes four projects to demonstrate a Wireless Thermostat.
This project employs the RNBD451 BLE module to create multi-link BLE connections with two peripheral nodes. Once connected, the central node functions as a GATT client, periodically requesting real-time temperature data from the peripheral GATT servers(peripherals) and displaying it on a 4.3-inch maXTouch graphics display. Users can set and send temperature threshold limits to the BLE peripheral nodes using the GUI. Furthermore, the central application transmits the gathered temperature data to the WFI32 IoT gateway via UART for real-time monitoring on the AWS cloud.
This application operates as a GATT server using the RNBD451 BLE module. It periodically collects temperature data from the IO/1 Xplained Pro board and updates the temperature characteristic value whenever the temperature changes. The node waits for the connection request from the central node. Once connected, it sends temperature data in response to read requests from the GATT client(central node) and can receive and implement threshold limit values from the central node. An onboard LED turns on whenever the temperature exceeds the designated limit.
This application uses ADC to read the analog output from the onboard MCP9700A temperature Sensor. Once connected to central node over BLE, it periodically sends the temperature characteristic value to the central node upon request. It can also receive and set threshold limit values from the central node, with an onboard LED illuminating when the temperature surpasses the defined cutoff
This application acts as bridge between the central node and the AWS cloud. It periodically receives the BLE end nodes temperature data from the central over UART and publishes the same over MQTT to the AWS IoT cloud for constant monitoring.
The projects have been verified to work with the following versions of software tools:
For Central PIC32CZ_CA90 GATT Client, Refer Project Manifest present in this path
For peripheral PIC32CM_LS60 GATT Server , Refer to the Secure Project Manifest and Non-Secure Project Manifest present in this secure and non-secure project paths.
For peripheral WBZ451 GATT Server, Refer Project Manifest present in this path
For Wi-Fi Gateway PIC32MZ_W1 , Refer Project Manifest present in this path
Any Serial Terminal application like Tera Term terminal.
Python 3.5 or higher.
Because Microchip regularly updates tools, occasionally issue(s) could be discovered while using the newer versions of the tools. If the project doesn’t seem to work and version incompatibility is suspected, it is recommended to double-check and use the same versions that the project was tested with. To download original version of MPLAB® Harmony v3 packages, refer to document How to Use the MPLAB® Harmony v3 Project Manifest Feature
Connect the 565 LCD Adapter Graphics Card to the “Graphics connector” of the PIC32CZ CA90 Curiosity Ultra Development Board.
Connect the 4.3” WQVGA maXTouch Display module to the 565 LCD Adapter Graphics Card of the PIC32CZ CA90 Curiosity Ultra Development Board.
Make sure the jumper J2 of the RNBD451 Add On Board has the cap mounted between J(2-1) and J(2-2) to be powered by the mikroBUS header.
Connect the jumper wire from PC08 on EXT1 for SERCOM UART TX to communicate with the Wi-Fi Gateway.
Connect the PIC32CZ CA90 Curiosity Ultra Development Board to the Host PC as a USB Device through a Type-A male to micro-B USB cable connected to Micro-B USB (Debug USB) port
Power the PIC32CZ CA90 Curiosity Ultra Development Board through the Barrel connector using the wall-mount 9V power supply provided in the kit, or Power supply with any Voltage (6.5-14V DC) and Current (> 750 mA) range.
Connect the RNBD Add-on board to the mikroBUS header on the PIC32CM LS60 Curiosity Pro Evaluation Kit.
Make sure the jumper J2 of the RNBD451 Add On Board has the cap mounted between J(2-1) and J(2-2) to be powered by the mikroBUS header.
Connect the I/O1 Xplained Pro Extension Kit to the EXT2 in the PIC32CM LS60 Curiosity Pro Evaluation Kit.
Connect the PIC32CM LS60 Curiosity Pro Evaluation Kit to the Host PC as a USB Device through a Type-A male to micro-B USB cable connected to Micro-B USB (Debug USB) port
Demo Hardware Setup:
Pre-requisites:
The WFI32E01PC module on the WFI32 IoT development board has an in-built Trust and Go (TNG) device. It is essential to upload the device certificate of the TNG device to the AWS IoT cloud for authenticated client TLS connection with the cloud platform.
Please follow the procedure mentioned in Generate Device certificate for extracting the certificate from the device.
Upon generation, the device certificate should be uploaded to the cloud. Refer to the Uploading Device Certificate to AWS IoT Cloud Service for more details about the procedure.
The configuration.h file of wfi32_iot.X project should be modified for connecting successfully to the AWS cloud.
The device can be programmed in two ways
Refer Method 1: Programming using the prebuilt hex file.
Refer Method 2: Programming by building the application project.
Open MPLAB® X IDE.
Close all existing projects in IDE, if any project is opened.
Go to File -> Import -> Hex/ELF File.
In the “Import Image File” window, Step 1 - Create Prebuilt Project, Click the “Browse” button to select the prebuilt hex file.
Select Device as “PIC32CZ8110CA90208”
Ensure the proper tool is selected under “Hardware Tool”.
Click on the “Next” button.
In the “Import Image File” window, Step 2 - Select Project Name and Folder, select appropriate project name and folder.
Click on the “Finish” button.
In MPLAB® X IDE, click on “Make and Program Device” Button. The device gets programmed.
Follow the steps in Running the Demo under PIC32CZ CA90 Central section below.
Note: Program the prebuilt hex files for other projects similarly, by choosing the respective devices and tool.
Open the project ls60_cprogroup.X in MPLAB® X IDE from here and set it as main project.
Open both Secure and Nonsecure projects inside the project group and set the Nonsecure project as the main project.
Ensure “PIC32CM LS60 Curiosity Pro” is selected as hardware tool to program/debug the application.
Build the code and program the device by clicking on the “Make and Program Device” button in MPLAB® X IDE tool bar.
Follow the steps in Running the Demo under PIC32CM LS60 Peripheral Node section below.
Open the project wbz451_curiosity.X in MPLAB® X IDE from here and set it as main project.
Ensure “WBZ451 Curiosity board” is selected as hardware tool to program/debug the application
Build the code and program the device by clicking on the “Make and Program Device” button in MPLAB® X IDE tool bar
Follow the steps in Running the Demo under WBZ451 Peripheral Node section below
Open the project pic32cz_ca90_cult.X in MPLAB® X IDE from here and set it as main project.
Ensure “PIC32CZ CA90 Curiosity Ultra” is selected as hardware tool to program/debug the application
Build the code and program the device by clicking on the “Make and Program Device” button in MPLAB® X IDE tool bar
Follow the steps in Running the Demo under PIC32CZ CA90 Central Node section below.
Open the project wfi32_iot.X in MPLAB® X IDE from here and set it as main project.
Ensure “WFI32 IoT board” is selected as hardware tool to program/debug the application.
Build the code and program the device by clicking on the “Make and Program Device” button in MPLAB® X IDE tool bar.
Follow the steps in Running the Demo under WFI32 IoT Gateway section below.
Note:Before proceeding to the next step, make sure the console messages shown on the peripheral Node 1 and Node 2 are as Node 1 Ready Status and Node 2 Ready Status
The central node starts to scan for the nearby BLE peripheral nodes. “Scanning” appears on the connect screen. Please wait for a few seconds for the BLE scanning process to complete.
Once the scanning completes, the central initiates connection with BLE Node 1.
Similarly , the central node initiates another connection to BLE node 2.
Upon successfully connecting with the second node, a tick mark appears on the GUI ,as below, and the next screen appears that shows “Preparing” appears.
LED0 and LED1 are turned on with a successful multilink connection on the PIC32CZ CA90 Curiosity Ultra Development Board as below
Note:The corresponding temperature can be viewed on the tera term console of nodes 1 and 2
Note:Please wait for a couple of seconds if the next screen doesn’t appear immediately.
To set threshold for node 1, adjust the temperature and press “enter”.
Similarly, to set threshold for node 2, adjust the temperature for node 2 and press “enter”.
Note: Please note that the limits for each node should be set individually. The nodes do not get updated simultaneously. To set threshold for both the nodes, change the limit in one node, press enter and then do the same for the other node.
Power up the board.
Open the Terminal application (Ex.:Tera term) on the computer
Change the baud rate to 115200.
Press “RESET” button of the PIC32CM LS60 Curiosity Pro Evaluation Kit to run the application from the beginning.
The below console output will be displayed. The last message on Tera Term will be “Connecting” where the node waits for a BLE connection.
Power up the board.
Open the Terminal application (Ex.:Tera term) on the computer
Change the baud rate to 115200.
Press RESET button to start over the application.
The device starts BLE advertisement and displays the current temperature in periodic intervals
The BLE node also receives the temperature threshold values set on the central node
The RGB LED(D6) of the WBZ451 Curiosity Development Board glows in Red when the current temperature exceeds the threshold set. In the above image the current temperature (31°C) is greater than the received threshold (22°C). The LED turns on in this scenario.
Power up the board
Open the Terminal application (Ex.:Tera term) on the computer
Change the baud rate to 115200 from Setup->Serial menu.
Press “RESET” button to run the application from the beginning.
The console displays TCP/IP stack initialization messages and the Gateway IP address gets assigned and displayed on successful connection with Wi-Fi AP. Wait for some time for the MQTT connection establishment as it may take some time.
Once the MQTT connection is established the device is ready to update the temperature received from the central node in AWS cloud periodically.
The device starts to publish the messages when the central node updates the temperature