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
-
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.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.