Access data from a weather station with the Raspberry Pi
Weather Watch
If you have a weather station that allows you to access data via a USB port, you can use your Raspberry Pi to analyze the data and publish the results via a web application.
My new weather station [1] has several sensors for wind, rain, and temperature, as well as a USB cable and evaluation software (Figure 1), albeit a desktop-only Windows application. However, I wanted to record the measured data and, if possible, access it on my cell phone while I was on the move.
Positioning a Windows PC running 24/7 next to my weather station was not an option; instead, I set my sights on the Raspberry Pi. Thus far, I had used it as a tiny media center with an equally tiny speaker, but by using its USB connection, my Pi could read the data output from the weather station. The power requirement is negligible compared with that of a full-size PC, and the Pi is silent. The question then arose: How can I acquire the data via USB if the station only comes with a Windows program?
Pi Configuration
Your Raspberry Pi can be freshly installed with the official recommended Debian Raspbian "wheezy" image from the Download page on the Raspberry Pi website [2]. The tool set necessary to complete this project comprises a C program, Ruby, the Sinatra web application library, a database, and graphing software, all of which are introduced in the "Ingredient" sections of this article. Figure 2 shows how all the components interact and fit together.
Note that you do not have to install a web server. The Ruby script in Listing 4 is the complete web server and web application; Sinatra loads a simple web server for the application when the script is executed (see "Ingredient 3").
Ingredient 1: A Small C Program
A small program written by John Sebastian named te923tool
[3] can read the data output by many weather stations based on HIDEKI. With some minor niggles, the program also works for my TFA Nexus. I only needed to compile the source code on my Raspberry Pi. For this to work, you need the developer tools gcc
, make
, and libusb-dev
.
After unpacking the archive, calling make
should give you the te923con
program. A test with the te923con -h
command not only informed me as to whether the program was running, it also provided detailed help for the program. If all is well, a call without any parameters returns the measured data:
$ sudo ./te923con 1363468817:20.40:50:i:i:i:i:i:i:i:i:-1.90:60:1008.0:i:5:0:14:0.4:0.6:-3.8:115
You will need to use sudo
here because access to the USB port requires root privileges.
Notice the values between the colons. The Help function explains that an "i" stands for values that could not be assigned. Although the first field is not explained, it is Unix time (i.e., the number of seconds since the Unix epoch, or January 1, 1970). Calling
date -d @1363468817 +%c
in the terminal converts this number into a legible date: Sat 16 Mar 2013 22:20:17 CET.
In a cron job, I run te923con
and redirect the output to a text file named weather.csv
, which a Ruby script then uses to populate a database.
Ingredient 2: Ruby
Ruby is the perfect way to process data and feed it to a web server. The numerous libraries that can be installed via Ruby's own package management system, RubyGem, include the ActiveRecord database interface and Sinatra web server. These two libraries later provide the core of the application. Ruby can be installed on the Raspberry Pi from the Debian repositories; however, for a more recent version that is easier to manage, you need the Ruby version management system rbenv
[4].
Because rbenv
is installed from a GitHub.com source, you need to install the git
package up front. Some Ruby libraries are also compiled before the installation on the target system. To be able to install additional libraries later, you will also want to install the zlib1g-dev
, libsqlite3-dev
, libssl-dev
, and libreadline6-dev
libraries as Debian package sources.
For instructions on installing rbenv
, check out the program website; then, you can run
rbenv install 2.0.0-p0
to install the current version of Ruby. On the Raspberry Pi, that can take a while. Before you can use Ruby, you need to call
rbenv global 2.0.0-p0
to define this version as the default for the user. A test with ruby -v
shows that the installation worked.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Red Hat Adds New Deployment Option for Enterprise Linux Platforms
Red Hat has re-imagined enterprise Linux for an AI future with Image Mode.
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.