I wanted something to monitor my room temperature and humidity, so I wrote this simple web-based weather station for Raspberry Pi and SenseHat.
Very "raw", fixes and PRs welcome!
- Raspberry Pi 3
- SenseHat
- GPIO Ribbon Cable (optional)
If you put your SenseHat on top of your Pi, the temperature readings might be inaccurate due to the heat coming from it - that's what the optional ribbon cable is for:
To use your SenseHat with a ribbon cable, you can remove the GPIO header on the bottom of the hat. It won't go easy the first time, just remember, you are removing the bottom one ;-)
The application was inspired by following resources:
- Sense-hat API documentation
- w3schools - for HTML menus, templates and CSS.
- ChartJS - Awesome charts used to display environment readings.
- Flask - Web server used to display data, inspired by this blog example.
- Python sqlite tutorial
Update your package database and make sure you have all required packages, then clone this git repository. Installation of supervisor is optional, it is used to keep the processes running in background.
sudo apt update
sudo apt install supervisor python3-flask sqlite3 git sense-hat
git clone https://github.com/odlevakp/enviro-pi.git ~/enviro-pi
Supervisor was installed to keep your two processes alive. First one, writer.py
, reads environmental information from sensehat and writes them into a database.
Second process, webserver.py
, starts a web server and displays collected data. The configuration needed to run them using supervisor, is placed in the
supervisor subdirectory.
cd ~/enviro-pi
sudo ln -s /home/pi/enviro-pi/supervisor/* /etc/supervisor/conf.d/
sudo systemctl restart supervisor.service
sudo supervisorctl
You should see both processes running and good to go. Open you browser on PI_IP_ADDRESS:8080
.
The writer process is storing environmental readings in a local SQLite database. You can use the CLI client to make additional queries on the recorded dataset.
$ sqlite3 sensehat.db
sqlite> .headers on
sqlite> .mode column
sqlite> SELECT * FROM sensehat;
sqlite> SELECT MAX(humidity),
datetime(epoch, 'unixepoch', 'localtime') as date
FROM sensehat;
Please note that time is stored in the epoch
column as time since epoch. Column temp_prs
stores temperature from pressure, not used in the web interface.
Copyright 2016 Pavol Odlevak
Using Chart.js and Moment.js available under the MIT license.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.