Part 1. Abstract
The main idea is to build a system to monitor temperature and humidity in my house and have access from a phone, tablet, laptop, etc.. Additionally I want to have historical data and show temperature, humidity charts for the last 24 hours, month, year, for instance.
To build the monitoring system I'm going to use Arduino Pro Mini as the main device which will read data from DHT22 temperature/humidity sensor and send them by Digi ZigBee Series 1. As a receiving device, I will use Raspberry PI 3 with connected Digi ZigBee Series 1 but configured as the receiver.
Temperature, humidity, and timestamp will be stored in MariaDB.
All code is available on GitHub, feel free to fork and use the code.
Let's get started.
Part 2. Building Sending Device
In this section I'm going to go through the steps I did to create a device which will get temperature, humidity data from the DHT22 sensor and send to a receiver, see Part 3. Building Receiving Device section.
The final device looks as on the images below:
Part 2.1. Configuring XBee
Each XBee device must be configured to communicate with another XBee device, also please note that here I use XBee Series 1, see some details in the following posts XBee Series 1 vs. Series 2, XBee Buying Guide.
For the configuration, I used XCTU - which allows you to configure XBee modules as well as see received data sent by another XBee modules if you would like to debug how XBee module configuration works. To connect XBee module via USB I used Waveshare XBee USB Adapter.
You could follow the following steps to set up XBee modules:
- In XCTU click on Add device to add USB connected XBee module
2. Select the connected device, as on the screenshot below.
Note: if you don't see your XBee module, make sure you have installed a driver. If you use Windows you could see the connected device in the Device Manager. I had such an issue and after installing that particular driver, the issue has been resolved.
After that, you will see the connected XBee module in the list of modules
3. Select the module and update: ID, DL, and MY values.
Here is what I used for my configuration:
|Device||ID PAN ID||DL Destination Address Low||MY 16-bit Source Address|
ID PAN ID must be the same for all devices, DL for Sender [x]'s is 3500 as the Receiver's MY 16-bit Source Address value. Senders MY 16-bit Source Address just unique IDs.
After these steps, XBee modules are ready for the next steps.
Part 2.2. Configuring Arduino
When everything is connected code could be uploaded to the Arduino Pro Mini. As far as Arduino Pro Mini doesn't have a USB port you need to use FTDI device, I used SparkFun FTDI Basic Breakout - 3.3V.
Probably when you upload the code into your Arduino you will need to disconnect XBee module, otherwise, you will get an error in the Arduino IDE.
Part 3. Building Receiving Device
Part 3.1. Configuring Raspberry PI
Now you are ready to upload the code into your Raspberry PI. The easiest way is to use SSH. In this post, I'm not going to describe how to install Raspbian and configure SSH, but you could easily google it.
Software for the Raspberry PI(receiver) consist from two parts:
- A Python script which reads data from the USB connected XBee module and calls Web Api to send received data;
- A Web part consists from an Api and UI:
- the Api:
- receivs requests from the Python script and save into MariaDB;
- retrieve data for the UI Spa application
- the UI is the Angular application:
- shows connected devices and theirs temperature, humidity, and head index;
- shows histrorical data for each particular device using charts
- the Api:
To build and deploy the code to the Raspberry PI use scripts from the
build.sh to build API and UI,
deploy.sh to deploy(don't forget to update the IP address in the
You could call
sh ./build.sh && sh ./deploy.sh from the
scripts directory to build and deploy.
Prerequisites to run the code on the Raspberry PI:
- Python 3 must be installed;
- .NET Core must be install, see Link #4 in the Links section.
After deployment the code connects to your Raspberry PI, navigate to the
monitoring directory and call
nohup sh ./run.sh & to leave
run.sh script running when you close SSH connection.
Part 4. Result
The final result is Web Application which looks like
Feel free to ask me any questions.