SwitchDocLabs WeatherStation from a Raspberry PI, in Java
The WeatherPiArduino Weather Board is described here.
It requires an ADS1015 for the Wind Direction (I2C ADC, address 0x48).
Important: This document goes along with the code at https://github.com/OlivierLD/raspberry-pi4j-samples/.
- In the sources, refer to
- There is also a full example, in RasPISamples, in the
weatherstation package. The script to run it is
This example provides several features:
- Read the weather station
- Feed a WebSocket (nodejs) server
- Log the data (in a MySQL database)
- Display the data in an HTML5 console (both logged data and real-time WebSocket ones)
We've added a Photon, that pings the Raspberry PI in real time to feed an IoT server.
This way, real-time data are also accessible from anywhere on the Internet.
It has an integrated BMP180 (I2C, address 0x77).
The Fritzing schema provided by SwitchDocLabs looks like this:
Orange & Yellow wires are the I2C ones (SDA, SCL), used by the ADS1015 & the BMP180, at least.
Gray and ochre ones can use any GPIO pin of the Raspberry PI's header, they will be used for the Wind Speed (ochre) and the Rain flow (gray).
In the diagram:
Those 2 pins will be used by the
- The ochre wire is on pin #10, called GPIO 15, WiringPi and PI4J call it GPIO_16.
- The gray wire is on pin #12, called GPIO 18, WiringPi and PI4J call it GPIO_01.
init method of the class
Those pins will be used to count the 'ticks' emitted by the anemometer, and the pluviometer.
final Pin ANEMOMETER_PIN = RaspiPin.GPIO_16; // <- WiringPi number. GPIO 15, #10
final Pin RAIN_PIN = RaspiPin.GPIO_01; // <- WiringPi number. GPIO 18, #12
SDLWeather80422 weatherStation = new SDLWeather80422(ANEMOMETER_PIN, RAIN_PIN, AdcMode.SDL_MODE_I2C_ADS1015);
The number of ticks is counted by a listener on that pin. A tick is an occurrence of the pin turned from
It works at least with the Raspberry PIs B, B+, A+, and B2.
It is easy from this kind of code to feed a WebSocket server (running on the RPi, even an A+ can run nodejs, without feeling it) and render the data to whoever can get connected on its network:
There is also an HTML5 rendering of the same data:
Real time data. You have to be in the same wireless network as the Raspberry PI.
This is where an Internet Of Things (IoT) server can be an asset. See the Photon section about that.
Mounted on its acrylic plate, with a Raspberry PI A+.
First presentation on the roof, Ocean Beach, San Francisco, CA.
Notice the hatch in the roof, made for the occasion...
With a "housing" for the Raspberry PI ;)
A rendering of the data logged by the Raspberry PI.
Accessible live from here.
A Photon in the picture
The Photon is a small and cheap IoT board provided by Particle.
The cool thing is that is also includes access to a server that can be used in a real-time mode, from anywhere on the Internet.
The project also contains a Photon sketch (
weather-station-http-client.ino) that runs on a Photon.
It pings the Raspberry PI to get the data (the node server running on the Raspberry PI can return a json object that represents the currant situation), and feeds the Particle IoT server.
This page displays a rendering if those live data. As you can tell, it does not require to be on the same network as the Raspberry PI. The Internet is good enough to host that thing.
Oliv did it