A Raspberry Pi based weather station, running a extensible Balena multi-container application inspired by the Raspberry Pi weather station project.
The following sections describe the hardware, wiring and configuration of the Balena Weather Station.
- Balena Weather Station
Let's start with the hardware used for this project.
- 1 Raspberry Pi 3 - the heart of the weather station. Balena Weather Station is also compatible with the Raspberry Pi 4.
- 1 Sparkfun Weather Meter Kit - the main weather station components, including an anemometer, wind vane and rain gauge.
- 1 Prototyping HAT for Raspberry Pi - I aimed to build a permanent weather station (see picture above). For this reason, I opted for the Prototyping HAT and soldering. You can also use a GPIO extender board with a breadboard for a less permanent solution.
- 1 MCP3008 - a 8-channel, 10-bit ADC with SPI interface. It is used to convert the analog voltage provided by the wind vane into a digital value.
- 1 SHT-30 - a wheater proof humidity sensor that includes a temperature sensor. The temperature measurements by the SHT-30 are also stored in InfluxDB. However, the default Grafana dashboard does not include them.
- 1 DS18B20 - standard 1-wire bus waterproof temperature sensor.
- 2 4.7kΩ resistors - used for the wind vane's voltage divider circuit as well as a pull-up resistor for the temperature sensor.
- 1 Raspberry Pi IP54 Outdoor Project Enclosure - a weatherproof enclosure for the Raspberry Pi.
The following diagram provides the schematics of the Balena Weather Station. The anemometer, wind vane and rain gauge are symbolised by their main electric component.
NOTE: The Sparkfun Weather station comes per default with 6-pin RJ11 connectors. The middle four pins are connected, but only two cables are used. Refer to the Sparkfun Weather Meter Kit manual to see which cables are relevant for each of the components.
Running this project is as simple as deploying it to a balenaCloud application. You can do it in just one click by using the button below:
Follow instructions, click Add a Device and flash an SD card with that OS image downloaded from balenaCloud. Enjoy the magic 🌟Over-The-Air🌟!
Via the balena
CLI
If you would like to add more services, get the balena
CLI and follow these steps:
- Sign up on balena.io
- Create a new application on balenaCloud.
- Clone this repository to your local workspace.
- Using the
balena
CLI, push the code withbalena push <application-name>
- See the magic happening; your device is getting updated 🌟Over-The-Air🌟!
On the software side, the Balena Weather Station is built as a multi container application. Services are defined in docker-compose.yml.
For the sensors to work, the Balena device or fleet configuration needs to enable the w1-gpio overlay as well as set the DT parameters "i2c_arm=on","spi=on".
The following Device Variables are supported by the Balena Weather Station:
Variable Name | Value | Description | Default |
---|---|---|---|
SAMPLE_RATE |
INT |
The default sample rate for each container is 15 minutes (specified in seconds). | 900 |
MQTT_USER |
STRING |
Username to authenticate with the MQTT message broker | |
MQTT_PASSWORD |
STRING |
Password to authenticate with the MQTT message broker | |
LATITUDE |
FLOAT |
Specify your LATITUDE for the api service that calculates sunrise and sunset |
|
LONGITUDE |
FLOAT |
Specify your LONGITUDE for the api service that calculates sunrise and sunset |
|
TIMEZONE |
STRING |
Defines your timezone to calculate the time of your sunrise and sunset |
Once all the services are successfully deployed, you will be able to access the Weather Station Grafana interface using the local device address http://<local-ip-address>/weather
or the Balena public address http://<public-ip-address>/weather
respectively.
TIP: Assuming your fleet is called weather, you can retrieve the public URL using:
balena device public-url $(balena devices -a weather --json | jq -r .[].id)
The following sections describe the various services in more detail.
Each service is contained in its own subdirectory. The README in each subdirectory provides additional information for each service.
- Anemometer - Anemometer (wind speed) sensor of the weather station.
- Humidity - Humidity and temperature sensor SHT-30.
- Raingauge - Raingauge sensor of the weather station.
- Temperature - Additional DS18B20 temperature sensor. I am using an additonal temperetature sensor to the SHT-30 temperature sensor which I place in the shade. The SHT-30 on the other hand is in direct sunlight.
- Windvane - Windvane sensor of the weather station.
- MQTT - Eclipse Mosquitto container which acts as message broker to which all sensors are sending their data. The Telegraf container reads from the Mosquitto queue and pushes the metrics into InfluxDB.
- Telegraf - Part of the TIG stack to consume and display sensor data.
- InfluxDB - Time series database storing the sensor data. This is the storage component of the TIG stack. It uses a default InfluxDB DockerHub image.
- NGINX - NGINX listening on port 80 and acting as reverse proxy.
- API - A Ruby based Sinatra app used for exposing REST APIs for Grafana (using the JSON datasource plugin).
- Grafana Dashboard - the Grafana dashboard displaying all data.
I decided to power the Raspberry Pi via the 5V power rail. The following links provide information on how to do so.
The balena-weather GitHub repo contains a solar branch with the required changes to add electricity production data for a SolarEdge solar panel installatio.
The data itself is provided by the balena-solar-edge service. balena-solar-edge uses the SolarEdge Monitoring Server API to retrieve the data and then pushes the data to MQTT.
The service can easily be added to docker-compose.yml like so:
solar:
image: hferentschik/solar-edge:0.0.1
restart: always
depends_on:
- mqtt
To keep the SolarEdge data seperate from the weather data, it gets stored into its own InfluxDB database. To do this a new Telegraf configuration file (solar-edge.conf) gets added to the /etc/telegraf/telegraf.d directory of the telegraf service. The configuration follows the Telegraf Best Practices in order to keep the configuration for the weather and solar part seperate. In particular the use of tagpass is important to ensure that only data from the solar MQTT topic ges added to the solar database.
###############################################################################
# OUTPUT PLUGINS #
###############################################################################
[[outputs.influxdb]]
alias = "influxdb_solar"
timeout = "1s"
database = "solar"
urls = [ "http://influxdb:8086" ]
[outputs.influxdb.tagpass]
topic = [ "solar" ]
###############################################################################
# INPUT PLUGINS #
###############################################################################
[[inputs.mqtt_consumer]]
alias = "mqtt_solar"
servers = [ "mqtt:1883" ]
topics = [ "solar" ]
json_name_key = "measurement"
data_format = "json"
json_time_key = "time"
json_time_format = "2006-01-02T15:04:05"
tag_keys = [
"tags_name", "tags_image", "tags_model"
]
# username = "mqtt"
# password = "pass"
Last but not least, the Grafana dash needs to be updated to display the solar data. The required changes are part of dashboard.json in the dashboar service.
Using this approach other services can be added as well.
Contributions, questions, and comments are all welcomed and encouraged!
If you want to contribute, follow the contribution guidelines when you open issues or submit pull requests.
If you have any issues feel free to add a Github issue here or add questions on the balena forums.