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
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.