Implementing the Weather Station with Alerts project
The STM32 instances come with support for Platform IO Core (CLI). We will be using it for working on our projects. To know more about Platform IO Core (CLI) and the different commands go to the Platform IO documentation.
First, we need to initialise a new project using Platform IO. Let's create a new folder called Weather-Notif
which will hold all our code related to the project and then open the newly created folder in the terminal. Use the following commands:
Now we will initialise a new project using Platform IO. Type the following command in the terminal:
The pio project init
command is used to initialise the project. Then we need to specify the board which we want to use with the --board
flag.
Once the project init command has run successfully, we will see some new folders inside the Smart-Home
folder. We will store the files related to the project in the src
folder.
After running the project init
command, if you can't see the new files, you may have to reload the project files by clicking on PROJECT in the File Explorer pane.
Create a new file called main.cpp
inside the src
folder. This file will hold the code for the Smart Home Control program. Click on the main.cpp file to open it up in our code editor. Now, paste the following code inside the main.cpp file.
In the above code, replace "yourusername
" with your Adafruit IO username and "youradafruitiokey
" with your Adafruit IO key which is present under My Key
in Adafruit IO.
Before we can compile our code, we need to install a few libraries. First, let's search for the Adafruit MQTT library. Go to your terminal and type:
Platform IO will now search for the relevant libraries and provide us with the results. Here we can see that we got the library we were looking for. We can see the Library ID at the top, in this case, it is 1092
. We will use this ID to install the library.
Type the following command in the terminal to install the Adafruit MQTT library:
This will install the Adafruit MQTT Library along with all of its dependencies. Now we need to install the Ethernet library. The ID for the Ethernet library is 872
, which we will use to install the library. Follow the same steps as before to install it via Platform IO.
Finally, we need to install the Sodaq_SHT2x library. The ID for this library is 803
, which we will use to install the library. Follow the same steps as before to install.
Now we are ready to compile our code. Save the main.cpp file. We will again use Platform IO to compile our code. Go to your terminal and type the following command.
The first time this command is run, Platform IO will download and install the relevant framework and toolchains required for the STM32. This process will take a few seconds.
Now Platform IO will compile our code and output a firmware.bin file. We need to copy this firmware file from the .pio/build/nucleo_f411re
to /workspace
. Usually you would need to use the cp
command, but we have created a custom command called load-firmware
for ease of use. Just write the following command and the firmware.bin file will be copied to the workspace folder.
Once we have copied the firmware.bin file, all we need to do is to reset the STM32 by pressing the red button above the STM32. After the reset, the STM32 will load the new firmware.
Now you have alerts set up for your weather station and you will receive notifications whenever the temperature crosses the threshold.
You can also create a dashboard for receiving the real-time Temperature and Humidity Data on your phone by using the MQTT Dashboard app. Refer to our guide for setting up the app.
Configuring the MQTT Dashboard appYou need to create 2 tiles of the Progress
type (like the Lux Value tile in the above guide) and connect them to the respective feeds.
You have completed the Weather Station with Alerts project. Now you can configure the project in any way you want and try to make something new.
Last updated