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.
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.
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": ""
}
- Install Docker and docker-compose.
- Download the server folder from the repository to the host.
- 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
- You have to have Python3 installed (comes pre-installed on Raspberry pi).
- Download the client folder to the Raspberry pi.
- Navigate to the downloaded file directory.
- Install the required libraries using pip:
pip install -r requirements.txt
- Start the client using:
python3 client.py
- Type in the IP of the server (without a port number, that is automatically 5000) and choose the operation mode.
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.
Two docker volumes are created so that the data isn't lost on reboot.
- influxdata
- grafanadata
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
If conditions are met (+50% temperature and -40% humidity) than a email notification is send.
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.
Influx DB creates a database with the name InfluxDatabaseName = 'env_data'
.
Grafana is used to visualize the data, by default you can log in by going to localhost:3000
and using username and password admin.
A dashboard with the name Pi is automatically created with the graphs and the queries that are needed.
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.