RMIT Programming Internet of Things Assignment 1
by Jing Li and Cheng Qian
The project once installed and configured, allows the Raspberry Pi with Sense Hat to automatically monitor ambient temperature and humidity, and compares them with preset range data and send out-of-range reading notification to user's Pushbullet device(s). Besides, it will also have the Raspberry Pi run bluetooth scanner and send out temperature/humidity readings to user's device(s), once it finds a paired device nearby.
This project also allows user to generate sensor data report to see if there is any out-of-range reading for each day. Last but not the least, user can also use this project to generate two pre-defined data visualization png files to learn more about the collected data.
- Flash the Raspbian image provided by RMIT School of Science to the Raspberry Pi with Sense Hat.
- SSH into the Raspbian and run
mkdir Workspaces
- Run
cd Workspaces
and thengit clone
this repository.
Run the following to install all required dependencies:
sudo apt-get install bluez bluez-firmware bluez-tools blueman
sudo apt-get install libatlas-base-dev
sudo apt-get install sqlite3
pip3 install pybluez
pip3 install requests
pip3 install matplotlib
pip3 install seaborn
pip3 install pandas
-
Go to https://www.pushbullet.com/ and create an account. Then go to My Account -> Settings and Create Access Token under Access Tokens.
-
Copy the newly created token from above step.
-
SSH into Raspbian and
cd Workspaces/GreenhouseMonitor
-
Run
vi token.json
(one can usenano
to create file instead ofvi
, same for all similar commands in this document) and add the following to the file and make sure to replace[COPIED ACCESS TOKEN]
with your access token:{ "pushbullet": "[COPIED ACCESS TOKEN]" }
-
Download Pushbullet App and/or web browser extensions and log in with the same account.
- SSH into Raspbian and
cd Workspaces/GreenhouseMonitor
- Run
sqlite3 greenhouse_monitor.db
- Type
.databases
to verify and.exit
to quit SQLite CLI.
- SSH into Raspbian and
cd ~
- Run
mkdir CronJobs
-
vi CronJobs/RunGreenhouseMonitor.sh
and add the following to the file and save:#!/bin/sh cd /home/pi/Workspaces/GreenhouseMonitor; python3 monitor_and_notify.py
-
Run
chmod +x /home/pi/CronJobs/RunGreenhouseMonitor.sh
-
sudo vi /etc/cron.d/GreenhouseMonitorJob
and add the following to the file and save:* * * * * pi /home/pi/CronJobs/RunGreenhouseMonitor.sh
-
vi CronJobs/RunGreenhouseBluetooth.sh
and add the following to the file and save:#!/bin/sh cd /home/pi/Workspaces/GreenhouseMonitor; python3 greenhouse_bluetooth.py
-
Run
chmod +x /home/pi/CronJobs/RunGreenhouseBluetooth.sh
-
sudo vi /etc/cron.d/GreenhouseMonitorJob
and add the following to the file and save:* * * * * pi /home/pi/CronJobs/RunGreenhouseBluetooth.sh * * * * * pi sleep 30; /home/pi/CronJobs/RunGreenhouseBluetooth.sh
The script itself takes about 15 seconds to run, and the two cron jobs above run the script every 30 seconds and therefore create a 15-second interval between two runs.
Finally, run sudo reboot
to restart Raspbian for the changes to take effect.
Once configured, the script should automatically run every minute and it will collect the sensor data (temperature and humidity) and save them to the local database. For every reading, it will also compare with the config.json
file and notify user if the reading is out of range. The notification is sent maximum once each day, local time.
To manually run the script, run:
cd /home/pi/Workspaces/GreenhouseMonitor; python3 monitor_and_notify.py
Once configured, the script should automatically run every 30 seconds and it will look for paired devices. If a paired device is nearby, it will collect the sensor data and send notification with the data to the user. The notification is sent maximum once every minute.
To manually run the script, run:
cd /home/pi/Workspaces/GreenhouseMonitor; python3 greenhouse_bluetooth.py
To see if readings are out-of-range for each day, user can manually run:
cd /home/pi/Workspaces/GreenhouseMonitor; python3 create_report.py
User can also modify the range in config.json
before creating the report.
User can manually run:
cd /home/pi/Workspaces/GreenhouseMonitor; python3 analytics.py
to generate two predefined graphs — line_chart.png
and joint_plot.png
.
The former shows the trends of temperature and humid, and the latter depicts the relationship between temperature and humidity along with their distributions.