Weather Station

We would like to keep track of the weather while on the move. Of course we could have just bought a regular weather station and mounted it somewhere in Molly. But we took a different approach, which involved a number of environment sensors, a Raspberry Pi and a little programming. The end result was great.

Of course it is good know what the current weather is, but it would also be nice to go back in time and know what the weather was on a particular day. And then cross reference this with where we were at that time. Turns out this is all possible.

The Sensors

Our little weather station is powered by sensors from Dracal Technologies out of Canada. We monitor indoor temperature and relatively humidity using the USB-TRH420 sensor, and outside we monitor temperature, relatively humidity and barometric pressure using the USB-PTH200 sensor. No plans to add light or wind sensors.

As the model numbers suggest, these sensors come with a USB connection. That makes it easy to connect to the Raspberry Pi. No soldering of wires needed.

Install USB drivers

However, there was a little bit of work to make the Raspberry Pi communicate with the sensors. I set myself a challenge to sort this in the time it takes to drink a cup of tea. It ultimately required two cups of tea. See below for the details of installing the USB Drives on a Raspberry Pi.

node-red Configuration

The indoor sensor has 2 “real” measurements, being temperature and humidity. It also has three “derived” measurements, of Dew Point, Humidex and Heat Index.

The outdoor sensors extends the indoor sensor with a real measurement of barometric pressure and derived measurements of xxx.

Grafana showing current and 5 day trend of temperature and humidity for 1 sensor.
And now with both sensors, indoor and outdoor.

Sensor Specifications

Indoor Sensor Specifications
Dracal USB-THR420

Temperature

Probe operating range: -40°C to 70°C.

Accuracy: ±0.2°C (-40C to 80°C)

Resolution: 0.015°C (typical)

Relative Humidity

Probe operating range: 0 to 100 %RH

Accuracy (at 25°C): ±1.5% from 0 to 70 %RH

Resolution: 0.01 %RH

Outdoor Sensor Specifications
Dracal USB-PTR200

Temperature

Probe operating range: -40°C to 70°C

Accuracy: ±0.3°C (-20°C to 70°C)

Resolution: 0.015°C (typical)

Relative Humidity

Probe operating range: 0 to 100 %RH

Accuracy: (at 25°C): Typical: ±2% from 0 to 90 %RH

Resolution: 0.01 %RH

Atmospheric (Barometric) Pressure:

Range: 1 to 120 kPa (10 to 1200 millibars)

Accuracy: ±0.15 kPa at 25 °C (1.5 millibars)

Resolution: 0.0065 kPa (0.065 millibars)

Altitude resolution: approx. 10 cm.

Installing Software on the Raspberry Pi

Installing the USB Drivers

The Dracal support website does a good job at explaining what to do. For linux I did the following.

Step 1. Make a cup of tea.

Step 2. Download the USB driver software and copy it over to the Raspberry Pi

Step 3. On the Raspberry Pi get the missing library which is achieved by

$ sudo apt-get install libusb-1.0-0-dev

Step 4. Go to the /client directory and make the executable

$ cd ~/usbtenki/usbtenki-2.1.17/client
$ make

Step 5. Now that we have the executable, let’s test it with the following command

$ ./usbtenkiget -l

which produces the following output (in my case)

Found: 'USB-TRH420', Serial: 'E14759', Version 1.3, Channels: 5
    Channel 0: SHT31 Temperature [Temperature]
    Channel 1: SHT31 Relative Humidity [Relative Humidity]
    Virtual Channel 256: Dew point [Dew point]
    Virtual Channel 257: Humidex [Humidex]
    Virtual Channel 258: Heat index [Heat index]

So this is obviously encouraging, but not so fast. The command to actually retireve the values (./usbtenkiget -i 0,1,256) did not work due to a permission problem.

Step 6. Make another cup of tea. After checking the Dracal support website, this was fixed by the following

$ sudo cp ~/usbtenki/usbtenki-2.1.17/scripts/99-usbtenki.rules /etc/udev/rules.d/

And after a quick reboot, now things are running a bit better

$ ~/usbtenki/usbtenki-2.1.17/client/usbtenkiget -i 0,1,256 -p
Temperature: 24.58 °C
Relative Humidity: 40.41 %
Dew point: 10.23 °C
Configuring node-red
node-red flow for sensors

The USB drivers can be accessed with a exec module within node-red. In our setup the command line to be used was

~/usbtenki/usbtenki-2.1.17/client/usbtenkiget -i a

Followed by a function block to assign the return string to variables. The final code has more error checking, but the essence of the code is as follows:

var envArray = msg.payload.split(",");

msg.payload = [{
    temperature: parseFloat(envArray[0]),
    humidity: parseFloat(envArray[1]),
    dewpoint: parseFloat(envArray[2]),
    humindex: parseFloat(envArray[3]),
    heatindex: parseFloat(envArray[4])
},
{
    source:"indoor",
    sensor:"USB-TRH420"
}];

return msg;

Finally a influxDB out connector to stores the values in the database. The exec module is triggered every 5 seconds with the inject module.

Because there are two environment sensors, one for the inside of Molly and one for the outside, the code is extended but referencing the USB interface with the serial number of the sensor. The full command becomes:

~/usbtenki/usbtenki-2.1.17/client/usbtenkiget -i a -s E14759