The aim of this project is to build a live dashboard for room temperature and humidity data. If you ever wanted to monitor the room micro-climate then this project is for you. The dashboard below shows temperature and humidity being plotted in real time on dashboard based on a Node.Js app.
An Si7021 sensor was used. This is a MEMS humidity and temperature sensor capable of 0.1 C deg resolution. The other two project components are a SwishPi pHAT and a Raspberry Pi Zero.
The SwishPi is a pico HAT (hardware attached on top) for rapid prototyping described in more detail here.
HardwareThe hardware portion of the project consists of mounting the SwishPi HAT and plugging in the Si7021 sensor on one of the I2C headers.
The software makes use of the Node Js Express framework and the Sockets.io library which comes with a nifty Websocket implementation for Node.
In addition Plot.ly lib is used for graphing live data. As the sensor is queried in real time the data is sent via Websocket to the client browser.
This example makes use of the sequential access of the I2C bus by using the AquilaHTU21D library. To get out of the callback hell, Javascript has introduced the Promises API. One improvement to the code would be use this new API to make the code asynchronous.
DemoRunning the app
For instant gratification:
- Clone the repo.
- Change the IP address of the server to the IP address of your Raspberry Pi.
Start the app by issuing:
sudo npm start
Open a web-browser and navigate to http://RPI_IP:3000
.
That's all people. Enjoy. Code attached as always.
Comments