Skip to content

GOA-UVa/meteostation

Repository files navigation

Latest Tag project_license Stargazers


Logo

meteostation

MeteoStation is a software tool for reading data from Thies Clima meteorological stations and storing that data.
This software is designed to work with Thies Clima's Clima Sensor US, part number `4.920x.x0.00x`.

View Demo

Table of Contents
  1. Getting Started
  2. Usage
  3. Setting up the Database
  4. Setting up a Measurement Station
  5. Visualising Data
  6. Sharing Data with Multiple Networks
  7. License
  8. Authors

Getting started

Prerequisites

  • Python >= 3.9.0

Installation

Set Up the Virtual Environment and Install the meteostation package and its dependencies.

1. Create and Activate a Virtual Environment

On Linux and macOS
python3 -m venv .venv
source .venv/bin/activate
On Windows
python -m venv .venv
.venv\Scripts\activate

2. Install meteostation package

After activating the virtual environment, install the meteostation package:

pip install -e .

Note: This library depends on mysqlclient python library. If any error ocurred during the installation of said library in Linux, please refer to its installation instructions

3. Initialize the directory with the needed ancillary files

Run meteostation's setup subcommand to generate the needed configuration and ancillary files to run command in the library.

python -m meteostation setup

After that, the file config.yml will be created in the working directory. Many parameters and options can be configured through this configuration file.

Usage

Once installed, you can run the meteostation subcommands after invoking the module. For example, to run the read_print subcommand:

python3 -m meteostation read_print

To see all the available options please run:

python3 -m meteostation -h

And to see the help for each specific command run add the -h flag after the subcommand. For example, to get the help for the send_command subcommand:

python3 -m meteostation send_command -h

Setting up the Database

DB Prerequisites

  • mySQL or a compatible DB manager like mariaDB

1. Run the SQL scripts

After creating the user username with the valid permissions for the meteostation database, run:

mysql -u username <db/meteostation.sql -p
mysql -u username <db/add_synops.sql -p

Setting up a Measurement Station

1. Set up the configuration files

If not yet done, run the setup subcommand to create the configuration file:

python -m meteostation setup

2. Modify the needed configuration values

Now, you must modify the following config.yml values:

  • instrument.port: Serial port name at which the instrument is connected to.
  • storage.csv_dir: Directory where the downloaded entries from the instrument will be stored as CSV files.
  • database:
    • username: Username to connect to the database.
    • password: Username's password to connect to the database
    • host: URL where the MySQL-like database is hosted at.
    • station: Name of the station to identify it. Must be different from the other stations.

3. Test the instrument data download

Run the subcommand read_store to check that the system can successfully read data from the station:

python -m meteostation read_store

4. Automate the Read and Store Task

Runner script

In order to run the read and store task for a fixed frequency, run the runner.py script. This launches a process that runs the task every 60 seconds using python time.sleep function to wait each period.

This is usually more precise than Window's task scheduler, in case better precision is required.

Linux (Using Crontab)

To run the script automatically at regular intervals, use crontab.

  1. Open the crontab editor:
    crontab -e
  2. Add a new job to run the script every 5 minutes (adjust as needed):
    */5 * * * * /path/to/your/repository/.venv/bin/python3 -m meteostation read_store

Replace /path/to/your/repository with the actual directory where your project is located.

Windows (Using Task Scheduler)

On Windows, you can use Task Scheduler to automate the execution.

  1. Open Task Scheduler (Press Win + R, type taskschd.msc, and hit Enter).
  2. Click Create Task in the right panel.
  3. Modify values under the General tab:
    • Name: MeteoStation Data Download
    • Security options:
      • Select "Run whether user is logged on or not".
      • Check "Do not store password. The task will only have access to local computer resources."
  4. Create a trigger under the Triggers tab:
    • Click New... and configure:
      • Begin the task: On a schedule
      • Settings: One time
      • Start: Set the seconds to :00 to align with minute boundaries.
      • Advanced settings:
        • Check "Repeat task every:" and set the frequency (e.g., 1 minute).
        • Set "for a duration of:" to Indefinitely.
  5. Create an action under the Actions tab:
    • Click New... and configure:
      • Action: Start a program
      • Program/script:
        C:\path\to\your\repository\.venv\Scripts\pythonw.exe
        
      • Add arguments:
        -m meteostation read_store
        
      • Start in:
        C:\path\to\your\repository\
        
  6. Modify settings under the Conditions tab:
    • Power:
      • Uncheck "Start the task only if the computer is on AC power."
      • Check "Wake the computer to run this task."
  7. Click OK to save the task. If prompted, enter your credentials to finalize the setup.

