GPL-2.0 License
Turn Raspberry Pi into weather station with DHT22 sensor and OpenWeatherMap.org
Live example located in Szczecin, Poland can be found here: http://weather.spychalski.info/
Blog: http://shtr.eu/
sudo apt-get update
sudo apt-get install git build-essential python-dev python-smbus
git clone https://github.com/adafruit/Adafruit_Python_BMP.git
cd Adafruit_Python_BMP
sudo python setup.py install
wget abyz.co.uk/rpi/pigpio/pigpio.zip
unzip pigpio.zip
cd PIGPIO
make
make install
sudo /home/pi/PIGPIO/pigpiod
to /etc/rc.local
sudo apt-get install php5-sqlite
sudo apt-get install nginx php5-fpm php-apc
git clone [email protected]:DzikuVx/WeatherStation.git
cd WeatherStation
git submodule init
git submodule update
python get_data.py
To configure WeatherStation to work with OpenWeatherMap you need to set some data in a few places.
For example, to get data for Szczecin, Poland you need to:
$config['cityId'] = 3083829;
. Of course, 3083829 is city ID for Szczecin, Poland. For any other city you need to set other ID (but this is obvious).config = {
'user': 'DzikuVx',
'password': 'you_would_like_to_know',
'api': 'yes_you_do_want_to_have_own_api_key',
'location': 'Szczecin,PL',
'coords': 'lat=53.48&long=14.40&alt=100'
}
Starting from release 1.2.0 WeatherStation starts to use new database with different tables and field names. If you have previous version running and want to update to 1.2.0 or newer you have to run migration scrit.
To run migration do as follows:
data.db
data.db
was not overwiritten during update. If so, restore it if from a copy mada in step 1python migrate.py
data.db
and data-new.db
. They should be similar in size (up to 20% difference is acceptable)If you are doing a fresh install, migration is not required
To serve its purpose, WeatherStation need to collect data on regular basis. That's why you need to configure some crontab jobs (crontab -e
):
*/20 * * * * sudo python /home/pi/WeatherStation/get_data.py
*/20 * * * * python /home/pi/WeatherStation/get_external_data.py
*/30 * * * * python /home/pi/WeatherStation/upload_data.py
*/15 * * * * wget -qO- http://weather.spychalski.info/cron.php &> /dev/null
server {
listen 0.0.0.0:80;
server_name weather.spychalski.info;
access_log off;
root /home/pi/WeatherStation/website;
index index.php;
# default try order
location / {
try_files $uri $uri/ /index.php?$args;
add_header Access-Control-Allow-Origin *;
}
# enable php
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
#Internet Of Things - ThingSpeak integration
Weather station provides simple ThingSpeak integration using REST api. This allows to upload collected measurements to ThingSpeak.
To enable ThingSpeak data upload:
thingspeakconfig.py
python thingspeak_post.py
*/30 * * * * python /home/pi/WeatherStation/thingspeak_post.py
To develop web interface:
docker-compose up -d
./node_modules/gulp/bin/gulp.js```