/rpiWeather

A simple python code that reads weather data from a DHT22 sensor and renders the reading using Flask

Primary LanguagePythonMIT LicenseMIT

rpiWeather

RaspberryPi setup

Install python pip:

$ sudo apt-get install python-pip -y

Install flask, pymysql, Adafruit_Python_DHT:

$ pip install flask
$ pip install pymysql
$ pip install Adafruit_Python_DHT

Set the crontab

Create a crontab

$ crontab -e

Set the sampling interval to 20 minutes (this will take a record every HH:00, HH:20, HH:40)

*/20 * * * * /usr/bin/python /path/to/weather_to_db.py

Database setup

CREATE DATABASE IF NOT EXISTS weather;
CREATE TABLE IF NOT EXISTS weather.dht (`when` DATETIME, temperature TINYINT, humidity TINYINT, PRIMARY KEY (`when`));

Hardware setup

Connect sensor pin 1 to RPi pin 1 (3.3V)
Connect sensor pin 2 to RPi pin 7 (GPIO4)
Connect sensor pin 4 to PRi pin 9 (GND)
Connect a 10kΩ resistor between sensor pin 1 and 2 (pull-up resistor)

For more information on DHTXX sensors refer to: Adafruit documentation