Another Raspberry Pi Weatherstation
Project description
snweatherstation
Another weather station for Raspberry Pi, logging temperature, humidity and pressure in a database table or to a file.
Getting started
Step | Action |
---|---|
1. | Install snweatherstation ([sudo] pip install snweatherstation ) |
2. | Connect the chosen sensor to the Raspberry Pi GPIO pins (see Supported Sensor Types) |
3. | Create a new MariaDB database or select an available one (see MariaDB below) |
4. | Create table for weather data (see Database Schema Setup) |
5. | Stage and configure the configuration file (see Configuration) |
6. | Do a test run (see Usage) |
7. | Set up Weatherstation service (see Configure Weatherstation Service) |
Usage
usage: weatherstation.py [-h] [-t] [-s] [-l] [-L] [-F] [-f FILE] [-v]
[-c CONFIG]
This program periodically reads environment sensor data
and stores these either in the database and/or in a file and/or just prints measured values.
If not otherwise specified on the command line, a configuration file
weatherstation.json
will be searched under $HOME/.config or under /etc.
This configuration file specifies the database connection and other runtime parameters.
optional arguments:
-h, --help show this help message and exit
-t, --test Test run - single cycle - no wait
-s, --service Run as service - special logging
-l, --log Shallow (module) logging
-L, --Log Deep logging
-F, --Full Full logging
-f FILE, --file FILE Logging configuration from specified JSON dictionary file
-v, --verbose Verbose - log INFO level
-c CONFIG, --config CONFIG
Path to config file to be used
Configuration
Configuration for weatherstation needs to be provided in a specific configuration file.
By default, a configuration file "weatherstation.json" is searched under $HOME/.config
or under /etc
.
Alternatively, the path to the configuration file can be specified on the command line.
Structure
The following is an example of a configuration file:
{
"sensorType": "DHT22",
"raspiPin": "PIN13",
"measurementInterval": 10,
"dbOut": true,
"fileOut": false,
"dbConnection":
{
"host": "localhost",
"port": 3307,
"database": "weather",
"table": "weatherdata",
"user": "testuser",
"password": "$[TestUser-1]@?"
},
"fileName": "~/weatherData.txt"
}
Parameters
Parameter | Description |
---|---|
sensorType | Type of the environment sensor (see supported sensor types, below) |
raspiPin | Raspberry Pi GPIO pin in BOARD notation used for data signal, if required |
measurementInterval | Measurement interval in seconds. |
dbOut | Specifies whether measured values shall be stored in the database (true, false) |
fileOut | Specifies whether measured values shall be written to the specified file (true, false) |
dbConnection | Database connection parameters (optional) |
host | Host name or IP address of database server |
port | Port for MariaDB service |
database | Name of the database where data shall be stored |
table | Name of database table where data shall be stored |
user | Database user |
password | Password for database user |
fileName | Path to file to which data shall be written (optional) |
Supported Sensor Types
See also https://github.com/signag/snraspi-lib/blob/main/docs/EnvironmentSensors.md
SensorType | Description | Measured Data | Raspi bus | raspiPin |
---|---|---|---|---|
DHT11 | DHT11 | temperature, humidity | 1-Wire | 1-Wire pin |
DHT22 | DHT22 | temperature, humidity | 1-Wire | 1-Wire pin |
BME280_I2C | BME280 | temperature, humidity, pressure | I2C | -- |
BMP280_SPI | BME280 | temperature, humidity, pressure | SPI | Chip Select |
MariaDB
weatherstation stores weather data in a MariaDB database (see https://mariadb.org/).
MariaDB is available on Linux and Windows platforms. A MariaDB server is also provided as plugin on most of the popular NAS systems. For weatherstation, you may use any of your available MariaDB servers, as long as it is visible to your Raspberry Pi.
Alternatively, you may also install a MariaDB server on your Raspberry Pi.
NOTE MariaDB Client and connectors are installed together with weatherstation.
Setup MariaDB Server on Raspberry Pi
INFO Skip this step if you will be using an existing MariaDB server
Installation
sudo apt install mariadb-server php-mysql
sudo apt install phpmyadmin
Service configuration
For automatic start:
sudo systemctl enable mariadb
For manual start:
sudo systemctl disable mariadb
sudo systemctl start mariadb
sudo systemctl stop mariadb
Database Schema Setup
weatherstation requires a database table with a specific structure.
An SQL script template is available under ./data
: createDBtable.sql in the installation folder.
The table name can be adjusted in the script and configured in the weatherstation config file so that different tables can be used to distinguish different physical weather stations in the same database.
Run this SQL script against the database to create the required database table.
Configure Weatherstation Service
To continuously log weather data, weatherstation should be run as service.
See https://www.raspberrypi.org/documentation/linux/usage/systemd.md
A service configuration file template can be found under
./data
in the installation folder.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file snweatherstation-1.0.0.tar.gz
.
File metadata
- Download URL: snweatherstation-1.0.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.21.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de0e2024b7bacf1c0be2825e7f7c0c226c11ab6a0a59cbebfc063a93ab950dcc |
|
MD5 | b8fb59bb7b67a073e1a29ca7106055bb |
|
BLAKE2b-256 | 0f90c424074619a29a1f20fde34aa2d2614a3e8d746ecf340a3fefe2221cc7a5 |
File details
Details for the file snweatherstation-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: snweatherstation-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.21.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f9d0390de96b3186f130eb516ea36791cf7c45004782711ab5689d6bc2ee5ae |
|
MD5 | 97a38904d83893d7c30de63b56387128 |
|
BLAKE2b-256 | 3d1403d6eed80a037acdc3ffe5d99a8b58a7a29e0990a75c1609f3a4d73c9475 |