Page 1 of 1

Temperture and Humidity Web Monitor

Posted: Sat Sep 12, 2015 2:01 pm
by hawkerpl
Damn hot pie
Hi ! I wanted to share with you my app for temperature and humidity web monitoring.
You need reaspberry pi and DHT temperature sensor. Here is the repo https://github.com/hawkerpl/damn_hot_pie.
And the project description continues below (copy from "README.md").

Raspberry Pi DHT sensor website app
This app lets you to view your DHT readouts online in a form of interactive plot.

Sample:
Image

(Viewing this plot may require you to push the autoscale button on plot.)

Setup
- Raspberry PI
- DHT11 sensor (DHT22 and DHT2303 are also supported, see wiringhttp://docs.gadgetkeeper.com/pages/view ... Id=7700673)
- interwebz connection
- Python 2.7
- Flask
- SQLAlchemy
- Adafruit DHT driver
- plotly

Dependencies
For web server and database dependencies requirements run:

Code: Select all

sudo pip install -r requirements.txt
You will also need Adafruit Python DHT driver.
The driver is accessible here:
https://github.com/adafruit/Adafruit_Python_DHT
Follow the installation instructions in the link above.

Installation

This projects runs purely as python app. As long as all the requirements are met, you don't have to install anything.

Running the project
If you are not interested in further options just run:

Code: Select all

python run_app.py
Website will run defaultly on host `0.0.0.0` and port `8080`.

Additional options of running and project files

model.py
This file contains sql model of the database where all sensor data will be saved. Running this script will result in creating file `dht_database.db` in folder where `model.py` is.

record_data.py and recording data to database
Contains class responsible for acquiring data input and saving it in database. Can be runned separately as script. If runned, will loop endlessly and save sensor data to database with given interval.

Code: Select all

Usage: record_data.py [options]

Options:
  -h, --help  show this help message and exit
  -p          print every record to STDOUT [default: False]
  -t T        time interval in minutes to request readout from sensor
              [default: 15]
  --pin=PIN   data pin connected to sensor [default: 4]
  -s S        number of DHT sensor in use (supported: 11, 22, 2302) [default:
              11]

server.py, template/index.html and the web service
`server.py` contains flask server with web-service. The web-service hosts restful api.

Method | Endpoint | Usage | Returns
---------- | ------------- | ------------- | -------------
GET | /data/ | Get last n sensor data rows. Where n is limit given in script. | List of sensor readouts.
GET | /data/{m} | Get last m sensor data rows. Where m is given parameter. If m>n then service will return n data rows. Where n is limit given in script. | List of sensor readouts.
GET | /last | Get last sensor readout. | Sensor readout.

Sensor readout(JSON):

Code: Select all

{"date": "Y-M-D h:m:s.s", "id": id, "temperature": t, "humidity": h}
Example:

Code: Select all

{"date": "2015-09-12 11:23:25.126321", "id": 3, "temperature": 20, "humidity": 37}
Request send to `/` will return index page from template folder.

`server.py` can be runned separately as a script. If so, it will set up web-service defaultly on host `0.0.0.0` and port `8080`.

Code: Select all

Usage: server.py [options]

Options:
  -h, --help   show this help message and exit
  --port=PORT  port [default: 8080]
  --host=HOST  host [default: 0.0.0.0]
  -n N         max limit of rows available by /data/ [default: 100]

run_app.py
This script combines run of `service.py` and `record_data.py`.
The recording class from `record_data.py` runs as a separate thread.

Code: Select all

Usage: you can find options info in server.py and record_data.py or by calling this script with -h options

Options:
  -h, --help   show this help message and exit
  --port=PORT  port [default: 8080]
  --host=HOST  host [default: 0.0.0.0]
  -n N         max limit of rows available by /data/ [default: 100]
  -p           print every record to STDOUT [default: False]
  -t T         time interval in minutes to request readout from sensor
               [default: 15]
  --pin=PIN    data pin connected to sensor [default: 4]
  -s S         number of DHT sensor in use (supported: 11, 22, 2302) [default:
               11]

Re: Temperture and Humidity Web Monitor

Posted: Sun Apr 30, 2017 8:24 pm
by mythofgriff
This is really cool! I know it is old but still cool.

If anyone knows how, it would be cool if the database-backed plot had axis labels and the legend said % humidity and degrees Celsius. The 1h,1d,1mo,1yr, and 'all' buttons would be cool too. I tried to figure it out, but plotly only exports a static version of the interactive graph... https://plot.ly/~griffincalme/3/

Re: Temperture and Humidity Web Monitor

Posted: Thu May 04, 2017 2:56 pm
by leocat3

Re: Temperture and Humidity Web Monitor

Posted: Thu May 04, 2017 3:40 pm
by tpylkko
In a way, a much more easier and eloquent (but also more common now) solution is to send that data with MQTT to a server like mostquitto or a cloud. Then you can plot the data with any of the already existing applications for phones, browsers whatever. But this does look nice for when you don't a bunch of sensors in different locations.

Re: Temperture and Humidity Web Monitor

Posted: Fri May 05, 2017 9:38 pm
by mythofgriff
mythofgriff wrote:This is really cool! I know it is old but still cool.

If anyone knows how, it would be cool if the database-backed plot had axis labels and the legend said % humidity and degrees Celsius. The 1h,1d,1mo,1yr, and 'all' buttons would be cool too. I tried to figure it out, but plotly only exports a static version of the interactive graph... https://plot.ly/~griffincalme/3/

Check it out!!! https://github.com/griffincalme/rpi_climate_server
I created a new module called generate_graph.py that generates a graph in the templates folder. I also edited the flask server.py so that it renders the templates/climate_graph.html. The record_data.py calls generate_graph() to render a new html page after recording every temp/humidity reading.

I had it originally so that the server generated a new graph each GET request. But rendering only after every temperature reading makes more sense. This way, the server doesn't get bogged down rendering every time someone does a GET request, it only does it when a new reading is added to the database.

It was a little difficult to figure out what code from the original is now obsolete, so I left most other stuff in and it seems to work fine.