Giter Club home page Giter Club logo

balena-weather's Introduction

Balena Weather Station

A Raspberry Pi based weather station, running a extensible Balena multi-container application inspired by the Raspberry Pi weather station project.

Weather Station

The following sections describe the hardware, wiring and configuration of the Balena Weather Station.

Hardware

Raspberry Pi 3

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.

Wiring

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.

Balena Weather Wiring

Deploy the code

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:

balena deploy button

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 with balena push <application-name>
  • See the magic happening; your device is getting updated 🌟Over-The-Air🌟!

Configure the Balena Weather Station

On the software side, the Balena Weather Station is built as a multi container application. Services are defined in docker-compose.yml.

balena-weather-station-balenaCloud

DT parameters and overlays

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".

Balena Device Configuration

Device Variables

The following Device Variables are supported by the Balena Weather Station:

Balena Device Variables

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

Access to the Grafana interface

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)

Grafana Dash

Individual service descriptions

The following sections describe the various services in more detail.

Sensors

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, Telegraf and InfluxDB

  • 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.

UI and API

  • 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.

Powering the Raspberry Pi via the 5V rail

I decided to power the Raspberry Pi via the 5V power rail. The following links provide information on how to do so.

Extending the Balena Weather Station

The balena-weather GitHub repo contains a solar branch with the required changes to add electricity production data for a SolarEdge solar panel installatio.

SolarEdge

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.

Contributing

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.

Troubleshooting

If you have any issues feel free to add a Github issue here or add questions on the balena forums.

balena-weather's People

Contributors

hferentschik avatar mpous avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

balena-weather's Issues

Improve README

Improve the README and add more information about the actual assembly/build part.

The README just refers to https://projects.raspberrypi.org/en/projects/build-your-own-weather-station as a reference, without further information. The relevant portions of the build should be inlined into the README/repo (preferably with some images).

Maybe it even makes sense to extract the "build" part into a dedicated markdown file. This will keep the README a bit more concise.

High levels goals:

  • Better descriptions of the concrete parts used
  • Step by step build instructions
  • Important steps to watch out for

Use a release version of InfluxDB

Currently, the code depends on a specific SHA with an unclear origin.

  influxdb:
    container_name: influxdb
    image: influxdb@sha256:73f876e0c3bd02900f829d4884f53fdfffd7098dd572406ba549eed955bf821f
    restart: always
    environment:
      - INFLUXDB_ADMIN_ENABLED=true
      - INFLUXDB_ADMIN_USER=admin
      - INFLUXDB_ADMIN_PASSWORD=admin
    volumes:
      - 'influxdb-data:/data'
    ports:
      - "8086:8086"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.