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
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.