You are curious. You want to know how hot it is in the attic, how cold it gets in the basement, if your plants need to be watered, how windy it is outside, or the temperature in your wine rack.
In this step-by-step article, you will see how easy it is to build a universal sensor hub using inexpensive components to monitor anything you want, starting with temperature, humidity and atmospheric pressure - you can add other sensors to it in future. What you will need:
- Raspberry Pi (version 2 and above) - $35 (Pi 3, 4, and Zero W have WiFi on board)
- BME280 environmental sensor module - $12
- Machinechat JEDI One software (runs on Raspberry Pi) - $39
In just 6 easy steps, we will have you capturing data from the BME280 module, displaying the real-time and historical data using beautiful dashboards, and creating rules and notifications so you will be alerted when key events take place. Let’s get started! (If your Pi is ready to go, skip to Step 2)
STEP 1: Set up your Raspberry Pi
Here are links to two ways of setting up a Raspberry Pi (select Raspberry Pi OS with desktop for the OS):
Setting up your Raspberry Pi with a USB keyboard, mouse and HDMI capable monitor or TV
If you are new to Raspberry Pi, check out this tutorial: Using your Raspberry Pi
During your setup, you will want to make sure i2c is enabled for this project. Also enabling SSH and VNC is helpful in working with your Pi from a PC, then you can ditch the keyboard, mouse, and monitor for good! This is all done on the configuration page (details in Step 3). Here’s a link to a free VNC viewer for your PC: VNC Viewer
STEP 2: Install important Raspberry Pi updates and software libraries
If you have not updated the operating system or its libraries recently, it is important that you do it now. Updating and upgrading Raspberry Pi OS. Open a terminal window on your Pi and execute these commands:
$sudo apt update
$sudo apt full-upgrade
Now install the tools and Python libraries required to allow your Pi to talk to sensors:
$sudo apt-get install i2c-tools
$sudo pip3 install adafruit-circuitpython-bme280
STEP 3: Connect the BME280 sensor module
The popular BME280 module is great to start with because its sensors can measure temperature, humidity and barometric pressure, all in one. It connects directly to the Raspberry Pi with just 4 wires (SDA, SCL, 3.3V, and GND) - this forms an i2c connection between the two boards. We recommend starting out with this one because it comes with the connector and attached wires (other BME280 modules from other vendors require a bit of soldering to attach the wires): Waveshare BME280 Module. It includes the connector and attached wires; all you need to do is plug the wires into the Pi as shown here:
Power on and check that the module is connected properly by running this command on the Pi:
$i2cdetect -y 1
You should see the i2c address of the module come up (77 for the Waveshare module):
If you don’t see it, check your wiring and also make sure i2c is enabled in the Raspberry Pi configuration. From the Pi GUI, click on the picture of a raspberry in the upper left corner, navigate to: Preferences -> Raspberry Pi configuration -> Interfaces. Enable i2c (SSH and VNC while you are at it):
Step 4: Collect data from the sensor
The following simple Python script (original source) will collect and print temperature, humidity, and pressure to the terminal window of your Raspberry pi. Of course you can use code written in any language (C, Java, Go, Perl, Python, etc):
import board import time from adafruit_bme280 import basic as adafruit_bme280 # Create library object using our Bus I2C port i2c = board.I2C() bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, 0x77) # Some BME280 sensors are strapped for 0x76 address. Change 0x77 to 0x76 above # If an error occurs saying no device found at 0x77
print("Temperature: %0.1f C" % bme280.temperature)
print("Humidity: %0.1f %%" % bme280.humidity)
print("Pressure: %0.1f hPa" % bme280.pressure)
Cut and paste the code above into a file on the Raspberry Pi using a text editor. For this example the file is saved as “adafruit-bme280.py”. Make the file executable and run it like this:
Now let’s change this script slightly, so that the JEDI One application can read this information and you can create some cool data dashboards. We’ll add a unique name (ID) for this device and we will modify the three print statements so JEDI One application knows to grab this information. Here’s what it looks like now:
#!/usr/bin/python3 # SendBMEtoJEDI.py - JEDI One Custom Plug-in Python script for Raspberry Pi with i2c attached BME280 # Makes values available to JEDI One # Requires installing Adafruit library - sudo pip3 install adafruit-circuitpython-bme280 # # v0.3 DRM 05/04/2022 import board import time from adafruit_bme280 import basic as adafruit_bme280 # Create library object using our Bus I2C port i2c = board.I2C() bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, 0x77) # Some BME280 sensors are strapped for 0x76 address. Change 0x77 to 0x76 above # If an error occurs saying no device found at 0x77 # Device ID, Create a unique device name so Jedi knows the source of the data devID = "BME280Sensor1" #New print statements that have Jedi tags print("metric:id=%s,n=Temperature,vd=%0.1f,u=C" % (devID, bme280.temperature)) print("metric:id=%s,n=Humidity,vd=%0.1f,u=%%" % (devID, bme280.humidity)) print("metric:id=%s,n=Pressure,vd=%0.1f,u=hPa" % (devID, bme280.pressure))
Save the file and make sure the modified Python script runs ok - “adafruit-bme280-JEDI.py” in this example. Your output on the terminal should look like this:
That’s it, you just created your first plug-in that collects data from a sensor and prints it in a format that is ready for the JEDI One application! We will move it into the JEDI One plugins folder soon. No matter what language you use, just make the simple formatting modifications to the print statements.
Step 5: Install Machinechat JEDI One software
JEDI One is really easy to install since it is a small, single binary! There are many ways to get JEDI One on to the Pi. You can download it via the browser on the Pi or use the SCP command on Mac and Linux or WinSCP on Windows. Here’s how to pull the file off of a USB Drive and place it in its own directory:
Now to get it running and move our python script to the plugins directory:
Step 6: Create Data Dashboards, Rules and Notifications
You’re almost there. Now you just need to login to JEDI One and you’ll be able to show your friends all the things you can monitor in minutes. Open a browser on your PC and enter the IP-address of your Raspberry Pi and :9123. In this example: 192.168.1.6:9123. (The Pi’s IP address can be found by running the ifconfig command on the Pi in a terminal window). Here's what you will see:
The first time you log into JEDI One software, you will need to use admin for both User ID and password, accept the license agreement and establish your own unique password. Once this is complete, log back in using the User ID admin and your new password. (Note: you can change your User ID after you have logged in to JEDI One through User Settings).
You will now see a screen like the one below in the video. We’ll have JEDI One start collecting data from the BME280 module by having it run the plug-in we wrote in Python. It’s quite simple; take a look at this video:
Now here is how to create some cool data dashboards to view your data:
Simple, right? Now you try it - add some charts for humidity and barometric pressure. Experiment with the variety of chart types.
Wouldn’t it be nice to if you could receive a text or email when a certain event occurs, for example if the temperature gets below 20C? With JEDI One, setting up alerts and notifications is super easy. All you need are:
- Your email account settings
- A Twilio account for sending SMS (text messages) or
- Your cell phone provider may have an email address which forwards the message to a phone via SMS. Cellular carriers with email to text capabilities
Within JEDI One, click into Settings -> Notifications. This is where you will enter your SMTP email server information, and for texts (SMS) your Twilio account details:
Once that is done, setting up a rule and notification action takes just a moment:
Make sure you fill in the email address the notification should go to and/or the SMS phone number including the + and country code. And here is our first text message notification:
And the email notification:
Congratulations! With your JEDI One-enabled sensor hub, now you can easily add additional sensors (simply repeat steps 3,4 and 6) in minutes. To explore more about what you can do with JEDI One software, check out these resources: