Weather Station Data Monitoring : A Flask-based web app to monitor weather via the Netatmo API.
208
A Flask-based web application for monitoring weather data from Netatmo stations. It is designed for learning and practicing Python, Flask, and the API.
This application retrieves and stores weather data from the Netatmo API, with the functionality to view station data, modules, and measurements in an easy-to-navigate interface. This application comes with a built-in SQL server and myPHPadmin. However, there is nothing to stop you from using your own server, just change the database server configuration in app.py and the db section in docker-compose.yml.
This is the first part of the project, the second part will deal with ML and using AI for analysis and prediction.
The app comes with a pre-made .env file in the root directory with the following data:
ACCESS_TOKEN= # Netatmo API access token
REFRESH_TOKEN= # Netatmo API refresh token
CLIENT_ID= # Netatmo API client ID
CLIENT_SECRET= # Netatmo API client secret
TOKEN_EXPIRY= # Unix timestamp for token expiry
TOKEN_URL=https://api.netatmo.com/oauth2/token
API_URL=https://api.netatmo.com/api/getstationsdata?get_favorites=true
For an example, refer to .env.example.
If you want to modify the Docker image to adapt it to your production environment, you need to obtain the app from Git Hub and set up a local development environment in Python.
git clone https://github.com/eavf/netatmo.git
cd netatmo
pip install -r requirements.txt
flask run
Access the application at http://localhost:5000.
For projects with multiple services or containers (like this application with a database and the Flask application), Docker Compose can help manage them in a single configuration file. We will now look at how to download and run this application, along with its MySQL database and phpMyAdmin interface, using a pre-built Docker image from DockerHub.
Ensure you have Docker and Docker Compose installed on your system. You can check if it’s installed by running:
docker --version
docker-compose --version
You can install it if it’s not installed by following the official Docker Compose installation guide.
version: '3.8'
services:
app:
image: eavfeavf/weather-station-app:latest # Použitie obrazu z DockerHub
container_name: flask_app
ports:
- "5000:5000"
environment:
- ACCESS_TOKEN=${ACCESS_TOKEN}
- REFRESH_TOKEN=${REFRESH_TOKEN}
- MYSQL_HOST=db
- MYSQL_USER=vovo
- MYSQL_PASSWORD=vovo_pass_sql
- MYSQL_DATABASE=vovo
depends_on:
- db
db:
image: mysql:8.0
container_name: mysql_db
environment:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_DATABASE: vovo
MYSQL_USER: vovo
MYSQL_PASSWORD: vovo_pass_sql
ports:
- "3306:3306"
volumes:
- mysql_data:/var/lib/mysql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql # Initializes the DB schema
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin_natatmo
environment:
PMA_HOST: db # Links to the `db` service
MYSQL_ROOT_PASSWORD: root_password # Root password of MySQL
ports:
- "8080:80" # Expose phpMyAdmin on localhost:8080
depends_on:
- db
volumes:
mysql_data:
git clone https://github.com/eavf/netatmo.git
cd netatmo
Replace yourpassword (all passwords) with a secure password, and optionally make sure the .env file exists in the root directory with your API credentials and other environment variables. You can also add these via the web menu after running the application.
Ensure you are in the folder containing the docker-compose.yml file, then run:
docker-compose pull # to pull image from dockerhub
docker-compose up -d # to run app
If you prefer to build local image, so go into the app folder and do it by changing the image instruction in the app:
build: .
and buil it locally by:
docker-compose up --build
Or without --built if you didnt change image configuration.
Access the application at http://localhost:5000.
/initialize_tokens: Initialize or update access tokens and credentials.
/show_data_table: View all weather station and module data.
/show_all_measurements: View all measurement data for the weather stations.
/get_data: Fetches current data from the Netatmo API.
http://localhost:8000: Run phpMyAdmin
The links will only work on the computer where the application is running. If you want to run it on a server, you need to modify the configuration of the server itself, reconcile the ports to which the communication is eventually redirected, and especially in the case of a production server, modify the application to run in a publicly accessible location (see the flash documentation).
Note that if you have not previously stored data in the database, any listing from it will be empty.
The application requires a development account on netatmo.com, where the relevant documentation for the Netatmo API is also available and where you can create the necessary keys and also obtain the necessary devices such as weather monitoring stations, thermostatic heads, and other interesting devices to build a smart home. The project is a development project, not a production application, if you don't know the difference between the two, don't use it on the Internet.
Content type
Image
Digest
sha256:3562af74f…
Size
125.3 MB
Last updated
almost 2 years ago
docker pull eavfeavf/weather-station-app