Thursday, March 14, 2019

Building a Better Barometer

Picture it: We're a 1000 miles from nowhere, it's 3pm, and we're staring at a trail map. Should we push forward and tackle the mountain pass ahead of us, or should we play it safe and take it on the next day? If only we had a way of knowing if the current weather was going to hold. Then it hits me: I can consult my phone's barometer to help predict the weather.

I bust out my phone, Bluetooth keyboard, and start up Termux. I then run tail -24 ~/storage/shared/Tasker/pressure.txt | baro to see the last 24 hour's barometric pressure readings. We huddle around my phone, trying to make sense of this raw data.

There are a number of things wrong with the above scenario. Top among them, the awkwardness of using my baro shell script. Fortunately, it's not hard to make this script far more practical.

First off, I discovered spark, a command line sparkline generator. Sparklines are an Edward Tufte invention that's used to help visualize data. Here's how Tufte defines sparklines:

A sparkline is a small intense, simple, word-sized graphic with typographic resolution. Sparklines mean that graphics are no longer cartoonish special occasions with captions and boxes, but rather sparkline graphics can be everywhere a word or number can be: embedded in a sentence, table, headline, map, spreadsheet, graphic. Data graphics should have the resolution of typography.

Thanks to this shell script you can add Bash terminal to the list of places sparklines can appear. The spark command reads data from stdin and generates a corresponding mini bar graph. Here's an example of me filling a data file with 100 random numbers and then graphing the results.

The other missing piece of the puzzle is an ability to run my baro command with ease. The Termux:Widget app has me covered there. Termux:Widget allows you to add a widget to your home screen that scans the ~/.shortcuts directory. Every file found in that directory shows up as a command in the widget. Pressing on the script name launches the corresponding command. Here's my ~/.shortcuts/show_pressure script:


cd ~/storage/shared/Tasker
tail -$hours pressure.txt | $bin/baro
tail -$hours pressure.txt | $bin/baro -d | $bin/spark
tail -$hours pressure.txt | $bin/baro -s

Combining spark and Termux:Widget means that I can now view my local barometric pressure by clicking over to my widget screen and pressing show_pressure:

Do we push on, or setup camp? Who knows. But at least consulting the barometer is now effortless.

No comments:

Post a Comment


Related Posts with Thumbnails