Build A Universal Sensor Hub and Monitor Anything You Want with a Raspberry Pi

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 to set up a Raspberry Pi (select Raspbian for the OS):

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 (1). Open a terminal window on your Pi and execute these commands:

Now install the tools and Python libraries required to allow your Pi to talk to sensors:

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:

You should see the i2c address of the module come up as “77”:

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 raspberry in the upper left corner, navigate to: Preferences -> Raspberry Pi configuration -> Interfaces. Enable i2c:

 

Step 4: Collect data from the sensor

The following simple Python script (2) 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):

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:

 

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).

The first time you log into JEDI One software, you will need to use admin for both User ID and password, accept the license agree-ment 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:

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:

Machinechat JEDI One Community

Machinechat

  1. More on updating and upgrading Raspbian:

    https://www.raspberrypi.org/documentation/raspbian/updating.md

  2. More info on the original example can be found at:

    https://learn.adafruit.com/adafruit-bme280-humidity-barometric-pressure-temperature-sensor-breakout/python-circuitpython-test

CONTACT

  • Twitter - White Circle
  • LinkedIn - White Circle

© 2019  Machinechat. All rights reserved.