5. Setup the sending of latest data

First, run the subcommand send_last_data to check that the connection with the database works correctly:

python -m meteostation send_last_data 1

After that, automate the process using Crontab or Windows Task Manager.

You can set it up to send last 30 minutes of data every 15 minutes. The command for sending the latest 30 minutes of data would be:

python -m meteostation send_last_data 0.5

Visualising Data

This tool allows users to generate visual representations of the weather data stored in the database.

Configuration

To enable plotting, you must define the output paths in your configuration file under the plot section. The following paths are available:

  • temp_humidity_path: Generates a graph showing temperature, humidity, dew point, and wind chill.
  • winds_path: Generates a graph displaying wind speed, gusts, and direction.
  • precipitation_path: Plots half-hourly and daily precipitation along with atmospheric pressure.
  • csv_path: Path to a CSV file containing the data used in the most recent plot.
  • json_path: Path to a JSON file containing the latest entry's data.

Available Subcommands

  • plots_db_last:

    python -m meteostation plots_db_last [last_hours]

    Generates plots using only data entries newer than last_hours ago.

  • plots_db_interval:

    python -m meteostation plots_db_interval [first_date] [last_date]

    Generates plots based on data retrieved from a specified time interval.

Sharing Data with Multiple Networks

The software currently supports data sharing with five networks:
Windy, Wunderground, PWSweather, Weathercloud, and Meteoclimatic.

Windy

python -m meteostation share_windy [last_minutes]

Fetches weather data from the database covering the past last_minutes up to the current time, and sends it to Windy using the API key and station ID defined in the configuration.

  • Data is sent using Windy's POST method.
  • Windy only accepts near-real-time data, specifically within 60 minutes of the current time.
  • The recommended update frequency is every 5 minutes.

Wunderground

python -m meteostation share_wunderground [last_minutes]

Fetches weather data from the database from last_minutes ago until now, and sends it to Wunderground using the API key and station ID specified in the config.

  • The recommended update frequency is every 10 minutes.

PWSweather

python -m meteostation share_pwsweather [last_minutes]

Retrieves weather data from the past last_minutes and sends it to PWSweather using the API credentials defined in the configuration.

  • Data can be sent retroactively as long as timestamps are accurate.
  • Recommended interval: 5–10 minutes.

Weathercloud

python -m meteostation share_weathercloud

This command must be run on the same machine where data is being collected from the weather station.

  • It reads the most recent local record.
  • If that entry is less than 90 seconds old, it is sent to Weathercloud using your configured credentials.
  • Free-tier Weathercloud accounts can only send data once every 10 minutes. Sending more frequently may result in a temporary block.
  • Only one data point is sent per execution. Batch sending is not supported.

Meteoclimatic

python -m meteostation share_local_meteoclimatic

This command must be run on the same machine where data is being collected from the weather station.

  • Reads the most recent local record.
  • If the entry is less than 90 seconds old, it is sent to Meteoclimatic using the configured credentials.
  • Meteoclimatic ignores the dateutc field in the Wunderground-style payload. It assigns the timestamp of reception as the official measurement time.
  • Data is sent using the Wunderground protocol, which is accepted by Meteoclimatic's EWU adapter.
  • Important: Meteoclimatic requires updates at least every 60 seconds when using this method. This script does not control the timing, one must schedule it appropriately using cron, systemd, or equivalent.

License

This project is licensed under the GNU General Public License v3.0 or later (GPLv3+).
See the LICENSE file for details.

Authors

About

Software tool for retrieving, storing and plotting data from Thies Clima meteorological stations. Designed specifically for use with the Thies Clima Clima Sensor US (part number 4.920x.x0.00x)

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors