Skip to content

A virtual weather station running on a Docker container that gets information from a raspberry pi, displays the data and notifies the user when certain conditions are met

License

Notifications You must be signed in to change notification settings

5okin/Virtual-Raspberry-Pi-weather-station

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Virtual Raspberry Pi weather station

A virtual weather station that periodically generates temperature, air humidity, ground humidity and wind speed data. It checks the values (locally) and if they differ by more than 10% they are send to server. If data hasn't been send to the server for over five minutes, the current measurements are send.

The server processes the incoming data, if the temperature increased by 40% and the air humidity decreased by 50% within the last five minutes, it sends a email alert to the user. The incoming data is also logged to a database and visualized using grafana.


Overview

Untitled Diagram


Server architecture

The server is a multi-container Docker app that uses the following:

  • InfluxDB - time series database.
  • Python3 - Programming language.
  • Flask - Web development framework.
  • Grafana - visualization UI for InfluxDB.

The database, grafana and the webApp are automatically connected. Furthermore grafana is setup with a user account and a working dashboard, displaying all the information.


Client architecture

The client is a Python3 program designed to run a RaspberryPi, it generates random measurements every 30sec or loads them from a JSON file (fake_weather.json).

{
    "temperature": 17.4, 
    "air-humidity": 72, 
    "ground-humidity": 70, 
    "windspeed": 8, 
    "time": ""
} 

Installation guide

Server:

  1. Install Docker and docker-compose.
  2. Download the server folder from the repository to the host.
  3. Change the usernames/passwords for the database, grafana, and the email in the .env file, more on that later.

Run the following command to start the server:
docker-compose up -d

To stop run:

docker-compose down

Client:

  1. You have to have Python3 installed (comes pre-installed on Raspberry pi).
  2. Download the client folder to the Raspberry pi.
  3. Navigate to the downloaded file directory.
  4. Install the required libraries using pip:
pip install -r requirements.txt 
  1. Start the client using:
python3 client.py
  1. Type in the IP of the server (without a port number, that is automatically 5000) and choose the operation mode.

mode_select

Ports

Service Host Port
Grafana 3000
InfluxDB 8086
Flask WebApp 127.0.0.1:5000

Note that if you want Influx to be accessible outside of Docker, you have to uncomment the option from the server/Docker-Compose.yml file.


Volumes

Two docker volumes are created so that the data isn't lost on reboot.

  • influxdata
  • grafanadata

Users, passwords and accounts

Three users are created, one user account for flask to connect to the database

  • InfluxUser
  • InfluxUserPass

Two admin users, one for InfluxDB and one for Grafana.

  • InfluxAdminUser
  • InfluxAdminPass
  • GRAFANA_USERNAME
  • GRAFANA_PASSWORD

Mail

If conditions are met (+50% temperature and -40% humidity) than a email notification is send.

alert

To send the alerts a google email account is needed with the Less secure app access option enabled.

Add the username and password to the .env file.

  • MailUser
  • MailPass

Read more about Less secure app access here.


Database

Influx DB creates a database with the name InfluxDatabaseName = 'env_data'.


Grafana

Grafana is used to visualize the data, by default you can log in by going to localhost:3000 and using username and password admin.

alert

A dashboard with the name Pi is automatically created with the graphs and the queries that are needed.


Grafana data sources

A data source with the name Rpi_EnvSensor_Data is created and is linked to the created database (env_data).

./grafana-provisioning/datasources/

Learn more about data sources from the Grafana Documentation.

About

A virtual weather station running on a Docker container that gets information from a raspberry pi, displays the data and notifies the user when certain conditions are met

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published