0% found this document useful (0 votes)
19 views115 pages

LXJ 246

Uploaded by

stefanogozzi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views115 pages

LXJ 246

Uploaded by

stefanogozzi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 115

NETWORK
SECURITY
and SSH
What You
Need to Know

Since 1994: The Original Magazine of the Linux Community OCTOBER 2014 | ISSUE 246 | www.linuxjournal.com

EMBEDDED
HOW-TO:
Sump Pump
Monitor with
+
Interview
Raspberry Pi with the
and Python Creators
of the
“Hello
AN World
Program”
INDEPTH
LOOK Advanced
at the U-Boot Vim Macro
Environment Techniques
Anatomy

Use the BeagleBone Black


TO COMMAND YOUR ELECTRONIC GEAR

LJ246-Oct2014.indd 1 9/19/14 4:06 PM


A CONFERENCE
EXPLORING OPEN SOURCE,
OPEN TECH AND THE OPEN
WEB IN THE ENTERPRISE.

LJ246-Oct2014.indd 2 9/17/14 4:48 PM


$UH\RXWLUHGRIGHDOLQJZLWKSURSULHWDU\VWRUDJH"

zStax ®StorCore =)68QLÀHG6WRUDJH IURP6LOLFRQ


0HFKDQLFVLVWUXO\VRIWZDUHGHÀQHGVWRUDJH
)URPPRGHVWGDWDVWRUDJHQHHGVWRDPXOWLWLHUHGSURGXFWLRQVWRUDJHHQYLURQPHQWWKHzStax StorCore
=)6XQLÀHGVWRUDJHDSSOLDQFHVKDYHWKHULJKWPL[RISHUIRUPDQFHFDSDFLW\DQGUHOLDELOLW\WRÀW\RXUQHHGV

2FWREHU zStax StorCore 64

)HDWXUHG
'RZQORDG

Achieving
Enterprise Class zStax StorCore 104
Storage in the
Cloud with
Software
'HÀQHG6WRUDJH

7DONZLWKDQH[SHUWWRGD\_ZZZVLOLFRQPHFKDQLFVFRP]VWD[

LJ246-Oct2014.indd 3 9/17/14 4:48 PM


CONTENTS OCTOBER 2014
ISSUE 246

EMBEDDED
FEATURES
56 Raspi-Sump
Put a Raspberry Pi
with Raspbian Linux
to work and protect
your basement
against flooding.
Al Audet

68 U-Boot
Environment
Variables
Everything you need
to know about the
U-Boot environment.
Sachin Verma

82 Accessing
the IO Ports
of the
BeagleBone
Black with
Python
With the BeagleBone
Black, you can
command all your
electronic gear with
a few lines of Python.
Samuel Bucquet

Cover Image: © Can Stock Photo Inc. / kgtoh

4 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 4 9/17/14 4:48 PM


COLUMNS
32 Reuven M. Lerner’s
At the Forge
2014 Book Roundup

38 Dave Taylor’s
Work the Shell
Picking Out the Nouns 22

42 Kyle Rankin’s
Hack and / ZĂƐƉŝͲ^ƵŵƉtŝƌŝŶŐŝĂŐƌĂŵ
ZĂƐƉďĞƌƌLJWŝDŽĚĞů ,Ͳ^ZϬϰhůƚƌĂƐŽŶŝĐ^ĞŶƐŽƌ
Return of the Mac

46 Shawn Powers’
The Open-Source Classroom s

This Is Why We Can’t Have Nice


Things: SSH
dƌŝŐƚŽŐƉŝŽϭϳ

ĐŚŽƚŽŐƉŝŽϮϳ ϰϳϬZKŚŵZĞƐŝƐƚŽƌ

110 Doc Searls’ EOF 'ƌŽƵŶĚ


ϭ<KŚŵZĞƐŝƐƚŽƌ

Learn GNU/Linux the Fun Way


56
IN EVERY ISSUE
8 Current_Issue.tar.gz
10 Letters
16 UPFRONT
30 Editors’ Choice
52 New Products
113 Advertisers Index

ON THE COVER
‹5L[^VYR:LJ\YP[`HUK::/·>OH[@V\5LLK[V2UV^W
‹/V^;V!:\TW7\TW4VUP[VY^P[O9HZWILYY`7PHUK7`[OVUW
‹(U0UKLW[O3VVRH[[OL<)VV[,U]PYVUTLU[(UH[VT`W
‹0U[LY]PL^^P[O[OL*YLH[VYZVM[OL¸/LSSV>VYSK7YVNYHT¹W
‹(K]HUJLK=PT4HJYV;LJOUPX\LZW
‹<ZL[OL)LHNSL)VUL)SHJR[V*VTTHUK@V\Y,SLJ[YVUPJ.LHYW
82

LINUX JOURNAL (ISSN 1075-3583) is published monthly by Belltown Media, Inc., 2121 Sage Road, Ste. 395, Houston, TX 77056 USA. Subscription rate is $29.50/year. Subscriptions start with the next issue.

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 5

LJ246-Oct2014.indd 5 9/17/14 4:48 PM


Executive Editor Jill Franklin
[email protected]
Senior Editor Doc Searls
[email protected]
Associate Editor Shawn Powers
[email protected]
Art Director Garrick Antikajian
[email protected]
Products Editor James Gray
[email protected]
Editor Emeritus Don Marti
[email protected]
Technical Editor Michael Baxter
[email protected]
Senior Columnist Reuven Lerner
[email protected]
Security Editor Mick Bauer
[email protected]
Hack Editor Kyle Rankin
[email protected]
Virtual Editor Bill Childers
[email protected]

Contributing Editors
)BRAHIM (ADDAD s 2OBERT ,OVE s :ACK "ROWN s $AVE 0HILLIPS s -ARCO &IORETTI s ,UDOVIC -ARCOTTE
0AUL "ARRY s 0AUL -C+ENNEY s $AVE 4AYLOR s $IRK %LMENDORF s *USTIN 2YAN s !DAM -ONSEN

President Carlie Fairchild


[email protected]

Publisher Mark Irgang


[email protected]

Associate Publisher John Grogan


[email protected]

Director of Digital Experience Katherine Druckman


[email protected]

Accountant Candy Beauchamp


[email protected]

Linux Journal is published by, and is a registered trade name of,


Belltown Media, Inc.
PO Box 980985, Houston, TX 77098 USA

Editorial Advisory Panel


"RAD !BRAM "AILLIO s .ICK "ARONIAN s (ARI "OUKIS s 3TEVE #ASE
+ALYANA +RISHNA #HADALAVADA s "RIAN #ONNER s #ALEB 3 #ULLEN
+EIR $AVIS s -ICHAEL %AGER s .ICK &ALTYS s $ENNIS &RANKLIN &REY
6ICTOR 'REGORIO s 0HILIP *ACOB s *AY +RUIZENGA s $AVID ! ,ANE
3TEVE -ARQUEZ s $AVE -C!LLISTER s #ARSON -C$ONALD s #RAIG /DA
*EFFREY $ 0ARENT s #HARNELL 0UGSLEY s 4HOMAS 1UINLAN s -IKE 2OBERTS
+RISTIN 3HOEMAKER s #HRIS $ 3TARK s 0ATRICK 3WARTZ s *AMES 7ALKER

Advertising
E-MAIL: [email protected]
URL: www.linuxjournal.com/advertising
PHONE: +1 713-344-1956 ext. 2

Subscriptions
E-MAIL: [email protected]
URL: www.linuxjournal.com/subscribe
MAIL: PO Box 980985, Houston, TX 77098 USA

LINUX is a registered trademark of Linus Torvalds.

LJ246-Oct2014.indd 6 9/17/14 4:48 PM


Instant Access to Premium
Online Drupal Training
Instant access to hundreds of hours of Drupal
training with new videos added every week!

Learn from industry experts with real world


H[SHULHQFHEXLOGLQJKLJKSURȴOHVLWHV

Learn on the go wherever you are with apps


for iOS, Android & Roku

We also offer group accounts. Give your


whole team access at a discounted rate!

Learn about our latest video releases and


RIIHUVȴUVWE\IROORZLQJXVRQ)DFHERRNDQG
7ZLWWHU #GUXSDOL]HPH 

Go to http://drupalize.me and
get Drupalized today!

LJ246-Oct2014.indd 7 9/17/14 4:48 PM


Current_Issue.tar.gz

Linux Inside! SHAWN POWERS

Linux Inside!
L
inux inside, Linux inside, every for programmers and neophytes like
single one of us has Linux myself. Now we get a glimpse at some
inside! (Sung to the tune of the books he uses for learning
of “Devil Inside” by INXS—you’re himself. Whether you want advice on
welcome for the ear worm, I can’t get language books, database books or
it out of my head either.) even some information on freelancing,
In the world of embedded systems, Reuven shares his stash. If you’re
systems-on-chip and single-purpose looking for your next book to read
hardware solutions, it’s easier to list (after this issue of Linux Journal, of
the products that don’t have Linux as course), check out his column.
their operating system! This month, we Dave Taylor begins a new adventure,
focus on putting Linux into tiny places, this time attempting to parse the
and that means everything from the written word and grammar with
tiniest “Android Wear” watch to the scripts. It’s always fascinating to see
ubiquitous Raspberry Pi. As Linux users, tasks that are simple for humans
we’ve been sneaking open source into attempted by programs and logic.
server rooms for decades. Now we get Dave’s column is more than just
to sneak it in everywhere! instructive, it will force you to think as
This issue starts with Reuven M. well! Speaking of thinking, the title of
Lerner discussing the books he’s Kyle Rankin’s column this month will
embedded into his bookshelf this year. make you think hard. “Return of the
Month after month, Reuven gives us Mac” seems like the exact opposite
incredible tips, techniques and training of what Kyle would write about. And,
of course, he doesn’t talk about an
VIDEO: Apple product. I won’t give it away,
V

Shawn Powers runs but don’t worry, Kyle hasn’t given up


through the latest issue.
the command line for the GUI world

8 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 8 9/17/14 4:48 PM


CURRENT_ISSUE.TAR.GZ

of Apple—in fact, quite the opposite. and teaches how to customize the
I put on my grey hat this month and information passed on at boot.
talk a little bit about SSH. “Hacking” is Finally, Samuel Bucquet gives a crash
a word that is used to describe far too course in accessing the BeagleBone
many things, most of which I think are Black’s I/O ports via Python. Although
more accurately described as, “Using the Raspberry Pi and BeagleBone
Things Like They Were Made To Be Black are both excellent platforms for
Used”, but that’s not as catchy for a embedded projects, the BBB’s sheer
movie title. Firewalls are important number of I/O options make it incredible
security tools for any network, but for projects with a large number of
it’s important to realize that firewalls sensor needs. With Samuel’s help, you
can’t be your only defense against can access those ports with the friendly
access. This month I show you why. Do and familiar Python language.
I “hack” the firewall? I don’t think so, The Embedded issue of Linux
but for someone unfamiliar with SSH Journal always makes me want to
tunneling, it sure looks like it. build something. Now that BirdCam
Al Audet shows how to embed Linux is off-line (the battery in my old
into a hole in the ground this month. Android phone blew up—it was ugly),
More specifically, he explains how he maybe it’s time to start over from
uses a Raspberry Pi device to monitor scratch. I’m sure there are some great
the sump hole in his basement to weatherproof IP cameras out there I
avoid flooding. Sump pumps are could use to get better shots of the
amazing devices—until they’re not. winter birds. Either way, this is a great
Al shares not only his method, but issue, and we had a great time putting
also his scripts for controlling a sensor together for you. Whether you want
that warns him if the water level rises tech tips, programming ideas or just
too much. It’s the perfect example of my silly insight on the best new apps
solving difficult problems with Linux. for your phone, the October issue of
Sachin Verma goes even deeper (pun Linux Journal aims to please! Q
intended) and shows how to deal
with the bootloader on embedded Shawn Powers is the Associate Editor for Linux Journal .
Linux systems. U-Boot is commonly He’s also the Gadget Guy for LinuxJournal.com, and he has
used in such environments, and along an interesting collection of vintage Garfield coffee mugs.
with booting the kernel, you can Don’t let his silly hairdo fool you, he’s a pretty ordinary guy
pass environment variables as well. and can be reached via e-mail at [email protected].
Sachin walks through the boot process Or, swing by the #linuxjournal IRC channel on Freenode.net.

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 9

LJ246-Oct2014.indd 9 9/17/14 4:48 PM


letters
version, and it looks best (I think) on
a large format color tablet. If you
look back, the older PDF versions
were even more difficult to read on
a computer screen, as the layout
mirrored the paper version exactly.

I know you said you don’t like the


EPUB version, but I’m not sure
whether you’ve tried reading the
EPUB on a computer screen or only
on eReaders. Using something like
Readium (http://www.readium.org),
you can change the font size and read
Two-Column Format the text in a single column. Apart
I love being able to read Linux Journal from that, I’m not sure what else to
on my laptop, but I can’t stand the suggest. I’m not sure what you dislike
two-column format that is used in the about the EPUB version, so I don’t
PDF version. I need to magnify the text know how to help there if Readium
due to poor eyesight, and the two- doesn’t work for you.—Shawn Powers
column format forces me to scroll down
and then up constantly in order to read Subscription Question
all the text on a page. A one-column I carry two tablets, one iOS and the
format for the PDF would make for other Android. If I subscribe on my
much smoother reading and navigation. iPad to Linux Journal, can I also read
it on my Nexus 7?
Please don’t suggest I read the EPUB —Greg
version. EPUB is a terrible format.
—Scott Randby If you subscribe directly through Linux
Journal, we will send you monthly
It’s tough to come up with a perfect notices with download links for .epub,
format. The PDF version is designed .pdf, .mobi and browser versions of
to look like the traditional magazine the magazine. You also will get access

10 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 10 9/17/14 4:48 PM


[ LETTERS ]

through our Android or iOS apps. Leap Years in Bash—or Anywhere


Regarding the detection of leap years
We want our subscribers to be able in Dave Taylor’s recent articles, there
to access the issues in any format is a very simple way to determine
that is available. whether a year is a leap year: if it’s
divisible by 4 and not 100. So a simple
If you order through Google Play or modulus function will suffice:
iTunes, you will receive only those
versions. Both have subscription YEAR=$( date "+%Y" )

options, but they are pretty much a if [ $(( ${YEAR} % 4 )) -eq 0 ] && [ $(( ${YEAR} % 100 )) -ne 0 ]

closed environment. then

echo 'Leap'

We want you to be able to access else

the magazine any way you choose. echo 'No Leap';

If you subscribed through Google fi

Play or iTunes, please send me your


transaction ID, e-mail address and For the real geek, during a century, an
full mailing address (we use that to integer binary number can be ANDed
encrypt the files) to [email protected]. with 0x03, and the result is represented
Once I have that, I can add you to our by the modulus of 4. If 0, the leap year.
subscription database as well. —Jacques Amar

The best deal I have for Linux Journal Dave Taylor replies: There are
directly is https://www.pubservice.com/ lots of ways to calculate it, for
Subnew2page.aspx?PC=LJ&PK=M48RENN. sure. I like my latest: just type
date -d 12/31/YEAR +%j , and
I hope that helps. Sorry that see if it’s 365 or 366.
it’s more complicated than we
would like, but once iTunes and Counting Days
Android closed their subscription Dave Taylor’s Work the Shell column is
environments, it became impossible one of my favorites in Linux Journal.
to extract those orders and However, while reading the August
automatically add them to our database 2014 issue, I thought “don’t re-invent
so readers can receive every format we the wheel.” In astronomy, getting the
have.—Mark Irgang, Publisher time interval (in days and fractions

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 11

LJ246-Oct2014.indd 11 9/17/14 4:48 PM


[ LETTERS ]

thereof) between any dates is a daily a bit anxious with such complicated
bread and butter issue. The solution formulae in the mix.
is the Julian Date, a consecutive
count of days from centuries ago into Thanks for pointing that out. Good stuff!
the future. It is a relatively simple
algorithm, although not intuitive. See, Norbert responds: Thanks for
for example, http://aa.usno.navy.mil/ responding to my earlier e-mail. Those
faq/docs/JD_Formula.php. constants are determined to “make
it work”, accounting for the fact that
Yes, the algorithm is originally different months have a different num-
coded up in FORTRAN (what else ber of days (even going over centuries)
was there in the science world and so on. It is hard to understand the
some decades ago), and we still algorithm; however, the result is a fast,
use it. A conversion to a shell accurate algorithm. Testing was done
script or any other programming on sample data, and after verification,
language should be easy. no further tests are needed as part of
—Norbert Zacharias the algorithm. Of course, one needs to
be very careful when cutting/pasting
Dave Taylor responds: Holy cow, lines in order not to screw it up.
that’s awesome stuff, Norbert! I
haven’t dabbled in FORTRAN since the PS. We still code in FORTRAN partly
job I had while I was an undergrad because we inherited a large body of
at UCSD back in the early 1980s. As code in our area of research and partly
it happens, I really enjoyed FORTRAN because the code is really easy to write
and enjoyed reading the code too. and efficient—it pays off when dealing
with billions of star positions. It even
How that formula works, however, is a still can be done on a modern laptop!
bit puzzling to me, as there are some
rather mysterious constants that don’t Suggestion
seem like they should work. Still, it’d I am working for a telecom vendor
be easy enough to recode as a shell on OSS products. Lately, I’ve been
script—in fact, the FORTRAN code working on NFV-related meetings
is almost workable as is with just a and workgroups. There is a lot
few tweaks. My only comment: the going with NFV all around telco
lack of error checking makes me get operators, and almost all will run

12 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 12 9/17/14 4:48 PM


[ LETTERS ]

PHOTO OF THE MONTH


I’m writing to share this magnificent Linux laptop, which I believe is one
OF THE SMALLEST AROUND )TS A :IPIT : AND )M A BIG FAN OF IT 4HANKS TO
Johannes from Wejp.k.vu, I’m able to host my Web site on this beauty.
—Matias

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 13

LJ246-Oct2014.indd 13 9/17/14 4:49 PM


[ LETTERS ]

on Linux/KVM/OpenStack. There is and will be a


lot of work done and money spent on this issue.
Operators are pushing vendors for open source.
At Your Service
There is OpenDaylight as well for SDN. The SUBSCRIPTIONS: Linux Journal is available
in a variety of digital formats, including PDF,
vendors are big ones, such as Ericsson, Huawei, .epub, .mobi and an on-line digital edition,
as well as apps for iOS and Android devices.
ALU, Oracle, Cisco, Nokia, Microsoft and HP. Renewing your subscription, changing your
e-mail address for issue delivery, paying your
Some other vendors are AT&T, Orange and TIM. invoice, viewing your account details or other

Those are the biggest players around. subscription inquiries can be done instantly
on-line: http://www.linuxjournal.com/subs.
E-mail us at [email protected] or reach
us via postal mail at Linux Journal, PO Box
You are the Linux magazine, yet I see almost 980985, Houston, TX 77098 USA. Please
remember to include your complete name
nothing on these issues. This disappoints me. and address when contacting us.

Personally, I would like to see not only NASA’s ACCESSING THE DIGITAL ARCHIVE:

open-source tools, but also such big enterprise Your monthly download notifications
will have links to the various formats
issues on open source and Linux. Linux is a serious and to the digital archive. To access the
digital archive at any time, log in at
thing that runs the Internet and many serious http://www.linuxjournal.com/digital.

applications on the enterprise level. I would like to LETTERS TO THE EDITOR: We welcome your
letters and encourage you to submit them
see these improvements in your magazine. at http://www.linuxjournal.com/contact or

—Umit Kaan Sonal mail them to Linux Journal, PO Box 980985,


Houston, TX 77098 USA. Letters may be
edited for space and clarity.

We look for content that interests our users, WRITING FOR US: We always are looking
for contributed articles, tutorials and
along with new technology we think deserves to real-world stories for the magazine.
An author’s guide, a list of topics and
be noted. Getting feedback like yours is the best due dates can be found on-line:
http://www.linuxjournal.com/author.
way for us to know what readers want, so we’ll
keep our eyes open. Thanks!—Shawn Powers FREE e-NEWSLETTERS: Linux Journal
editors publish newsletters on both
a weekly and monthly basis. Receive
late-breaking news, technical tips and
tricks, an inside look at upcoming issues
and links to in-depth stories featured on
http://www.linuxjournal.com. Subscribe
WRITE LJ A LETTER for free today: http://www.linuxjournal.com/

We love hearing from our readers. Please enewsletters.

send us your comments and feedback via ADVERTISING: Linux Journal is a great
resource for readers and advertisers alike.
http://www.linuxjournal.com/contact. Request a media kit, view our current
editorial calendar and advertising due dates,
or learn more about other advertising
and marketing opportunities by visiting
PHOTO OF THE MONTH us on-line: http://ww.linuxjournal.com/
advertising. Contact us directly for further
Remember, send your Linux-related photos to information: [email protected] or
[email protected]! +1 713-344-1956 ext. 2.

14 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 14 9/17/14 4:49 PM


NEW!
Linux Journal
eBook Series
GEEK GUIDES FREE
Down
loa
Slow Down to Speed Up: NOW d
!
Continuous Quality Assurance in a DevOps Environment
By Bill Childers
DevOps is one of the newest and largest movements in Information
Technology in the past few years. The name DevOps is a portmanteau
of “Development” and “Operations” and is meant to denote a fusion of
these two functions in a company. Whether or not your business actually
does combine the two functions, the lessons and tools learned from the
DevOps movement and attitude can be applied throughout the entire
Information Technology space. This eBook focuses on one of the key
attributes of the DevOps movement: Quality Assurance. At any point,
you should be able to release your product, code or configuration—so
long as you continue keeping your deliverables in a deployable state. This is done by “slowing
down” to include a Quality Assurance step at each point in your workflow. The sooner you catch
an error or trouble condition and fix it, the faster you can get back on track. This will lower the
amount of rework required and keep your team’s momentum going in a forward direction,
enabling your group to move on to new projects and challenges.

Build a Private Cloud for Less Than $10,000!


By Mike Diehl
This eBook presents a compelling argument as to why you should
consider re-architecting your enterprise toward a private cloud. It
outlines some of the design considerations that you need to be
aware of before implementing your own private cloud, and it
describes using the DevCloud installer in order to install OpenStack
on an Ubuntu 14 server. Finally, this eBook will familiarize you with
the features and day-to-day operations of an OpenStack-based
private cloud architecture, all for less than $10K!

DOWNLOAD NOW AT: http://linuxjournal.com/geekguides

LJ246-Oct2014.indd 15 9/17/14 4:49 PM


UPFRONT NEWS + FUN

diff -u
WHAT’S NEW IN KERNEL DEVELOPMENT
Kernel configuration has become driver name which arch it’s for (lately
more and more complex through the the majority are for ARM), but that isn’t
years with the proliferation of new really a great way to handle things.”
drivers, new hardware and specific There was some resistance to the
behaviors that might be needed for idea. Greg Kroah-Hartman, in
particular uses. It has reached about particular, suggested that there were
3,000 config options, and that existing alternatives. For example,
number will only increase. he said users simply could compile
Jean Delvare recently pointed out everything as modules. Then, they’d be
that a lot of those config options were loaded into the system only as needed.
relevant only to particular hardware, But, neither Jean nor Josh liked that
and yet the config system presented suggestion. Jean said that in the old
them to users who didn’t have that days it was fine to build everything
hardware. This seemed like a bug to as a module, but nowadays there
him, and he suggested that maintainers were just too many modules, and that
begin requiring proper hardware “Saying ’m’ to everything increases
dependencies for all config options. build times beyond reason. You also
He acknowledged this would be hit build failures you shouldn’t have
a big task—especially for existing to care about, depmod takes forever,
drivers. But creating the requirement updates are slow as hell. This is the
for new drivers would at least get the problem I am trying to solve.”
ball rolling, and older drivers could Greg didn’t see how build times
follow along more gradually. could be a problem. Building the kernel
Josh Boyer agreed with all this. on his laptop, he said, took about
From his work on the Fedora project, 20 minutes—with all 3,000 modules
he had to deal with the config system compiled in. If that wasn’t good
intensively, and he found it difficult. He enough, he suggested upgrading the
said, “I’ve gotten to the point where hardware to get a faster build time.
I can somewhat guess based on the But, Jean said this wasn’t a practical

16 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 16 9/17/14 4:49 PM


[ UPFRONT ]

solution for some cases. He said, “We the discussion, but it does seem
have 34 kernel flavors for openSUSE as though there’s a vast mountain
13.1, for example. And, every commit of configuration options that are
potentially triggers a rebuild of the becoming more and more difficult to
whole set, to catch regressions as fast deal with. Eventually, I think some
as possible. So every module we build, form of clean hardware dependencies
for no good reason, gets built a hundred will end up being implemented, along
times each day.” He added that it would the lines of Jean’s suggestion.
cost a lot of money to upgrade the With all the new devices coming
hardware underneath that build system. out on the market, there’s a big
Greg said he understood the issue, desire to get Linux running properly
but that fixing the config system was on all of them. Things like Intel’s
just a hard problem to solve. It boiled Quark system use only a few MB of
down to enforcing better habits on RAM and have other tight hardware
everyone producing patches. He said, requirements. Shrinking Linux down to
“If you see new drivers show up that you the right size poses a challenge.
don’t know where they work on, ask the Andi Kleen recently pointed out,
developers and make up patches.” He “One problem on these small systems is
added, “Perhaps a few developers could the size of the network stack. Currently
be auditing the new Kconfig items of enabling IPv4 costs about 400k.” He
every kernel around -rc3 time frame to wanted to give users the option to
ensure that they don’t do stuff like this.” prune down the Linux networking
Jean said that -rc3 would be too stack to only the bare essentials and
late, because “all kernel developers get it down to 100K per application—
and distributions have already moved competitive with Adam Dunkel’s LwIP
to the new kernel so they have already (Lightweight IP) project.
answered the n/m/y question for all Andi posted some patches to
new entries.” He added, “It’s the create three available options for the
reviewer’s job to refuse new drivers networking stack: a full system with
with bad Kconfig descriptions in the all current features, a partial system
first place. This must happen as early that supported regular users but
as possible in the chain.” not servers or a minimal networking
No clear decision came out of system for the special userland on

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 17

LJ246-Oct2014.indd 17 9/17/14 4:49 PM


[ UPFRONT ]

deeply embedded systems. The minimal system, he


said, would “remove rtnetlink (ioctl only), remove They Said It
ethtool, raw sockets”.
This seemed extreme to Richard Weinberger, Do not hire a
who said that on such a minimal system, even the ps man who does
your work for
command wouldn’t work. Tom Zanussi on the other
money, but him
hand, said that the microYocto Linux distribution ran
who does it for
okay with Andi’s patches and had decent workarounds
love of it.
to keep ps working properly. But, he added that —Henry David
microYocto was “very much a work-in-progress with a Thoreau
lot of rough edges, but it is a fully functional system
on real hardware”. When in doubt,
Alexei Starovoitov felt that trying to support such tell the truth.
a minimal system would only create config options —Mark Twain
that led to a hacky, work-in-progress, rough-edged Experience is a
system. He said that if the goal was to create a half- good teacher,
functional system that was just very very small, the but she sends
same thing could be accomplished with linker hacks. in terrific bills.
Simply “compile kernel as-is. Most functions have a —Minna Thomas
stub for mcount() already. Use it to track whether the Antrim
kernel function was called or not. Collect this data
Just the
in userspace (as perf already does), add a few more
knowledge that
functions that had a ’notrace’ attribute on them, and
a good book
feed this into a special linker that unpacks existing is awaiting one
vmlinux, throws away cold functions, relocates the rest at the end of
and here you have tiny vmlinux without recompilation.” a long day
But, Andi pointed out that for networking code, this makes that
wouldn’t really work. He objected, “How would you day happier.
know you exercised all the corner cases in the TCP stack? —Kathleen
And you wouldn’t want a remotely exploitable system Norris
because some important error handler is missing.”
Always be a
The discussion ended inconclusively. But, it does little kinder than
seem as though real patches, and not linker hacks, will necessary.
be used to support all new hardware—even the tiny —James M.
hardware that’s been coming out lately. —ZACK BROWN Barrie

18 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 18 9/17/14 4:49 PM


[ UPFRONT ]

EdgeRouter Lite
In the
September
2014 issue, I
mentioned my
new router,
and I got a
lot of e-mail
messages
asking about
how well it
works. I can say without hesitation Q Advanced configuration possible.
it’s the nicest router I’ve ever owned.
And, it was less than $100! Q Price!
The EdgeRouter Lite is a business-
class router based on the open-source I’ll admit, setting up the EdgeRouter
Vyatta system. It has been forked, Lite was a pain in the rear end. The
and as it matures, it will become less basics can be done via the Web
and less like the original Vyatta code, INTERFACE BUT IF YOU WANT ANY 1/3 FOR
but for the present, it works much your connection, it will be a learning
the same. I purchased the EdgeRouter experience trying to figure out the
because my old ATOM-based ClearOS Vyatta command and code (and
router/firewall couldn’t keep up with concepts!) for doing so. It took me
the traffic from my home network. My three or four hours to get the setup
favorite features include: that I’m happy with, and since then, I
haven’t touched it—at all. It works so
Q Three GigE ports, each fast, I never notice it, and it’s been rock-
routable separately. solid since day one. If you’re looking
for an advanced router, but don’t want
Q A claimed one million packets to break the bank, the EdgeRouter Lite
per second throughput. might be exactly what you’re need. Be
warned, however, its setup is not for the
Q Wire-speed routing. faint of heart.—SHAWN POWERS

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 19

LJ246-Oct2014.indd 19 9/17/14 4:49 PM


[ UPFRONT ]

The Cow Says, Have Fun!

Sometimes, when the clock hits Web site showing off the best ones.
3:00am, and you’ve been in the
server room since 9 o’clock the Q cowsay: install this program, and
previous day, you start to get a little the cow will say whatever you ask
batty. That’s the only explanation it to. (Bonus: there’s a GUI version
I have for programs like cowsay in of cowsay too, called xcowsay!)
Linux. Still, I’m glad they’re there,
because life wouldn’t be nearly as Q sl: this is a program I like to install,
fun without them. Here’s a quick list because it makes fun of you when
of silly Linux programs off the top of you accidentally type sl instead
my head. I’d love to hear about more, of ls —a steam locomotive chugs
so please, send me your crazy Linux across the screen. (It also shows up
Easter eggs, and I’ll follow up on the if you press caps lock, and type LS !)

20 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 20 9/17/14 4:49 PM


[ UPFRONT ]

Q cmatrix: blue pill or red pill, marshmallows, because you can


this little program will suck you watch the entire Star Wars movie
in to the Matrix either way! in a terminal window.
(Leaving this matrix just requires
a Ctrl-C, thankfully.) Most of these silly things have
been around for years and years, but
Q libaa-bin: install this package, every so often, I learn of one I never
and then type aafire to stoke knew about before. Send me your
up the ASCII flame. Grab your favorites, and I’ll be sure you get
digital marshmallows! credit for slacking off at work—er,
I mean for discovering awesomeness!
Q Star Wars: open a terminal and type E-mail [email protected]
telnet towel.blinkenlights.nl, (put something like “FUN” in the
and grab some popcorn. Or subject line so I know what it’s
maybe roast some of those digital about). —SHAWN POWERS

LJ246-Oct2014.indd 21 9/17/14 4:49 PM


[ UPFRONT ]

What’s Happening above


Your Head?
In the past, I’ve covered various A package should be available in most
astronomy packages that help Linux distributions. In Debian-based
you explore the universe of deep ones, you can install Gpredict with:
space. But, space starts a lot closer
to home. It actually begins a few sudo apt-get install gpredict
hundred miles above your head.
There are lots of things in orbit right This is usually a version or two
above you. In this article, I look at behind the latest, so if you want to
one of the tools available to help have the newest options, you always
you track the satellites that are can download and build from source.
whizzing around the Earth: Gpredict Once you have it installed, you
(http://gpredict.oz9aec.net/index.php). can start it with the gpredict

Figure 1. When Gpredict first starts, you get an initial module called Amateur.

22 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 22 9/17/14 4:49 PM


[ UPFRONT ]

Figure 2. Some views have drop-down lists of options.

command. When it opens, you should which contains a map view, a polar
see the main window, with a sample view and a single satellite view. For
layout given by the module named some of these views, you may notice
“Amateur” (Figure 1). a small down-arrow in one of the
In the rest of this article, I take a top corners. Clicking this icon gives
look at all the various possible layouts you an appropriate drop-down list
and show just how much information of options. For example, clicking the
is available to you. down-arrow in the map view gives you
The core concept in Gpredict is a list of items, such as detaching the
that of the module. You can think module or configuring it (Figure 2).
of modules as documents in a word The map view offers a map of the
processor. They are containers you can Earth, with a series of satellites and
use to hold a number of other layout their footprints on the Earth. When
objects that display satellite information you hover over one of the satellites,
in a number of different ways. you will see an information box
When you first start Gpredict, you with the satellite’s detailed location.
get the default Amateur module, The single satellite view provides

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 23

LJ246-Oct2014.indd 23 9/17/14 4:49 PM


[ UPFRONT ]

Figure 3. You can set the configuration details for the map view here.

even more detail about one specific clicking the down-arrow and selecting
satellite. You can select which satellite configuration (Figure 3).
is being displayed by clicking on the You can add another ground
down-arrow in the view. The polar station by clicking the plus sign.
view provides an overhead look, This will pop up a details window
located at the ground station. where you can enter a name and the
In the Amateur module, you get location data for your ground station
one ground station called “sample”. (Figure 4). For the location, you can
You can add more ground stations by enter the latitude and longitude

24 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 24 9/17/14 4:49 PM


[ UPFRONT ]

Figure 4. You can add a ground station with details here.

manually, or if you live in a major module. It might make the display a tad
city, you can select it from a global crowded, but it still should work.
list of locations. I should take a step back at this
One other item you will notice when point and describe some other
you have the configuration window configuration options available.
open is that you can select which The first option to look at is the
satellites are displayed. This list is rather menu item EditAUpdate TLE. This
large, but there is nothing stopping option lets you update the Keplerian
you from adding all of them to your elements for the satellites. You can

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 25

LJ246-Oct2014.indd 25 9/17/14 4:49 PM


[ UPFRONT ]

Figure 5. The preferences window lets you change all sorts of options.

update them either from the network data, visit http://www.amsat.org/


or from a local file. The default amsat-new/tools/keps_tutorial.php.
configuration is set up to remind All the other configuration options
you when the TLE data is likely out are available under the menu
of date. You then can go ahead and item EditAPreferences (Figure 5).
update this data. For an update over Here, you can change options like
the network, the default configuration the number formats used or the
is to download NORAD data from geographical coordinates. There also
http://www.celestrak.com. For is a tab for ground stations, where
a tutorial on the format for TLE you can edit or add ground stations.

26 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 26 9/17/14 4:49 PM


[ UPFRONT ]

Figure 6. You can control radios and antenna rotators that are defined in Gpredict.

The modules section lets you change select the custom layout, you define
configuration options used in the display what it will look like by entering the
of the Gpredict modules. You can change layout code. See the user manual for
things like the refresh rate for the displays details on how to define a code to
or what map to use as the background create the layout you want.
for the map view. You also can select Gpredict also has the ability to
what type of layout you want for a control radios and rotators. The key to
particular module. When you select a this is the hamlib library. By using this
new layout, you will see a preview of library, Gpredict can handle Doppler
what it will look like in the preferences tuning of radios and tracking of
window. There are nine different antenna rotators. When you want to
pre-generated layouts available, or you connect hardware to your computer,
can create a custom layout. When you you should verify that hamlib can talk

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 27

LJ246-Oct2014.indd 27 9/17/14 4:49 PM


[ UPFRONT ]

to it successfully. Once you have made pulling up the radio control window,
sure everything is working correctly, which you access by clicking the down-
you can set up Gpredict to talk to arrow in the map view and selecting
your hardware. This is handled in the Radio Control (Figure 6). You can see
interfaces section of the preferences the details of the downlink and uplink,
window. There are two tabs, one for as well as information about targets.
radios and one for rotators. Since Now that you know how to get
hamlib communicates over network satellite information for what is moving
protocols, the radio or rotator doesn’t above your head, you should be able
even need to be connected to the same to go outside and do some actual
machine. You can define one of these observations and see all of the man-
pieces of hardware with a hostname, made objects travelling around. It
a port and the communication can be inspiring to see how much we
details. Once you have the hardware already do in space, and how much
configured, you can control it by more we could be doing.—JOEY BERNARD

LINUX JOURNAL
now available
for the iPad and
iPhone at the
App Store.

linuxjournal.com/ios
For more information about advertising opportunities within Linux Journal iPhone, iPad and
Android apps, contact John Grogan at +1-713-344-1956 x2 or [email protected].

LJ246-Oct2014.indd 28 9/17/14 4:49 PM


[ UPFRONT ]

Non-Linux FOSS:
Remember Burning ISOs?
I was chatting with a Windows-
using friend recently, and he
wanted to try Linux on one of
his older computers. I always like
those sorts of conversations, and
so I kept chatting, walking him
through setting up Unetbootin
to create a USB installer and so
on and so on. Unfortunately,
he wasn’t able to get the USB
drive to boot. Since we were
half a country apart, I couldn’t
troubleshoot locally, so we moved
on to burning a CD/DVD.
My first instinct was to have
him download the incredible
InfraRecorder. Unfortunately,
there seems to be a malware- Image courtesy of http://www.visualpharm.com.
infected version of InfraRecorder
going around, and of course, about the malware masquerading as
that’s the download link he found. open-source software. Remember to
So, be sure to send folks directly send people directly to the Web site
to http://infrarecorder.org rather than having them “google”
to download it. for it. The open-source InfraRecorder
Alternatively, I’m a big fan of the is at http://infrarecorder.org,
free-but-not-free program ImgBurn and the freeware ImgBurn is at
as well. It’s not open source, but it http://www.imgburn.com. Once
is freeware, and it has a very simple they switch to Linux, everything
interface. Either way you go, be sure they need will be an apt-get or
to warn potential Linux converts yum away! —SHAWN POWERS

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 29

LJ246-Oct2014.indd 29 9/17/14 4:49 PM


[ EDITORS' CHOICE ]

Android Candy: EDITORS’


CHOICE
Goodbye RDP, ★
Hello Chrome
Remote Desktop!
Controlling a remote computer is GUI Linux machine, it’s always a pain
something you’re all familiar with. in the rear.
Whether that means RDP to your The folks at Google are trying to
corporate Windows Server (we make it a little easier with Chrome
don’t judge), Apple Remote Desktop Remote Desktop. It’s a combination
(which is really VNC) to your OS X of Chrome browser app and
machine or VNC/X11/etc. into your native binary that runs on your

30 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 30 9/17/14 4:49 PM


client machines. Once the dæmon barging in on your work session.
is installed, you can access the The dæmon is available for Windows
computer remotely from anywhere, and OS X, and recently they released
including a really cool Android a beta version of the dæmon for
app. The combination of available Ubuntu/Debian Linux! Thanks
platforms is pretty impressive too: to its wonderful cross-platform
Server platform (what can approach and smooth functionality
be controlled): in our testing, Chrome Remote
Desktop earns this month’s Editors’
Q Windows Choice award! Check it out today
at https://chrome.google.com/
Q OS X remotedesktop.
—SHAWN POWERS
Q Linux (Beta, Ubuntu/Debian for now)

Client platforms (what can be used


to control the systems above): LINUX JOURNAL
Q Windows
on your
Android device
Q OS X
Download the
app now in
Q Linux the Android
Marketplace
Q Android

Q iOS (coming soon, supposedly)

Permissions on the dæmon can


be customized for controlling your
own computer remotely (no local
permission required) or for allowing
other people in to assist you. The
latter is preferred to avoid anyone www.linuxjournal.com/android

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 31

LJ246-Oct2014.indd 31 9/17/14 4:49 PM


COLUMNS
AT THE FORGE

2014 Book REUVEN M.


LERNER

Roundup
Reuven gives his annual rundown of great books on
programming languages, databases and analytics,
freelancing and more.

As I write these words, the end an elegant language that is both


of summer is approaching, and with powerful and easy to learn. I have
it, so is the time for my annual book been teaching a growing number of
roundup. As in past years, in this Python courses during the past few
article, I describe books that were new years to a variety of audiences—
to me during the past 12 months, aspiring Web developers, companies
which means that I might well mention interested in moving their automation
some new ones or ignore others that and testing systems into an open-
simply didn’t come to my attention. source high-level language, and also
My interests (professionally, and for people interested in learning basic
this column) generally are relevant to programming techniques and ideas.
people involved in Web development The best-known book about Python,
using open-source technologies, but Programming Python by veteran
I admit to veering into other subjects instructor Mark Lutz, recently was
occasionally. And as I have done for the released in its 4th edition by O’Reilly
last few years of this annual roundup, (ISBN 9780596158101). The book has
I have expanded my list of books also been expanded and improved in many
to include blogs, podcasts and other ways, most importantly with additional
resources that may be of interest to information about Python 3.x. Truth
others in the Open Source community. be told, I have yet to encounter a
company that is using Python 3; all of
Programming Languages my consulting and training clients still
Python continues to grow in use Python 2.7. However, there’s no
popularity and for good reason—it’s doubt that Python 3.x is the future,

32 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 32 9/17/14 4:49 PM


COLUMNS
AT THE FORGE

and Lutz has done us all a good service increase performance: benchmarking
by providing such information. and profiling (to understand where the
This is not a book about learning problem is); NumPy’s arrays (which are
Python, but rather it’s meant to be a faster, if more limited, than Python’s
reference and in-depth description of built-in lists); Cython (which translates
how the language works. And at that, Python code into C); and finally,
it succeeds. At the same time, I feel like multiprocessing. The book is relatively
the book is far too large (at more than short (at 108 pages), but it does provide
1,600 pages), 400 pages of which are some of the most common techniques
spent describing TkInter, a GUI toolkit for increasing program speed. At the
that is included with Python, is easy same time, I think that some more
to use and is cross-platform. But, it’s basic techniques, such as not using +=
also extremely ugly and not particularly to iteratively build strings, would have
popular, in my experience. If you’re a added something to the book.
Python programmer though, you’ll likely The hottest language continues to
want to have this book on your shelf. be JavaScript, if for no other reason
When I’m teaching Python than the very large number of people
programming classes, my students who have access to browsers, be it
often ask me how they can boost on their computers or their mobile
the performance of their code. devices. JavaScript’s huge community
True, I think that Python, like many has been pushing forward with a
other high-level languages, stresses variety of techniques and libraries that
programmer efficiency over language make development easier. Moreover,
efficiency. And of course, we know JavaScript is now popular beyond the
that worrying about performance too browser, in such places as node.js,
early in a project is asking for trouble. a server-side framework that uses
At the same time, once our program is asynchronous JavaScript.
working, we definitely want to increase It is this first topic that Async
its speed. Python High-Performance JavaScript, written by Trevor Burnham
Programming, written by Gabriele and published by the Pragmatic
Lanaro and published by Packt Programmers (ISBN 978-1-937785-27-7),
Press (ISBN 978-1-78328-845-8), addresses. Part of the difficulty that
aims to solve some of these issues. people have when working with
The book concentrates on a small JavaScript is its asynchronous nature.
number of areas that can be used to You often set up a function to be

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 33

LJ246-Oct2014.indd 33 9/17/14 4:49 PM


COLUMNS
AT THE FORGE

executed later on, when a particular soon to be published in paper form


even happens, and it’s frequently tough by No Starch Press), reviews the basics
to remember just how that worked. This of JavaScript as a language, ignoring
book introduces techniques that will the Web-related aspects until halfway
help you build asynchronous programs through the book. So you learn
that are easier to understand and debug. about JavaScript objects, higher-order
Functional programming is a functions and even regular expressions,
technique that was pushed aside with clear and interesting examples.
for many years by object-oriented HTML5 is not quite a language, but
programming, but it’s making a it certainly represents a combination
comeback. Even if you’re not using of APIs and tools—most specifically,
a purely functional programming HTML, JavaScript and CSS—that are
language, functional techniques are the standard way to create modern
increasingly important and useful. Web applications. It’s quite amazing to
Functional JavaScript, written by see the breadth and depth of HTML5,
Michael Fogus and published by O’Reilly as well as the applications that people
(ISBN 9781449360726), introduces a are creating with it. If you’re reading
wide variety of functional ideas and this column, you’re probably not the
techniques. I’d say that this book right audience for Head First HTML5
is good for two types of audiences: Programming, which aims to teach
those who already know functional the basics of HTML, JavaScript and
programming and want to see how CSS to people who have little or no
these ideas can be applied in JavaScript, familiarity with those technologies.
as well as the opposite, people who But if you know of someone who wants
know JavaScript and are interested in to understand how these things work,
learning functional programming. it’s worth recommending it.
If you are new to JavaScript, or if Another non-language is Git, which
you have been using it only for Web has become one of my favorite and
development and haven’t yet learned most indispensable tools. It’s hard to
how it works as a more general- believe that I used to be content with
purpose programming language, CVS and SVN, given the advantages
you may well want to read Eloquent that Git brings to the table. I must
JavaScript. The book, written by Marijn admit that many years ago, a friend
Haverbeke and available on-line at of mine said that I eventually would
http://eloquentjavascript.net (and switch to a distributed version-control

34 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 34 9/17/14 4:49 PM


COLUMNS
AT THE FORGE

system, which would make life so much data” increasingly is applied to such
easier. He was right, although he was programs, and a number of books have
recommending a system that preceded been written in the past few years that
Git known as Arch, which I don’t attempt to help newcomers to the field.
believe is used any longer. In some cases, you don’t need to
I frequently teach courses in the use collect or analyze the data yourself.
of Git, and I’ve found that the problem Rather, you can get by just using the
for most users is not the commands, APIs that various systems have provided.
but rather the understanding of what This is particularly the case with social
Git does (and doesn’t do) and how networks, which collect enormous
the various objects work together. In quantities of information about their
particular, an understanding of what members and the connections between
a commit is, and how branches, tags, them. Mining the Social Web, by
blobs and trees fit into this commit- Matthew A. Russell, was released in its
centric view of the world, is the biggest second edition (ISBN 9781449367619),
obstacle to working with Git. and it describes many ways in which
So, I was happy to see the Git you can access and analyze different
Pocket Guide, written by Richard E. social networks. I’ve played with
Silverman and published by O’Reilly such APIs in the past, so I wasn’t
(ISBN 9781449325862). Yes, this book new to their use in my applications,
will help you use Git better, and it will but this book described a number
remind you of many of the commands. of uses I didn’t think of, with lots of
But more significant, the Git Pocket clear example code that illuminated
Guide introduces you to the objects the points.
Git uses and describes how they work For those who want to analyze large
together to provide a robust and data sets more directly, Doing Data
efficient version-control system. Science, by Cathy O’Neil and Rachel
Schutt and published by O’Reilly
Databases and Analysis (ISBN 9781449358655), is a dense,
The growth of the Web has led not but interesting, introduction to the
only to a growing need for people techniques that are collectively known
who can create Web applications, but as “Data Science”. The authors give
also for those who can store, retrieve a whirlwind tour of the math and
and analyze the data generated by algorithms used in such analysis and
those applications. The term “big also the types of conclusions you

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 35

LJ246-Oct2014.indd 35 9/17/14 4:49 PM


COLUMNS
AT THE FORGE

can draw from its use. Some of this Other Books


book was a bit heavy for my needs Of course, I don’t read only technical
and interests, but it gave me a much books, although my friends and
better sense of what the Data Science family might not quite believe that
people are doing, and how it is already claim. I have read a number of
becoming useful. I should note that excellent books in the past year that
Cathy O’Neil, one of the co-authors of I think you all might enjoy.
this book, is a participant in the new Tim Harford is a well-known economics
“Slate Money” podcast. If you want writer and has published numerous
to hear financial analysis driven by big books on the subject. His most recent,
data, you might want to tune in to that The Undercover Economist Strikes Back,
weekly recording. describes how macroeconomics and
government policies work, and the
Freelancing and Business various theories that economists have
I’ve been a freelance consultant since used to try to understand these policies
1995, working with clients around the and their effects. I have long had an
world, and I really enjoy my work. I interest in economics, but still very much
even participate in a weekly podcast, enjoyed reading this book, which shed
“The Freelancers Show”, in which new light on the differences between
panelists discuss different aspects of various schools of economics.
what it’s like to be self-employed. Another favorite writer of mine,
Two of my co-panelists from the show Tom Standage, came out with a new
have come out with eBooks during the book this year: Writing on the Wall:
past year. Curtis McHale wrote Don’t Be Social Media—The First 2,000 Years.
an Idiot: Learn to Run a Viable Freelance Standage’s argument is that just
Business (http://curtismchale.ca/ about every type of social media
products/run-viable-freelance-business), and technology that we use
which gives practical advice for starting nowadays has precedents in
and running a successful freelance previous cultures. His funny and
business. Along the same lines, Eric interesting book is sure to give you
Davis has a practical, day-by-day some perspective on Facebook and
plan for you to start on the freelancing LinkedIn, among other things.
track, in his 30 Days to Become a Another great book that came out
Freelancer (http://theadmin.org/ this year is How Not to Be Wrong:
30-days-become-freelancer). The Power of Mathematical Thinking,

36 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 36 9/17/14 4:49 PM


COLUMNS
AT THE FORGE

by Jordan Ellenberg. Ellenberg is a Are Building a New Empire in Africa,


mathematics professor, and he tries to which describes the experiences and
show in this book how mathematical interactions of Chinese expatriates in
thinking can help you make useful various African countries.
decisions. He starts the book by Finally, as someone who recently
pointing out that “mathematics” finished a PhD, I can recommend
isn’t what you learned in elementary a funny (if rather cynical) book:
and high school, and it succeeds in Surviving Your Stupid, Stupid
having very few equations in the Decision to Go to Grad School, by
book. Rather, his point is to show Adam Ruben. Perhaps it’s easier
how it’s a perspective on life that to laugh at his jokes now that I’ve
can help you make decisions or completed the degree, but I found
persuade others. To his credit, the it not only funny but also
author also includes a number of therapeutic to know that others
examples of where mathematics had experienced similar problems
cannot really provide a clear-cut and challenges to mine during their
answer, such as (most surprisingly) grad-school careers.
in deciding election results. I hope these recommendations
As readers of this column know, I will provide you with many hours of
have traveled to China several times insightful and interesting reading! I’m
in the past few years to teach Ruby sure I have missed many good books
and Python programming classes. that came out in the past year; I’m
And, I’ve become something of an always open to hearing about them
aficionado of China-related books and welcome your suggestions. Q
written by reporters who were there.
Evan Osnos, who was the New Yorker’s Reuven M. Lerner is a Web developer, consultant and trainer.
correspondent in China for several He recently completed his PhD in Learning Sciences from
years, published a book this year titled Northwestern University. You can read his blog, Twitter feed
Age of Ambition: Chasing Fortune, and newsletter at http://lerner.co.il. Reuven lives with his wife
Truth, and Faith in the New China that and three children in Modi’in, Israel.
tries to make sense of the political and
social changes happening in China.
Along the same lines, I’m enjoying Send comments or feedback via
Howard French’s book, China’s Second http://www.linuxjournal.com/contact
Continent: How a Million Migrants or to [email protected].

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 37

LJ246-Oct2014.indd 37 9/17/14 4:49 PM


COLUMNS
WORK THE SHELL

Picking Out DAVE TAYLOR

the Nouns
Dreamer—a dream interpretation program, as a shell script...
well, sort of.

A reader wrote a letter to me (oh disconnected the elements of a dream


happy day!), and although I’m still often seem. Dreams have been seen
not entirely sure what she’s trying to as both visions from the gods and
accomplish, it’s an interesting puzzle the playground of our subconscious
to try to tackle anyway. Here’s what and its need to resolve our daily
she asked: experiences. And then there’s Freud,
who is pretty sure that if you aren’t
I do not know how to code, but literally dreaming of cigars, it’s
I have a project in mind that is because you’re envious of people with
something like Mad Libs, but is cigars or because you’re fixated on
for dream interpretation. I would cigars but suppressing your interests.
like for people to be able to type OOohhhhkay then. No cigars, okay?
a dream, and then the computer And no Lewinsky jokes either.
program would pick out the nouns What we need to accomplish this
and ask the participants to freely task is a script that parses input,
associate anything that comes to identifies and creates a list of nouns,
mind if they were that object or prompts users for their free-association
person. Then, the computer would synonyms for each of the nouns, then
replace the typed responses back pushes out the original text again,
into the typed text for the surreal replacing each original noun with a
interpretation. Do you think this substitute as suggested by the user.
would be difficult to create? To start, how do you identify nouns?

Mad Libs for dreams? That’s First, We’ll Kill All the Nouns
certainly a curious idea, particularly I was going to grab the comprehensive
given how seemingly random and dictionary from Princeton University’s

38 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 38 9/17/14 4:49 PM


COLUMNS
WORK THE SHELL

Wordnet program, but closer examination that we have a noun list:


reveals that it has more than 85,000
words and has all sorts of obscure for word in $( sed 's/[[:punct:]]//g' $dream |

alternative uses and so forth. The end ´tr '[A-Z]' '[a-z]' | tr ' ' '\n')

result is that although it’s comprehensive, do

it generates too many false hits. So # is the word a noun? Let's look!

INSTEAD $ESI 1UINTANS HAS A SIMPLE WORD if [ ! -z "$(grep -E "^${word}$" $nounlist)" ] ; then

only list you can grab for our purpose nouns="$nouns $word"

here: http://www.desiquintans.com/ fi

downloads/nounlist.txt. done

It’s in exactly the format needed too:


The for loop is a bit complicated,
$ head nounlist.txt but it’s removing all punctuation from
aardvark the input, translating uppercase to
abyssinian lowercase, and then converting each
accelerator space into a carriage return. The result
accordion can be shown most easily by example.
account Let’s say that we had this as input:
accountant
acknowledgment I've never seen a blue chipmunk!
acoustic
acrylic Running it through the sed | tr | tr
act filter produces this:

It seems like that would be the ive


most difficult step, but in fact, it’s never
surprisingly easy given the almost seen
infinite data store of the Internet. a
blue
Identifying Nouns in Prose chipmunk
The next step is rather easy: given
some prose, break it down into That’s easy enough, and now that
individual words, then test each word we can separate out each word from
to identify which are nouns. This is the input, it’s easy to search the noun
really the bulk of the program, now list to see if any match. Again, it’s

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 39

LJ246-Oct2014.indd 39 9/17/14 4:49 PM


COLUMNS
WORK THE SHELL

a bit complex, because we need until [ "$input" = "DONE" -o "$input" = "done" ]

to ensure that we aren’t getting do

embedded matches (for example, echo "$input" >> $dream

matching the noun “acoustic” for read input # let's read another line from the user...

the slang word “stic”). done

That’s done by rooting the search as a


regular expression: ^ is at the beginning echo ""

of the line, and $ is the end of the line— echo "Okay. To confirm, your dream was about:"

hence the regular expression ^${word}$


where the use of the optional {} cat $dream

notation just delimits exactly what the


variable name is to the shell. echo "=============="

With some debugging code


included, here’s our first draft of this for word in $( sed 's/[[:punct:]]//g' $dream | tr '[A-Z]'

entire script: ´'[a-z]' | tr ' ' '\n')

do

#!/bin/sh # is the word a noun? Let's look!

if [ ! -z "$(grep -E "^${word}$" $nounlist)" ] ; then

# dreamer - script to help interpret dreams. does this nouns="$nouns $word"

# by asking users to describe their most recent fi

# dream, then prompts them to free associate done

# words for each of the nouns in their original description.

echo "Hmm.... okay. I have identified the following

nounlist="nounlist.txt" ´words as nouns:"

dream="/tmp/dreamer.$$" echo "$nouns"

input=""; nouns="" echo "Are you ready to do some free association? Let's begin..."

trap "/bin/rm -f $dream" 0 # no tempfile left behind for word in $nouns

do

echo "Welcome to Dreamer. To start, please describe in a echo "What comes to mind when I say $word?"

´few sentences the dream" done

echo "you'd like to explore. End with "DONE" in all caps

´on its own line." exit 0

40 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 40 9/17/14 4:49 PM


COLUMNS
WORK THE SHELL

As is immediately obvious, the free association


section at the end and the subsequent reassembly
of the prose with the new free association words
or phrases is still to come.

It’s really broken into simple Are you ready to do some free association? Let's begin...

functional blocks: first prompting What comes to mind when I say tree?

users to share their dream, then What comes to mind when I say house?

breaking down the prose into What comes to mind when I say middle?

individual words and comparing What comes to mind when I say forest?

them to the noun list and finally What comes to mind when I say owl?

(albeit not yet in its final form), What comes to mind when I say cold?

prompting for the free association


of each identified noun. As is immediately obvious, the free
Let’s run it to see what I mean: association section at the end and the
subsequent reassembly of the prose
$ sh dreamer.sh with the new free association words
Welcome to Dreamer. To start, please describe in a few or phrases is still to come.
sentences the dream you'd like to explore. End with DONE But that’s a project for next month.
in all caps on its own line. Meanwhile, keep a dream journal
I was sitting in a tree house in the middle of an ancient and soon you’ll be ready to interpret
forest and an owl was staring at me. It asked "who?" and it thanks to the Linux shell—or
I woke up in a cold sweat. something like that! Q
DONE

Dave Taylor has been hacking shell scripts for more than 30 years.
Okay. To confirm, your dream was about: Really. He’s the author of the popular Wicked Cool Shell Scripts
and can be found on Twitter as @DaveTaylor and more generally
I was sitting in a tree house in the middle of an ancient at his tech site http://www.AskDaveTaylor.com.
forest and an owl was staring at me. It asked "who?" and

I woke up in a cold sweat.

============== Send comments or feedback via


Hmm.... okay. I have identified the following words as nouns: http://www.linuxjournal.com/contact
tree house middle forest owl cold or to [email protected].

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 41

LJ246-Oct2014.indd 41 9/17/14 4:49 PM


COLUMNS
HACK AND /

Return of KYLE RANKIN

the Mac
Save yourself keystrokes by building a library of vim macros
to automate mundane text-editing tasks.

In my July 2014 column, I talked more complicated edits, or if I have to


about vim macro basics. In that perform edits selectively in some files
article, I described how to record a but not others, I’ve found it useful to
custom macro, assign it to a key and record a few different simple macros
then use it to make automated edits under different keys, then record a new
to a BIND zone. I also teased that macro that just calls those other macros
I would cover more advanced uses in a particular order. Among other
of macros, like nested macros, in a things, this lets me change some of the
future issue. I took a brief detour shorter macros if I need to, without
to cover a few different topics, but having to re-record everything.
now I’m back on topic, and in this For the first example, let’s look at
article, I discuss more complicated a more complete version of the BIND
uses for macros. zone file I used last time:
I like using BIND zone files for macro
examples, because it’s the file I most ;

often use macros in myself. Because ; BIND data file for example.com

multiple people often edit zone ;

files, they may not all have the same $TTL 15m

formatting. Plus, the top of a zone @ IN SOA example.com. root.example.com. (

file generally has a different multi-line 2014081500

format compared to the rest of the 10800

file. In my July 2014 article, I talked 1200

about how to add 50 sequential A 7200

records in a zone file using a single 7200 )

macro, but when I have to perform ;

42 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 42 9/17/14 4:49 PM


COLUMNS
HACK AND /

example.com. IN NS ns1.example.com. Q Macro s will change the contact


example.com. IN NS ns2.example.com. information and increment the
; serial.
ns1 IN A 10.9.0.5

ns2 IN A 10.9.0.6 Q Macro n will update the name


; server records.
worker1 IN A 10.9.0.15

worker2 IN A 10.9.0.16 Q Macro w will add one more worker.


worker3 IN A 10.9.0.17

. . . Because I’m going to chain these


worker50 IN A 10.9.0.64 macros together, it’s even more
important than in the past that I make
In this example, let’s say I have sure my cursor is anchored in a known
15 zone files for different zones, location first. For the first macro, this
but I want to make the same set of means starting with gg to move to the
edits to all of them. I want to change very top of the file, while for the last
the TTL in the file to be 10 minutes, macro, I will want to type G to move
and I need to change the contact info to the bottom of the file. At each
for the domain from root@domain phase, it’s incredibly important that
to dnsadmin@domain. I also need you test each macro, then undo the
to increment the serial number changes and confirm that your macros
(2014081500) in the zone file, and I work exactly how you expect. Let’s
need to change the name server IPs all break down each macro.
to point to a new set of name servers For macro t, I first type qt to enter
at 10.1.0.250 and 10.1.0.251, and macro mode and assign the macro to
finally, I want to add 50 more workers the t key. Then I type gg to make sure
to each zone file. I’m at the top of the file. Next I type
Although I imagine I could build /TTL <Enter> to move the cursor to the
all of this into a single big macro, TTL line. Then I type w to move forward
for me, it makes sense to split up a word to the actual TTL value I want
the steps into at least four macros to change, and then I type cw10m to
that I already have pre-assigned change the following word from 15m
letters to: to 10m. Finally, I press Esc to exit insert
mode, and q to exit the macro. The
Q Macro t will change the TTL. complete set of macro keystrokes then

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 43

LJ246-Oct2014.indd 43 9/17/14 4:49 PM


COLUMNS
HACK AND /

Although this seems like a lot of text, it will save


a ton of work when you have to repeat the steps
on multiple files.

would be qtgg/TTL <Enter> wcw10m to the top of the file. Next I type
<Esc> q. Once I record the macro, I type /^ns1 <Enter> to move to the line
u to undo my changes, and then test that configures the name servers.
the macro by typing @t. At this point, there are a few ways I
For macro s, I type qs to enter could edit these lines. My preference
macro mode and assign the macro is to type /IN A <Enter> 2w , which
to the s key. Then I type gg again will move my cursor to the beginning
to anchor to the top of the file. of the IP. Then I type c$10.1.0.250
Next I type /SOA <Enter> to move <Esc> to edit to the end of the line
to the SOA line. Then I type /root and exit insert mode.
<Enter> to move to the beginning Since ns2 is so similar to ns1, I can
of root.example.com, and then just type yyp <Ctrl-a> $ <Ctrl-a> to
type cwdnsadmin <Esc> to change copy and paste ns1, increment ns1 to
that word to dnsadmin and exit be ns2, then move to the end of the
insert mode. Next I type ^j to move line and increment the IP. Next I need
the cursor to the beginning of to find the existing ns2 line and delete
the following line. Finally, I type w it with /^ns2 <Enter> dd . Finally, I
<Ctrl-a> to move forward to the serial can type q to save the macro. The
number and increment it, and then complete macro is qngg/^ns1 <Enter>
q to exit macro mode. The complete /IN A <Enter> 2wc$10.1.0.250
set of macro keystrokes becomes <Esc> yyp <Ctrl-a> $ <Ctrl-a> /^ns2
qsgg/SOA <Enter> /root <Enter> <Enter> ddq . Although this seems like
cwdnsadmin <Esc> ^jw <Ctrl-a> q . a lot of text, it will save a ton of work
And again, I save the macro and use u when you have to repeat the steps on
to undo the change and replay it with multiple files.
@s to make sure it does what I expect. For the final macro w, I type qw
For macro n, I type qn to enter to enter macro mode assigned to
macro mode and assign the macro to the w key, and then type G to move
the n key. Then I type gg to anchor to the bottom of the file this time.

44 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 44 9/17/14 4:49 PM


COLUMNS
HACK AND /

Then I type /^worker <Enter> N to file, I can just type @c to perform the
search for the next worker (which complete list of steps.
will wrap around to the top, then N Now besides saving a few
will move back to the last worker in keystrokes, there are other good
the file). Finally, I type yyp to copy reasons to nest macros in this way.
and paste the line, then <Ctrl-a> Because I saved each logical step
$ <Ctrl-a> to increment both the as its own macro, I can tweak or
worker hostname and the IP. Finally, modify any of the above macros
I type q to exit macro mode. The independently, save the new macro
complete macro is then qwG/^worker to the same key, and all of the other
<Enter> Nyyp <Ctrl-a> $ <Ctrl-a> q. macros, including the final combo
Like the others, I test it out with @w macro can stay the same.
a couple times, and use u to undo Let’s say that after I recorded all of
all the changes in between until I am these macros, I realized I got the IP
satisfied that it works. address for the name servers wrong.
Now that I have all of these All I would have to do is record a
macros recorded, I could just open new macro assigned to the same n
each file and type @t to update key, and once I was done, I still could
the TTL, @s to edit the contact use @c to make the complete set of
information and serial, @n to update changes to a file.
the name servers, and type 50@w to I hope you find these examples
add 50 more workers. useful, and that the next time you
Because I’m going to perform have to perform a series of mundane
these same steps on a number of edits to many text files, you’ll save
files, I might as well capture all those some keystrokes with vim macros. Q
commands in a new macro I’ll assign
to c. To do that, I just type qc to enter Kyle Rankin is a Sr. Systems Administrator in the San Francisco
macro mode assigned to the c key, Bay Area and the author of a number of books, including The
then type @t@s@n50@w to perform all Official Ubuntu Server Book, Knoppix Hacks and Ubuntu Hacks.
of the previously recorded macros. He is currently the president of the North Bay Linux Users’ Group.
Finally, I type q to exit macro mode.
The complete set of keystrokes is
qc@t@s@n50@wq to assign all of the Send comments or feedback via
above sets of keystrokes to a single http://www.linuxjournal.com/contact
macro. Now when I open the next or to [email protected].

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 45

LJ246-Oct2014.indd 45 9/17/14 4:49 PM


COLUMNS
THE OPEN-SOURCE CLASSROOM

This Is Why SHAWN POWERS

We Can’t Have
Nice Things: SSH
Firewalls are great, but don’t rely on them as your only
network security!

I’ve written about SSH before— into the computer. If you’re not,
often even. But for the Linux user, however, you can use SSH to open
SSH is one of those tools that is a tunnel for you automatically. This
so incredibly flexible, everyone does require a few things:
should know and understand it
inside and out. For this article, I Q You need a server running SSH with a
decided to put on my black hat public IP address. I use my co-located
and demonstrate how convenient, Raspberry Pi in Austria, but you can
and terrifying, SSH can be. use your home connection as long
as you set up a Dynamic DNS entry
Phone Home in case your IP changes.
Most articles on SSH start
with forwarding X11 traffic or Q The firewalled network has to
demonstrating the SOCKS proxy allow outgoing SSH connections.
feature. I want to start with Most do, but if you can’t SSH out
something a little more creepy and from inside the firewall, you might
a whole lot more awesome. The have to do something creative
premise is this: you have a computer like run SSH on port 443 on your
inside a firewalled, NAT’d network, server. (That port is usually open
and you want to access it remotely. for HTTPS traffic, and since it’s
If you’re the sysadmin, you can encrypted, it’s tougher to sniff out
just forward a port on the firewall your naughty deeds.)

46 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 46 9/17/14 4:49 PM


COLUMNS
THE OPEN-SOURCE CLASSROOM

Q You need key pairs set up for server, I’m stuck behind a firewall.
password-less logins from the Will you listen on port 2222 for
computer inside the firewall to anyone trying to connect, and if they
your server with the public IP. do, please forward the traffic to me
(Here’s a demo I did back in 2009 on my port 22.”
on how to set up SSH key pairs: The command can get creepier
https://www.youtube.com/ too. In my example, I just forwarded
watch?v=R65HTJeObkI.) traffic to the public port 2222 to the
internal port 22 behind the firewall.
Once you have the prerequisites But if you were to change the
in place, the process is a simple command like this:
one-liner. First, the command, then
the explanation: ssh -N -R 0.0.0.0:3389:192.168.1.5:3389 user@remotehost

ssh -N -R 0.0.0.0:2222:127.0.0.1:22 user@remotehost You’ve now created a public-access


tunnel directly to the Windows RDP
The -N flag tells SSH that you don’t server on 192.168.1.5 behind the
want an interactive shell; you just firewall. Anyone on the Internet
want to establish the connection. who connects their RDP client to the
That means in order to take the remote host’s IP address will get the
tunnel down, you simply press Ctrl-C. RDP login screen from 192.168.1.5.
It can become confusing if you Freaked out yet?
have an open terminal connected One of the problems with this
interactively to a remote server. The setup is the relative instability of the
tunneling still will work, but if you Internet. If the SSH connection is
inadvertently type exit , it logs you severed, the tunnel collapses, and you
out and kills the tunnel. no longer can reach the computer
The -R 0.0.0.0:2222:127.0.0.1:22 inside the firewall. Thankfully, there’s
portion of the command is where a really great tool to help with that
the magic happens. What you’re too: AutoSSH.
doing is creating a reverse tunnel,
which allows anyone who can access AutoSSH
your public IP server to ssh in to the Having a diabolical tunnel to an
server behind the firewall. In English, internal network across the globe is
the command is saying, “Hi remote only awesome until it stops working.

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 47

LJ246-Oct2014.indd 47 9/17/14 4:49 PM


COLUMNS
THE OPEN-SOURCE CLASSROOM

SSH is a finicky protocol, so the of the line is similar to what I showed


smallest blip over the Internet can typed above.
cause the connection to fail. If I used to write complex bash scripts
you launch the SSH command with to check for connectivity, and kill off
AutoSSH, however, it will monitor then restart SSH, but using AutoSSH
your connection and restart it if is much more efficient and reliable.
things go wrong. AutoSSH will keep I’ve been using it for years, and it is
trying too, so even if the network is rock-solid. The most I’ve ever had to
down for an extended time, when it do is kill off defunct SSH connections
comes back up, the SSH connection on the public server if for some
will be re-established. reason I can’t connect. AutoSSH then
AutoSSH is available for just about happily creates a new connection,
every major distribution, but it has to and I’m back in business.
be installed on the computer inside
the firewall, because that’s where the What Good Is It?
connection has to initiate from. How I personally use this sort of setup to
I do it is basically put something like access internal servers that aren’t
this in my crontab to run on @reboot: accessible directly from the Internet.
I don’t like to open ports directly
autossh -M 41000 -f -N -R 0.0.0.0:2222:127.0.0.1:22 user@remotehost into internal servers if possible, so if
I can grant myself access to multiple
Only two of the flags are for internal servers by SSH’ing to a
AutoSSH; the others get handed remote, unrelated IP on a random
off to SSH itself. Basically, the -M port, I feel a little better about it.
41000 establishes a monitor port I also use this sort of setup to
for AutoSSH to use. It’s possible to expose multiple Web servers from
use SSH’s built-in ability to monitor inside a network to the outside.
a connection, but I’ve had very bad Figure 1 shows the basic premise. The
luck with it. Using AutoSSH’s -M flag command looks similar to the example
seems to work the best. It doesn’t above, but with multiple -R flags.
matter what port you select, as long
as it’s not currently in use on either autossh -M 41000 -f -N -R 0.0.0.0:8001:192.168.1.10:80 \

computer. The next flag, -f , just tells -R 0.0.0.0:8002:192.168.1.20:80 user@remotehost

AutoSSH to run in the background


and monitor the connection. The rest To note, that’s all on one line, I

48 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 48 9/17/14 4:49 PM


COLUMNS
THE OPEN-SOURCE CLASSROOM

Figure 1. Although there’s a lot going on behind the scenes, an end user accessing
the virtual hosts on the left just sees a Web server.

just used the backslash so it Even Scarier!


formats better. Basically, by using You may have noticed that using
multiple SSH reverse tunnels an SSH tunnel provides you only
(the -R flags), internal Web servers with specific access to specific
are accessible by pointing the ports spelled out with the tunnel
browser to http://remotehost:8001, directives. It is possible to pass
http://remotehost:8002 and so on. multiple -R flags, but it’s tough
I then use a reverse proxy (see my to do that on the fly, because the
column in the August 2013 issue command is performed on the
for details) to connect to those computer inside the firewall. If you
strange URLs with standard virtual need to access the entire network
hostnames. SSH is such a powerful, behind the firewall, that’s where
flexible tool, that its uses are sshuttle comes into play.
seemingly unlimited! With that great I’ve mentioned sshuttle in past
power comes great responsibility issues of Linux Journal, but when
though, because SSH allows you to used in conjunction with the tunnels
do some pretty creepy things. I just described how to create, it

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 49

LJ246-Oct2014.indd 49 9/17/14 4:49 PM


COLUMNS
THE OPEN-SOURCE CLASSROOM

Figure 2. Using SSH tunnels and sshuttle together can provide an incredibly scary level
of network access from outside the firewall.

turns into something that should be server to connect through—in this


impossible, but isn’t. Once you have case, user@remotehost on port
the reverse tunnel established, using 2222. Then the last part describes
the processes above, the command to the internal network behind the
get you access to the entire firewalled firewall. This is something you’ll
network is another one-liner: need to know or figure out from
your internal workstation. It will
sshuttle -D -r user@remotehost:2222 192.168.1.0/24 ask you for your sudo password,
and then establish a network route
As a reminder, this runs on your through the SSH tunnel.
home workstation, not on the Basically, you’ve now not only
computer behind the corporate accessed the workstation inside
firewall. (See Figure 2 for a complete the firewall, but you have full access
picture.) The -D flag tells sshuttle to to anything that workstation has
run as a dæmon in the background. access to as well—from anywhere
The -r flag tells it what remote on the Internet.

50 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 50 9/17/14 4:49 PM


COLUMNS
THE OPEN-SOURCE CLASSROOM

We’re All Doomed! Today’s little tutorial isn’t really


If you are feeling a bit like the nerdy hacking. We’re not doing anything
hero in a modern espionage film, the protocols aren’t designed to do.
well yeah, I get it. There are some Heck, all the tools are available pre-
legitimate reasons to create tunnels packaged in your distribution! I don’t
like this, although admittedly an want anyone to spend too much effort
actual VPN is usually the “proper” trying to block my “attack”, because
way to go about it. It’s important for it’s not an attack at all. It’s just using
those of us in charge of networks to the tools available in exactly the way
realize how easy it is to gain access to they’re supposed to be used.
internal systems, however. It’s possible SSH is my favorite command-line
to block access like this at the firewall utility. It can do so many things, from
level, but honestly, there’s always transferring files to tunneling X11
ways around the firewall if you’re traffic. As I described here, you also
able to initiate internally. Plus, using can reroute traffic over tunnels giving
draconian blocking methods will just you access to systems that shouldn’t
inconvenience your users to the point easily be accessible. Ultimately, I
of making them revolt. So what’s a hope learning about SSH will get you
network admin to do? interested in network security, because
Obviously, learning about network until you understand the danger, there’s
security is crucial. The reasons VLANs not much motivation to learning and
and NAC (network access control) implementing such systems. Until next
systems exist is to prevent undesired time, happy tunneling!Q
access to various systems. When
you’re designing or redesigning Shawn Powers is the Associate Editor for Linux Journal.
your network, don’t assume an He’s also the Gadget Guy for LinuxJournal.com, and he has an
external firewall will protect you from interesting collection of vintage Garfield coffee mugs. Don’t let
computers outside your network. his silly hairdo fool you, he’s a pretty ordinary guy and can be
Disgruntled employees, malware reached via e-mail at [email protected]. Or, swing by
victims or nerdy employees like me the #linuxjournal IRC channel on Freenode.net.
will find a way to access systems from
the outside. Make sure their point
of entry doesn’t give them access to Send comments or feedback via
systems they shouldn’t have access to http://www.linuxjournal.com/contact
in the first place. or to [email protected].

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 51

LJ246-Oct2014.indd 51 9/17/14 4:49 PM


NEW PRODUCTS

Paragon Software Group


and Cambridge University
Press’ Cambridge English
Pronouncing Dictionary
English-language learners—and American Anglophiles practicing their imitation of James
Bond—will delight in the news that the Cambridge English Pronouncing Dictionary is
now in app form. This latest version of the dictionary, “the classic guide to accurate,
contemporary pronunciation for British and American English”, is published jointly by
Cambridge University Press, the world’s oldest publisher, and Paragon Software Group.
This dictionary app for Android, iOS and Mac OS X users is based on the classic version
of Daniel Jones’ guide to contemporary pronunciation for British and American English
and is designed to meet the needs of English language learners striving to perfect their
pronunciation of even the most challenging words, such as “though” and “hono(u)r”,
personal names, company names, technology and science definitions, and more. The app
VERSION CONTAINS A VARIETY OF FEATURES THAT AID LEARNING SUCH AS A &LASH #ARD 1UIZ SEARCH
and navigation (such as full-text search) and convenience (no Internet connection required).
http://www.cambridge.org and http://www.slovoed.com

Imagineer Systems Ltd.’s


mocha Pro
Visual effects solutions developer Imagineer
Systems Ltd. says that it has made its mark
on such films as The Hobbit, Black Swan,
Transformers and the Harry Potter series. The
latest release in Imagineer’s creativity toolkit
is mocha Pro 4, the company’s updated standalone software utility optimized for visual
effects and post-production challenges. Key existing mocha Pro features include a rock-solid
planar motion tracking engine, advanced roto tools, 3-D camera solver, stereoscopic 3-D
support, calibration of lens distortion, stabilization module and insert module. New features
found in version 4 include new advanced tools for stereoscopic 3-D, customizable keyboard
shortcuts, Adobe Premiere support, Python scripting, improved format support and more.
http://www.imagineersystems.com

52 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 52 9/17/14 4:49 PM


NEW PRODUCTS

Checkmarx Game of Hacks


In its new on-line game Game of Hacks, Checkmarx
allows developers to have fun while honing their
security skills and understanding of the hacker’s
perspective. In the game, developers and security
professionals test their application hacking skills,
improve their code security know-how and facilitate better security practices in hope of
reducing the amount of vulnerabilities in their applications. Available for desktop, tablet
and mobile, Game of Hacks presents developers with vulnerable pieces of code and
challenges them to identify the application layer vulnerability as quickly as possible. It even
has a two-player mode allowing head-to-head competition. Players analyze vulnerabilities
INCLUDING 31, INJECTION 833 LOG FORGERY PATH TRAVERSAL PARAMETER TAMPERING AND OTHERS IN
myriad programming languages. Additionally, developers can add their own questions and
vulnerable code to the game in any programming language highlighting any vulnerabilities,
growing the game’s scope as more users join.
http://www.gameofhacks.com

Laura Cassell and Alan Gauld’s


Python Projects (Wrox)
Python trainers Laura Cassell and Alan Gauld targeted their new
book Python Projects at the Python programmer with basic skills
who is ready to start building real projects. Programmers who
know the Python syntax and lay of the land, but who still may be
intimidated by larger, more complex projects, will find this book
useful. Python Projects provides a walk-through of the basic setup
for an application and the building and packaging for a library, and explains in detail the
functionalities related to the projects. Topics include maximizing the power of the standard
library modules; finding and utilizing third-party libraries; creating, packaging and reusing
libraries within and across projects; building multilayered functionality, including networks,
data and user interfaces; and using development environments like virtualenv, pip and
more. Publisher Wrox says that Python developers looking to apply their skills to real-world
challenges will find a goldmine of information and expert insight in Python Projects.
http://www.wrox.com

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 53

LJ246-Oct2014.indd 53 9/17/14 4:49 PM


NEW PRODUCTS

AES’ CleverView for TCP/IP on Linux


and CLEVER Mobile for Linux
The CleverView for TCP/IP on Linux solution from AES addresses the
challenge in cloud-based data centers that an ever-greater amount
of traffic is between servers, preferably Linux-based ones, of course.
CleverView is a performance and availability monitoring solution for
Linux, UNIX and System z that has added new features in its latest v2.3
release. Concurrently, AES released an updated CLEVER Mobile for Linux
so that enterprise knowledge workers can access server performance
and availability details from their mobile devices. The most noteworthy
highlight of CleverView v2.3 is the SMF Host Utility that integrates Linux/UNIX-monitored
metrics with z/OS SMF records, expanding enterprise insight into performance and availability.
Also noteworthy is the real-time notification of problems leading to increased Linux and UNIX
service availability, regardless of the hardware platform on which Linux or UNIX resides.
http://www.aesclever.com

Paul Schuytema’s
The Web Wargame Toolkit
(Mercury Learning & Information)
Paul Schuytema’s new book The Web Wargame Toolkit walks readers
through the process of crafting an old-school, turn-based wargame
in PHP utilizing the CodeIgniter application framework. More
generally, this is a soup-to-nuts how-to book for those interested in
crafting Web game applications utilizing a basic LAMP system. The
wargame project serves as an exciting context for PHP programmers looking to gain more
in-depth application coding experience. Those with an interest in game development will
learn the coding skills to support design decisions as they create the game project. The book
assumes at least a beginning level of PHP coding experience, though no previous CodeIgniter
or game development experience is required. Other features of the book-DVD set include full
database design for game data structures, a flexible game map system, a complete overview
of a simple CRUD system and complete, modifiable source code for the game.
http://www.merclearning.com

54 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 54 9/17/14 4:49 PM


NEW PRODUCTS

Wolfram SystemModeler
The updated Wolfram SystemModeler 4 is an easy-to-use, next-generation
modeling and simulation environment for cyber-physical systems.
SystemModeler enables users to draw on a large selection of built-in and
expandable modeling libraries to build industrial-strength, multidomain
models of a complete system. Wolfram is also well known for the
complementary Mathematica application, which provides a fully integrated
environment for analyzing, understanding and quickly iterating system
designs. The new SystemModeler 4 vastly expands support for modeling
libraries, adds standardized deployment of models to other simulation tools
and deepens integration with Mathematica. Other key new features include
a library store with verified model libraries, improved modeling features,
model creation support from Mathematica, as well as improved workflow in the integration with
Mathematica, a new documentation center and support for our beloved Linux OS.
http://www.wolfram.com

CacheGuard Technologies Ltd.’s


CacheGuard OS
CacheGuard Technologies Ltd.’s motto is “Web security made
affordable”. The company puts its motto into action with products
like CacheGuard OS, an integrated security solution designed
to manage Web traffic that is based on a custom-hardened version of Linux. The latest “next-
generation” release is CacheGuard OS NG v1. The company calls CacheGuard OS a powerful,
turn-key solution that allows companies to protect and optimize Web traffic traversing their Web
infrastructure. Customers can utilize CacheGuard OS as an appliance or turn their own hardware
into a powerful Web Gateway Appliance. CacheGuard OS integrates numerous Web security and
optimization technologies in a single functional network device. Technologies like proxy, IP firewall,
bandwidth shaping, caching, HTTP compression, URL filtering, Web application firewall and Web
malware filtering are all integrated into a unique operating system.
http://www.cacheguard.com

Please send information about releases of Linux-related products to [email protected] or


New Products c/o Linux Journal, PO Box 980985, Houston, TX 77098. Submissions are edited for length and content.

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 55

LJ246-Oct2014.indd 55 9/17/14 4:49 PM


FEATURE Raspi-Sump

RASPI-SUMP

How to set up a sump pump monitor


with an ultrasonic sound sensor,‚
Raspberry Pi and Python.
AL  AUDET

56 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 56 9/17/14 4:49 PM


I n June 2013, we had the
unfortunate luck of a basement
flood, caused by a tripped electrical
breaker connected to our sump pump.
There are so many things that can go
pit at regular intervals and sent me a
text if there was a problem. If it also
could display pretty graphs of sump
pit activity that I could access easily,
that would be a bonus.
wrong with a sump pump. You always Although I had written many scripts
are on guard for power outages, through the years at work, I never
blown breakers, sump pump failures, learned object-oriented programming.
clogged pipes and all manner of I made the decision to learn Python,
issues that can arise, which ultimately and a few months later, set myself
can end with a flooded basement. I to work on a monitoring system. I
needed a way to alert me of issues chose Python because it has an active
when I was not at home. Audible community, and many Raspberry
alarms are fairly cheap and are great Pi enthusiasts use it as their main
when you are physically in the house. scripting language. The Raspberry
They fail miserably when you are ten Pi uses Raspbian Linux, which is
miles away at work. I had a Raspberry based on Debian, so that already was
Pi that I had tinkered with periodically familiar ground. With these tools in
but for which I never had a real hand and in true Linux and Raspberry
purpose. I decided to try to put the Pi spirit, I decided to build my own
Pi to work as a dedicated sump pit and called it Raspi-Sump.
monitoring device. Hopefully, the Pi Raspi-Sump is a sump pit water-level
could send me SMS alerts if a problem monitoring system written in Python.
arose while I was away. It uses a Raspberry Pi and an HC-SR04
Since I did not have a programming ultrasonic sensor to monitor the water
background, I started to look for level in a sump pit, log the readings
an existing project I could install on and send SMS e-mail alerts if the
the Pi that could act as a sump pit water rises above a predefined level.
monitor. There are other projects In this article, I show the methodology
that can monitor sump pump activity; I used to create Raspi-Sump. I also
however, it seemed that everything I describe the physical setup of the
came across looked overly complicated monitor and the scripts that make it
or didn’t have the features I required. work. If you choose to do something
I needed something simple that similar, the source code and install
monitored the water level in the sump instructions are available on GitHub.

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 57

LJ246-Oct2014.indd 57 9/17/14 4:49 PM


FEATURE Raspi-Sump

With the help of a Python script,‚ the sensor,‚


which is mounted inside the sump pit facing
the water,‚ sends a sound pulse that reflects
off the water and back to the sensor.
It is free to use and modify as you Raspi-Sump includes:
wish (see Resources).
I determined that the features Q Raspberry Pi Model B and case.
I required in a monitor included
the following: Q Raspbian Linux.

Q Regular one-minute-interval Q HC-SR04 ultrasonic sensor.


readings of the water depth in
my sump pit. Q Five feet of Cat5 wire (four 24AWG
strands needed).
Q Logging of readings to a comma-
delimited file for processing graphs Q Two resistors (one 470R Ohm and
and historical pump activity. one 1K Ohm).

Q Automated SMS e-mail alerts if the Q Heat-shrink tubing to protect


water exceeds a predefined level. soldered connections.

Q Off-site graphical reports of the Q Plastic bracket to hold the sensor.


current water level to a Web site.
Q One two-foot piece of wood
Q Web-based historical information strapping to mount the plastic
on sump pump activity. bracket in the pit.

Q Automatic restart of the raspisump.py Q One floppy drive four-pin power


process after an unexpected failure. connector salvaged from an old PC.

The Physical Setup Q Two case-fan power connectors,


The complete list of components for also salvaged from the same PC.

58 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 58 9/17/14 4:49 PM


Total cost for materials, including time it takes for the sound pulse
a couple spare sensors, was $80. to bounce back to the sensor. It
The ultrasonic sensor I chose calculates the distance by measuring
is the HC-SR04, which has four the time required for the pulse to
connections that are wired to the return at the speed of sound. This
GPIO pins of the Raspberry Pi. W ith gives you a reading of the distance
the help of a Python script, the between the sensor and the water.
sensor, which is mounted inside the The distance is used to calculate the
sump pit facing the water, sends water depth and log a time-stamped
a sound pulse that reflects off result to a CSV file.
the water and back to the sensor. Figure 1 shows a closer look at
The script monitors the amount of the connections.

ZĂƐƉŝͲ^ƵŵƉtŝƌŝŶŐŝĂŐƌĂŵ
ZĂƐƉďĞƌƌLJWŝDŽĚĞů ,Ͳ^ZϬϰhůƚƌĂƐŽŶŝĐ^ĞŶƐŽƌ

s

dƌŝŐƚŽŐƉŝŽϭϳ

ĐŚŽƚŽŐƉŝŽϮϳ ϰϳϬZKŚŵZĞƐŝƐƚŽƌ

ϭ<KŚŵZĞƐŝƐƚŽƌ
'ƌŽƵŶĚ

Figure 1. Wiring Diagram

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 59

LJ246-Oct2014.indd 59 9/17/14 4:49 PM


FEATURE Raspi-Sump

The four pins on the sensor are A way is needed to throttle the
wired to the Raspberry Pi as follows: current to 3.3V, which won’t damage
the Pi. To protect the Pi from damage,
Q Pin 1 VCC connects to the 5V pin 2. simply insert a voltage divider on
the Echo line between the sensor
Q Pin 2 Trig connects to GPIO17 pin 11. and the Pi.

Q Pin 3 Echo connects to GPIO27 pin 13. Voltage Divider


The purpose of a voltage divider is
Q Pin 4 Ground connects to pin to reduce the amount of current sent
6 Ground. from one component to another.
As shown in Figure 1, I soldered
I chose GPIO17 and 27, but you can a 470R Ohm resistor on the Echo
use any available GPIO pins on the Pi wire and bridged a 1K Ohm resistor
as long as they are identified properly between the Echo and Ground wires.
in the Python script. This prevents blasting 5V to a pin
Pin 1 provides 5V of power to that is rated only for 3.3V. With
the HC-SR04 sensor. A command these resistors, voltage is actually
is initiated on GPIO17 (Trig) that a touch higher at 3.4V, which is
sets the value of the pin to True within a tolerable level. All soldered
for 10 micro seconds. This causes connections are covered with
the sensor to initiate a series of heat-shrinking tube to avoid
sound pulses toward the water electrical shorts.
for that short amount of time. Calculating resistor types required
The Echo pin connected to GPIO27 is beyond the scope of this article,
listens for a return pulse. The but there are many handy Web-
difference between the send and based voltage divider calculators
the return of the pulse gives a available to determine your
time measurement. The requirements. In this example, a 1K
measurement is used to calculate and 2K Ohm resistor would reduce
the distance of the water. the current to 3.333V.
This causes a small problem as
Raspberry Pi GPIO pins are rated Wiring
only for 3.3V. The sensor sends a The Raspberry Pi is connected to the
5V current back toward GPIO27. sensor with a five-foot length of

60 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 60 9/17/14 4:49 PM


Figure 2. Floppy Connector

CAT5 cable. Because there are four on-line, but anything you can
connections, only four of the eight salvage from an old PC works great.
twisted wires are used. On each
end of the selected wires, I soldered Mounting
connectors that were compatible The HC-SR04 is attached to a plastic
with the sensor pins and the pins case and screwed onto a piece of
on the Pi. An old 3.5" floppy drive wood strapping. The wood strapping
power connector works great for is inserted into the sump pit facing
the sensor connection (Figure 2). I downward and is easily adjustable
used a couple two-pin PC case-fan and removable if needed. The Cat5
connectors, salvaged from an old wire is securely taped to the sump
PC, for the connections on the Pi’s pump’s ABS pipe and an open
pins. These connectors are available wall stud to prevent tangling and

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 61

LJ246-Oct2014.indd 61 9/17/14 4:49 PM


FEATURE Raspi-Sump

Figure 3. Open
Sump Pit View

disconnection of the wire when


removing the sump pit lid.
Finally, the Raspberry Pi is
mounted on a wall stud and plugged
in to a UPS unit. Figure 4 shows the
finished view.

Raspi-Sump
The Raspi-Sump program currently
consists of three Python scripts. The
main script is raspisump.py. The script
is very simple and is only about 100
lines of code. The first thing it does
is set the variables of the sump pit,
like depth (72cm), critical water level
Figure 4. Finished Pit View (35cm) and GPIO pin assignments

62 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 62 9/17/14 4:49 PM


as mentioned earlier.
The script then takes
a sample of 11 water-
level readings every
minute and uses the
median sample as the
best reading (more on
this later). Once the
reading is established,
the script determines
if the water is at a
safe or critical level.
Safe levels are logged
to a CSV file, and the
script waits for another
minute to take the
next reading. Critical
levels are passed to a
function that logs the
level to the same CSV
file and initiates an SMS
e-mail to my cell phone
(Figure 5). I use the
Python smtplib module
to handle e-mail alerts.
You can configure any
e-mail server to handle Figure 5. SMS Alert
the alerts, including
a localhost mail server on the Pi, if sensor is called RPi.GPIO. This module
your ISP allows port 25 traffic. You can be used to control so many
also can use your ISP’s SMTP server or different types of equipment with your
Google’s Gmail SMTP server if you are Pi. Without delving into the “nuts and
using a Gmail account. bolts” of RPi.GPIO, the module helps
The key Python module used to you take control of the pins by turning
communicate between the Pi and the them on and off. This allows you to

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 63

LJ246-Oct2014.indd 63 9/17/14 4:49 PM


FEATURE Raspi-Sump

Figure 6. CSV File Being Updated in Real Time by raspisump.py

control all sorts of equipment, like The ampersand (&) starts the script
sensors and LEDs, for example. as a background process.
You can view the GPIO code in Access to GPIO pins requires elevated
the raspisump.py script within the privileges on the Pi. To start the script
water_level() function. Similar code manually, issue the command:
is used by many other projects that
communicate with the Pi’s GPIO pins. sudo /home/pi/raspisump/raspisump.py &
Adam Lappin’s Byte Creation Blog has
a good example that helped me learn Figure 6 shows using the tail
how to use the RPi.GPIO module in command to demonstrate the
this project (see Resources). CSV file being updated in real
Raspi-Sump is started automatically time by raspisump.py.
on bootup of the Raspberry Pi by What is displayed in Figure 6 is
adding this line to /etc/rc.local right rather strange. The water depth is
before the last line exit 0 : bouncing around. You would expect
the water to be consistently higher
/home/pi/raspi-sump/raspisump.py & with each reading. The reason for

64 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 64 9/17/14 4:49 PM


Figure 7. Graphs Generated by todaychart.py

this is that there is a one-centimeter of the actual water level. For a


variance in each reading. Linux is a residential system, I am not concerned
multitasking OS and not a real-time with millimeter accuracy. A small
one. It is not optimal for real-time variance in readings still provides safe
applications like communicating with reporting of the water level. This also
sensors and returning precise results. helps explain the jagged line in the
The best reason I can come up with is graphs that are generated and sent to
that the OS is busy doing other tasks a Web server at regular intervals.
and allows raspisump.py to record the The second script I use is
reading when it is finished dealing todaychart.py. This script generates
with those other processes. graphs, as shown in Figure 7, of
This brings me back to the reason water level activity from my CSV log
I use the median reading of a sorted files. It uses the Python matplotlib
sample. Every once in a while, the and NumPy modules to generate the
script gives an invalid reading that can graphs. rsync over SSH copies the
be way off. This can trigger a false graphs and CSV log files hourly to my
warning SMS alert even if the water is Web server via a cron script. I chose
below my critical level. However, these to generate graphs on the Pi instead
readings are rare. By using a sorted of the Web server, because different
sample, I can remove those fringe Linux distributions package different
readings at the high and low end if versions of matplotlib and NumPy. I
they occur. The median reading is prefer using the packaged versions for
always accurate within one centimeter simplicity. Always using the Raspberry

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 65

LJ246-Oct2014.indd 65 9/17/14 4:49 PM


FEATURE Raspi-Sump

Pi renders more consistent graphs, no of PVC pipe in the sump pit and force
matter which distro you use for your the sensor to take its reading down
off-site component. the empty pipe. This will focus the
The third and final script is pulse and hide the objects in the pit
checkpid.py. Its purpose is to monitor that are causing problems.
the health of the raspisump.py process
and restart it if it is stopped. Cron Conclusion
runs the script at regular intervals and Raspi-Sump is still in the early stages
looks for one of three outcomes. If the of development. There are other
script returns 0, this indicates a failed features I would like to add, such as:
process. checkpid.py then initiates a
restart command. If the script returns Q A manual power button to start
1, the process is fine, and the script and shut down the Raspberry Pi
exits cleanly. If the number is greater gracefully without logging in.
than 1, this indicates more than one
raspisump.py process. In this instance, Q A small LCD display to show
a killall 09 raspisump.py the current water level without
directive is initiated, and the process opening the lid.
is restarted.
Q A Web-based reporting system
Other Issues with Raspi-Sump using a Python Web framework.
The HC-SR04 sensor has a fairly wide
sonar field. The user manual states Q A Web-based management
that it works best with a 30° angle. interface for Raspi-Sump on the Pi
My sump pit is a busy place. It has a (like a home router).
backup pump that sits higher than the
main pump on a 2x6 stud. Each pump Q A GSM module component to
has a float ball that bounces around use the cellular network for alerts
in the pit. This results in false readings instead of the Internet.
when the sensor picks up an object
that enters its field. This problem can Q A configuration file to store variables
be mitigated by strategically placing as opposed to within the script.
the sensor further away from these
objects. If that is not possible, you can Q Package management for
vertically insert a 3" or greater piece installation of Raspi-Sump.

66 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 66 9/17/14 4:49 PM


A sump pit monitor is just one tool Raspi-Sump to suit your needs. If you
you can use to help avoid a flooded do, I would love to hear from you.
basement. It’s not a replacement for
a complete strategy that includes a Acknowledgement
backup pump on a separate electrical Special thanks to Ron Hiller (GitHub
breaker. A gas-powered electrical user @rhiller) for tirelessly answering
generator is also essential for my questions about voltage dividers
extended power outages. Also, I kept and his own sump pump monitor called
my cheap Home Depot audible alarm. pi-distance: https://github.com/rhiller/
A text alert at two in the morning is pi-distance.Q
useless if I am sound asleep. I want a
“full-out” screech to wake me up. Al Audet lives in Timmins, Ontario, with his wife Lucie and
I welcome all feedback on this project. five-year-old son Nicholas. He works as a Team Leader and
I am not a professional programmer, and Technical Advisor in Platform Virtualization Services for Shared
I am sure that I can substantially improve Services Canada and has been a Linux enthusiast and advocate
the code or add useful features that I since 1997. He loves all technology whose purpose is to increase
have not even considered. quality of life. He is user @Al_Audet on Twitter.
Although it’s not perfect, I now have
a system that works and gives me extra
peace of mind while I am away. If you Send comments or feedback via
are looking for a similar solution, I http://www.linuxjournal.com/contact
hope you can use, modify and improve or to [email protected].

Resources
Raspi-Sump Web Site: http://www.linuxnorth.org/raspi-sump

Source Code: https://github.com/alaudet/raspi-sump

Quick Start Guide: https://github.com/alaudet/raspi-sump/tree/master/docs

MIT License: https://github.com/alaudet/raspi-sump/blob/master/License

HC-SR04 User Manual: http://www.linuxnorth.org/raspi-sump/HC-SR04Users_Manual.pdf

Adam Lappin’s Byte Creation Blog:


http://www.bytecreation.com/blog/2013/10/13/raspberry-pi-ultrasonic-sensor-hc-sr04

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 67

LJ246-Oct2014.indd 67 9/17/14 4:49 PM


FEATURE U-Boot Environment Variables

U-Boot
Environment
Variables
A close look
at the anatomy
of the
U-Boot environment.
SACHIN VERMA

68 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 68 9/17/14 4:49 PM


D as U-Boot is a popular
bootloader for embedded
systems. This wide adoption of
U-Boot is hardly surprising given the
number of architectures and platforms
variables in a fruitful way. Production
images also need some versatility.
When a product’s OS images need
an upgrade, the bootloader must be
configurable to fetch the images from
it supports. Additionally, U-Boot has different sources.
a flexible compile-time configuration U-Boot has a number of system
setup. You can select different variables that you can modify to
features and drivers via config options achieve your desired results. For
and build a custom bootloader image example, on certain systems, initrd
for your platform. U-Boot’s flexibility images loaded on top of DDR may
is extended at runtime as well. Using not be accessible to the Linux kernel.
U-Boot environment variables, you can To counter this, you can instruct
influence the program execution flow. U-Boot to load initrd at a lower DDR
U-Boot comes with a CLI address. You can do this by setting the
(command-line interpreter), which initrd_high environment variable.
has basic scripting capabilities. This Another common situation during
scripting ability combined with the development is the presence of
U-Boot environment variables can different network configurations.
be used to create some powerful On your home setup, you may be
booting scenarios. The ability to working on a static IP configuration
manipulate program behavior using using NFS. But, when you are out
environment variables is beneficial for a demo at a client location,
for both development and production you only have DHCP available with
setups alike. During development, images kept on a TFTP server. U-Boot
people strive to test all possible paths is highly configurable for such
for loading and booting images for scenarios because it provides so
their platforms. So, you may try to many options. You can change the
load a Linux kernel image from a local network configuration, modify the
storage (Flash, SDcard, USB, eMMC IP addresses of image servers and
and so on), or access it over the gateway servers with the help of
network (NFS, TFTP and so on). environment variables. You
U-Boot simply makes your life easier could assign a console over serial
as a developer. You just need to tweak port, or you could use netconsole or
the scripts combining environment usbtty if you prefer.

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 69

LJ246-Oct2014.indd 69 9/17/14 4:49 PM


FEATURE U-Boot Environment Variables

So, What Is This U-Boot side shows that the variables have
Environment? been flattened and written in a
A simple answer to that question serialized form.
would be “a collection of name=value
pairs”. Here, “name” refers to the How Is the Environment Stored?
name of the environment variable U-Boot has two types of
to which you want to assign some persistent environments.
“value”. This “value” could be of any 1) Default Environment
type: string, hexadecimal, boolean and (Compiled-In, Read-Only): Every
so forth. Whatever type the value is, it U-Boot binary has a default built-in
is converted into a string before being environment of its own (Figure 2a).
stored in a linearized environment During compilation, a character array
data block. Each environment called default_environment is
variable pair (“name=value”) would embedded into the U-Boot image. This
be stored as a null-terminated character array stores the environment
string. So, the collection of many variables as a list of null-terminated
environment variables is nothing but strings with a double-null terminator.
a null-separated list with a double- The contents of this array are
null terminator. Figure 1 illustrates populated conditionally based on
how a list of strings is actually the config options selected for your
stored. The left-hand side is just a board. Environment variables that
logical representation of environment are commonly used can be enabled
variables, whereas the right-hand by defining the corresponding

Figure 1. Linearized Representation of Environment Variables

70 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 70 9/17/14 4:49 PM


Figure 2. (a) Type 1 Persistent Environment Read-Only, Embedded; (b) Type 2 Persistent
Environment User-Supplied, Read-Write Enabled

CONFIGs in your board’s config file to add certain environment


(include/configs/<YOUR_BOARD>.h). variables that are specific to your
Figure 3 lists some commonly used board or that just are convenient
options, which, once defined, would for you. You may, for instance,
make their way into the default want to embed the revision number
environment of your board. of the board into this environment.
Apart from the standard variables You could do that by defining
used across boards, you may want all of these variables in a macro

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 71

LJ246-Oct2014.indd 71 9/17/14 4:49 PM


FEATURE U-Boot Environment Variables

Figure 3. System variables defined in your board’s config become part of the default
environment.

called CONFIG_EXTRA_ENV_SETTINGS next) may be inaccessible


in your board’s config file: or must not be used due to
security concerns.
#define CONFIG_EXTRA_ENV_SETTINGS \

"board=" XSTR(BOARD) "\0" \ Q A user-supplied environment may


"load_addr=" XSTR(CONFIG_SYS_LOAD_ADDR) "\0" be inaccessible due to a storage
device malfunction or environment
Remember that the default data corruption.
environment is “read-only”, as it
is part of the U-Boot image itself. You shouldn’t keep too much
Vendors normally keep some data in this default environment,
essential system variables as part as it directly adds to the weight of
of this environment. the binary. Keep only critical system
There are some good reasons to variables in this environment.
keep a default environment as part 2) User-Supplied Environment
of the image: (Flashed in External Storage, Writable):
Typically, vendors flash an environment
Q Because it is read-only, you always data image to external storage present
have a default state to revert to. on your board. The format of this pre-
built environment is again the same—
Q During early bootup, a user- that is, a linearized list of strings, but
supplied environment (defined there is a 4-byte CRC header prefixed

72 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 72 9/17/14 4:49 PM


to it. This CRC is computed over the such possibilities (including power
environment data. Figure 2b illustrates failure), and for robustness in general,
such an environment blob with CRC you also can configure a redundant
data, followed by valid environment user environment. You can configure
data and an invalid one after that. The the location and size of this duplicate
total size of this environment data is environment data as well in your
fixed to CONFIG_ENV_SIZE during board’s config.
compilation. So, if your environment
usage exceeds this size, you would Saving Environment
need to recompile your U-Boot binary Out of the two default environments
after increasing CONFIG_ENV_SIZE . (default and user), only the user is
If you do not increase the size, writable. So, whenever you modify
U-Boot will refuse to save the a variable and issue a saveenv
environment variables. command, that variable ends up in
You may decide to keep this the user environment.
environment in external storage, When you do a saveenv , U-Boot
but you must configure the board’s does the following:
config accordingly. U-Boot must
know which storage method (and at Q Sorts the list of current
what offset) will be used to hold the environment variables.
user environment. U-Boot provides a
number of options to configure the Q Converts them to a linearized list
location of the environment data. of strings.
U-Boot has the infrastructure to access
environment data stored in serial Q Computes CRC over this data and
flashes, NVRAM, NAND, dataflash, burns the env back at its fixed
MMC and even UBI volumes. See location in storage.
the U-Boot documentation for more
information on how to use these Creating a Pre-Built User
CONFIG options. Since the default Environment
environment size has to be minimized, U-Boot provides a utility named
most of the environment variables mkenvimage that can be used to
are stored here. Certain storage generate an environment blob suitable
technologies like raw NAND flashes to be flashed. mkenvimage needs at
are inherently unreliable. To combat least two inputs to create the blob:

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 73

LJ246-Oct2014.indd 73 9/17/14 4:49 PM


FEATURE U-Boot Environment Variables

1. Environment variables in a text file This environment data blob must


(only one env “name=value” string be flashed at the predefined offset
on each line). in the storage device. You can use
U-Boot, Linux or any other flasher to
2. The size of the environment burn this blob.
blob in bytes (remember,
this must comply with the Relocation of Environment Data
CONFIG_ENV_SIZE you have to RAM
defined in your board’s config). During an early boot when
U-Boot has not relocated to RAM,
For example, if my env data file it uses the linearized form of
is called my_env_data.txt, and environment data (as shown in
the size of my desired env blob Figure 1). But once U-Boot has
is 16384 (16 KiB), I would use the relocated to RAM, this linearized
following command: form is no longer used. Instead,
U-Boot imports all such env data
$./tools/mkenvimage -s 16384 -o env_blob my_env_data.txt stored from persistent storage
into a RAM-resident hashtable. If
You can see the dump of the env the user-supplied environment is
blob using the od command: good (that is, the CRC is okay),
it is imported from Flash to RAM.
$ od -t x1c env_blob Otherwise, U-Boot imports the
default compiled-in environment
0000000 0d d2 49 96 62 61 75 64 72 61 74 65 3d 31 31 35 to this hashtable. Figure 4 shows
\r 322 I 226 b a u d r a t e = 1 1 5 how the user environment is
0000020 32 30 30 00 62 6f 6f 74 64 65 6c 61 79 3d 31 30 imported in to the hashtable,
2 0 0 \0 b o o t d e l a y = 1 0 whereas U-Boot along with its
0000040 00 6c 6f 61 64 5f 61 64 64 72 3d 30 78 34 30 30 default environment relocates to
\0 l o a d _ a d d r = 0 x 4 0 0 top of the RAM. If the user
0000060 30 30 30 30 30 00 00 00 00 00 00 00 00 00 00 00 environment is corrupt or
0 0 0 0 0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 inaccessible, U-Boot would import
0000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 the default environment in to
\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 the hashtable.
* The use of the RAM-resident data
0040000 structure (hashtable) is important for

74 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 74 9/17/14 4:49 PM


various reasons: on different variables while still
keeping the persistent storage form
Q It boosts performance, as you are simple (a linear list).
manipulating variables in RAM and
not in Flash. Once the environment has relocated
to RAM (into the hashtable), all
Q You have to manipulate data only commands operating on environment
in RAM and need not access some variables will be working only on this
slow Flash driver (and deal with the hashtable. U-Boot does not touch
associated complexity). the environment variables stored in
the persistent storage at all (unless it
Q It allows U-Boot to deploy type needs to save the env).
checks and access control attributes Each environment variable entry

Figure 4. The user environment is imported into a hashtable. If the user environment is
corrupt, the default environment is imported instead.

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 75

LJ246-Oct2014.indd 75 9/17/14 4:49 PM


FEATURE U-Boot Environment Variables

Figure 5. Hashtable representation of an environment variable. There is an associated


callback function, as well as a bitmap to store type and access control.

inside the hashtable is represented environment variable. If defined, this


by a data structure called a struct callback handler would be invoked
entry (Figure 5). Apart from the whenever any operation (like add,
members key and data , which delete or modify) is performed on this
correspond to “name” and “value” in environment variable.
the linearized representation of data,
you have members called callback How to Control/React to
and flags . flags is of integer type Environment Variable Modification?
and is used to implement type check At times you may want to do your own
and access control. callbacks is the runtime configurations. You may want
callback function associated with this to react (accept, reject or produce

76 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 76 9/17/14 4:49 PM


some side effects) to the changes Now, you need to establish a link
done to some environment variable. to this registered handler with an
For such use cases, U-Boot provides environment variable. Take a look at
a mechanism of deploying callback the struct entry in Figure 6. You can
handlers. You can associate a callback see that there is a member named
function with an environment variable. callback (a function pointer) for each
As a first step, you have to register environment variable. U-Boot would
a callback handler with U-Boot. This invoke this handler before committing
function would be called whenever the modified environment variable to
you do any modifications to the the hashtable. You can make this as-
environment variable. Figure 6 shows sociation of callback handler with the
sample code to register a callback with environment variable either at compile
U-Boot. You can place such handler time or at runtime. For compile-time
code in your board-specific file. association, you need to define the
The macro U_BOOT_ENV_CALLBACK config option #define
registers the callback function CONFIG_ENV_CALLBACK_LIST_DEFAULT
on_change_foo with the handler named foo:foo_h in your board’s config file.
foo_h . Your handler is now registered You also can do runtime association
with U-Boot with the name “foo”. as depicted in Figure 7. Here I have

Figure 6. Code a handler you want to call for an environment variable.

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 77

LJ246-Oct2014.indd 77 9/17/14 4:49 PM


FEATURE U-Boot Environment Variables

Figure 7. Associate the callback handler with the environment variable by


setting an environment variable .callbacks. Here, any modification of foo
would invoke on_change_foo().

created a new environment variable attempt to change it. Another such


.callbacks , which is a standard example is the MAC address of the
U-Boot system variable to make such device. Again, you want to keep that
associations. I have deployed a handler variable as read-only or, at worst,
named foo_h for the environment write-once. U-Boot supports different
variable foo . Once this registration access modifiers: any , read-only ,
is done, whenever you do some write-once and change-default
modification to variable foo , the (Figure 5). The U-Boot hashtable
function on_change_foo() would representation of environment
be invoked. You now can deliver your variables has a member LQWÁDJV
reaction to different types of actions (Figure 5). The member ÁDJV is used
( env_op_create , env_op_overwrite to keep a bitmap specifying the access
or env_op_delete ). permission associated with variable.
U-Boot already deploys similar So, whenever any modification attempt
handlers for managing console is done on variable, it must comply
changes, splash images and so on. with the access permission; otherwise,
U-Boot will reject the changes.
Type and Access Control of Another problem faced by users is
Environment Variables the basic sanity check of environment
There are certain environment variables variable type. Since the linearized form
that you want to use but do not of environment keeps only strings,
want to do casual modifications. For U-Boot needs to make sure that it can
example, say you have an environment do some kind of type check before
variable serial# ; you definitely want assigning a value to a variable. To
this variable to be read-only, and address this issue, U-Boot makes use of
you want automatic rejection of any some predefined types, such as “string”,

78 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 78 9/17/14 4:49 PM


Figure 8. Each environment variable can be associated with a type and access
permission in the environment variable .flags.

“decimal”, “hexadecimal”, “boolean”, address make use of type m . This will


“IP address” and “MAC address”. make U-Boot do a sanity check on the
There are corresponding codes for value entered by the user to confirm
these type modifiers: “s”, “d”, “x”, whether the value is indeed a valid
“b”, “i” and “m”. Again, U-Boot MAC address.
stores this type information of variables
in flags as a bitmap (Figure 5). Modifying the U-Boot User
You can associate “type” and Environment from Linux
“access control” to a variable either U-Boot environment variables can
at compile time or at runtime. be added, modified or deleted from
For compile-time association, you Linux as well. U-Boot provides a set
need to define a config #define of utilities called fw_printenv and
CONFIG_ENV_FLAGS_LIST_DEFAULT fw_setenv to do the job. First, you
foo:sr in your board file. For need to compile these utilities for
runtime association, you can define Linux. Figure 9 shows the compilation
an environment variable .flags steps for the utility. Here, I am cross-
(Figure 8). Here, I am associating an compiling it for the ARM platform. It
environment variable foo with type is a multi-call binary. So, you need to
s (meaning the value is a string) and make a symlink named fw_setenv to
access control r (meaning it is read- the binary fw_printenv .
only). Once deployed, if you try to To modify the environment, you
modify the variable foo , U-Boot will first need to boot in to Linux on
reject your request. Also, if a value is the target board. Next, you need to
not of specified “type”, your update to create a file called /etc/fw_env.config.
the environment variable will fail. This file contains all the information
Environment variables like MAC needed to specify the location of

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 79

LJ246-Oct2014.indd 79 9/17/14 4:49 PM


FEATURE U-Boot Environment Variables

Figure 9. Compiling fw_printenv/fw_setenv for an armv7 Host

Figure 10. My Configuration File

the environment data blob. Figure from the beginning of Flash and had
10 shows my configuration file. I a size of 0x40000. The size of each
kept my environment in an SPI Flash, sector of my Flash is 0x10000. This
which appeared as /dev/mtd0 to my is all the information I needed to
kernel. My environment blob was provide in order for the environment
configured at an offset of 0x80000 manipulation utilities to work.

80 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 80 9/19/14 9:23 AM


As soon as I keyed in the command reset the specified variables to a value
fw_printenv , I could see the variables from the default environment.
that I saved in the U-Boot user To restore the complete
environment appearing on my console. environment from the default,
You also can set the environment invoke the following command:
variables using fw_setenv . As shown
in Figure 10, I make use of a text file env default -a
(list.txt) containing the variables I
want to set. The format is simple. The The env command is very powerful;
first whitespace after a name acts as a you can use it import/export
delimiter, and the characters until the environment data from/to RAM.
end of line thereafter are considered
the value for the key. Final Comments
You can verify that the variables have The U-Boot environment can act as a
been set by executing fw_printenv . very useful runtime configuration tool.
These variables now would be visible When combined with scripting, it can
from U-Boot as well. make the arduous task of development
and testing boot scenarios much
Restoring the Default Environment simpler and more fun to do. Q
Sometimes after a lot of
environment variable changes, you Sachin Verma is a Linux kernel Engineer with
can corrupt the state. To restore STMicroelectronics Pvt Limited. His interest areas include
sanity and get the original values of the Linux kernel, virtualization and multicore computing.
the default environment, you can He can be reached at [email protected].
use the env command:

env default [-f] var [...] Send comments or feedback via


http://www.linuxjournal.com/contact
The above command would forcibly or to [email protected].

Resources
U-Boot Source Code: http://git.denx.de/u-boot.git

Das U-Boot Development Wiki: http://www.denx.de/wiki/U-Boot

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 81

LJ246-Oct2014.indd 81 9/17/14 4:50 PM


FEATURE Accessing the I/O Ports of the BeagleBone Black with Python

Accessing
the I/O Ports
of the
BeagleBone
Black
with Python
The BeagleBone Black is a wonderful little piece of
hardware. You could use it to send your next rocket to
Mars with just a few lines of Python.

SAMUEL BUCQUET

82 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 82 9/17/14 4:50 PM


T
he BeagleBone Black (BBB) is
a low-cost, low-power, credit-
card size (3.4" x 2.1") board
with a lot of features, and it costs
about $60. It sports a 1GHz Sitara
AM335x ARM Cortex-A8 (an ARMv7)
processor from Texas Instruments,
512MB of RAM, and it has all the
I/O capabilities you’d expect from a
typical microcontroller, such as access
to a CAN bus, SPI interface and i2c,
analog input, PWM and so on.
But, the board also holds two
PRUs, an HDMI video output, an SD
card slot and 100Mb Ethernet. This
makes the board a complete ARM
PC, fully compatible with Linux. As
icing on the cake, Beagle fancies an
open hardware philosophy: all of
the chips and designs are available
to the public. Figure 1. The BeagleBone Black board—
Right out of the box, you can use it isn’t she beautiful?
for the following:
Q A light desktop system if you
Q A great learning platform with add a 5VDCC external power
easy access to the connected supply, an HDMI cable, a screen,
hardware. You can play with keyboard and mouse.
almost all the functionalities
from the Web interface with the This article focuses on working
Bonescript language. Just plug in on a BBB from a Debian system
the board via the USB client on a with Python and some minimalism
PC, open the page of the board in mind. But, this is still a fully-
(http://192.168.7.2) and voilà! fledged Linux system, not an
(See http://beagleboard.org/ Arduino or microcontroller.
getting-started.) In this article, I describe how to

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 83

LJ246-Oct2014.indd 83 9/17/14 4:50 PM


FEATURE Accessing the I/O Ports of the BeagleBone Black with Python

There is no X session, no fancy Web interface,


just the good-old command line via SSH, and
the applications are launched automatically at
boot via /etc/rc.local.

access some of the I/O ports: accessible only through a network


connection. I chose to configure
Q The serial ports, to read and write them with the bare minimum, from
on devices with an RS232 interface the eLinux version. There is no X
like a GPS, for example. session, no fancy Web interface, just
the good-old command line via SSH,
Q The GPIOs, which allow you to and the applications are launched
trap or send TTL signals, drive automatically at boot via /etc/rc.local.
a relay, read a button status, They are used in a Unmanned Surface
and in particular, let you add a Vehicle (USV), and the interactions
PPS to Linux. with the operator are done through
a hardware control panel via a serial
Q The analog input voltage for line, through Web interfaces and
reading voltages coming from with networked applications. The
a lot of sensors. interactions with the hardware of the
USV are done through its many I/O
Q Components on the i2c bus: an ports, of course.
RTC handled by the system and a
DAC driven from your applications. Why Python?
Do I really need to tell you? Okay,
I finish the article explaining how we have enough processing power,
to use the BBB as a time server, so Python equals less code and more
thanks to a GPS. readability of the applications, and a lot
of useful modules already are available.
What Do We Use It For? All code and examples in this article are
In our project, the BBB boards are for Python 2.7, but it would be not very
embedded in small compartments, difficult to port it to Python 3.4.

84 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 84 9/17/14 4:50 PM


Danger: Important Usage Precautions
You need to take several precautions Q Do not apply any voltages that are
when working the expansion headers generated from external sources until
to prevent damage to the board: the SYS_RESETn signal is HI.

Q All voltage levels are 3.3V max. Application Q If voltages are generated from the
of 5V to any I/O pin will damage the VDD_5V signal, those supplies must
processor and void the warranty. not become active until after the
SYS_RESETn signal is HI.
Q Analog in voltages are 1.8V max.
Application of >1.8V to any A/D pin Q If you are applying signals from other
will damage the processor and void boards into the expansion headers,
the warranty. make sure you power up the board
after you power up the BeagleBone
Q Do not apply any voltages to any I/O pins Black or make the connections after
when the board is not powered on. power is applied on both boards.

Q Do not drive any external signals into the Q Powering the processor via its
I/O pins until after the SYS_RESETn signal I/O pins can cause damage to
is HI (3.3V). the processor.

Pimp My BBB fetch an image from armhf:


The Debian system: When we http://www.armhf.com/boards/
received our BBB boards in September beaglebone-black/#wheezy.
2013, they were pre-installed with Since March 2014, Debian
the Angstrom distribution. Thanks Wheezy (stable) is an official system
to the work of others who were also image available for the BeagleBone
attached to Debian, I quickly was able Black (rev B and C). For the latest
to keep playing with my favorite Linux images, see http://beagleboard.org/
system on my fresh BBBs. latest-images.
I installed the images provided by You can choose to upgrade to testing
eLinux, but you also can (or sid if you feel more adventurous) in

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 85

LJ246-Oct2014.indd 85 9/17/14 4:50 PM


FEATURE Accessing the I/O Ports of the BeagleBone Black with Python

order to enjoy more recent software. The BBB accepts booting from the
(See the Upgrading from Debian Stable internal memory, the eMMC or from
to Debian Testing sidebar.) an external SD. (See the Booting the
BBB from an SD Card sidebar.)
To test another version of the system,
Upgrading from simply download and write it on your
Debian Stable to SD. If you are satisfied with it, you have
Debian Testing the option to put it on the eMMC.
As the environment hosting our
First, update your system with apt-get BBBs is subject to strong vibrations, I
update && apt-get upgrade. chose to put my system in the eMMC
rather than on an SD.
Next, modify your /etc/apt/sources.list.d/ Flash the eMMC: In order to flash
debian.list file. Copy the lines with your new system to your eMMC,
wheezy or stable, and replace all download the flasher version from
occurrences of wheezy with jessie eLinux or the official one. Write it
on the copied lines. You can choose to your SD and boot your BBB from
testing instead of jessie if you the SD. The flashing process happens
want to keep on with the testing release automagically. You will have to wait
after jessie was made stable. less than ten minutes before the four
blue LEDs become steady, indicating
Then launch apt-get update && that the flashing is over. As the official
apt-get upgrade again, and if all firmware is much larger, the flashing
is well (it might take a long time will take a lot longer (45 minutes).
depending on your connection quality Danger: you need to power the
and the packages already installed), board with an external 5VDC power
run apt-get dist-upgrade. supply when flashing!
In order to use the armhf version,

Booting the BBB from an SD Card


Power off the board, then with the SD card inserted, hold down the S2 button near the
SD slot, apply power, and continue to hold down the button until the first LED comes on.

86 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 86 9/17/14 4:50 PM


If an NTP server is available to your BBB, good
for you, but as the BBB lacks a backed battery
RTC, it doesn’t retain date and time after
reboot, so you will have to take a few measures.

partition and format your SD card For interfacing with a GPS with a PPS:
following the armhf site instructions
at http://www.armhf.com/boards/ # apt-get install gpsd python-gps pps-tools \

beaglebone-black/bbb-sd-install. bison flex git-core

You then can download a recent armhf


rootfs archive (http://s3.armhf.com/ If you want to play with NTPd:
dist/bone/debian-wheezy-7.5-rootfs-
3.14.4.1-bone-armhf.com.tar.xz) # apt-get install ntp
and copy it to your SD. Then, when
booting from the SD, you likewise Configure the System
can copy your SD installation to What Time Is It? If an NTP server is
your eMMC. available to your BBB, good for you,
As the time of this writing (July 2014), but as the BBB lacks a backed battery
these Debian images come with Linux RTC, it doesn’t retain date and time
kernel 3.8.13. This version brought many after reboot, so you will have to take
improvements to accessing the BBB a few measures.
hardware by the kernel via sysfs. First, enter the date in UTC
Here is a list of packages I manually, before anything else:
recommend for working with the
board from the shell and from Python: # date -u 072314512014.30
Wed Jul 23 14:51:30 UTC 2014
# apt-get install kbd locales htop vim screen \

rsync build-essential git python-setuptools \ If your BBB must be isolated from


cython python-pip python-virtualenv python-dev \ an NTP server, one solution is to
manpages-{dev,posix{,-dev}} glibc-doc- \ add an RTC to the board, like a
reference python-serial python-smbus python- \ ds1307. (I will show how to add
lxml python-psutil i2c-tools one on the i2c bus.)

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 87

LJ246-Oct2014.indd 87 9/17/14 4:50 PM


FEATURE Accessing the I/O Ports of the BeagleBone Black with Python

Finally, if you are isolated and date saved when the system halted.
without an RTC module, try the To DHCP or Not to DHCP: If your
fake-hwclock package from the network hosts a DHCP server, you are
Debian repositories. It will allow fine; otherwise, you can configure
your clock to restart with the last your network card “static” in order to
avoid a big DHCP timeout when you
boot your BBB with the Ethernet cable
Configuring plugged in. (See the Configuring the
Network Card Static sidebar.)
the Network Card A Life Line (Serial Debug): More
Static often than not, the boards are in a
place where we can’t have a keyboard
Edit the /etc/network/interfaces file and display attached to them. We
and change the line reading: can work remotely by SSH, but if
something goes wrong, we need to
iface eth0 inet dhcp access the serial debug interface on
the board.
to: The serial interface available
through the USB connection to the
iface eth0 inet static board is not ready when you boot
address 192.168.1.101 with U-Boot—you can’t see the kernel
netmask 255.255.255.0 starting or intervene. That’s why we
broadcast 192.168.1.255 use the serial debug provided by the
gateway 192.168.1.254 J1 connector on the board, referred to
as ttyO0 by the system.
Then restart networking with: As a side note, this serial line can
be made available via Ethernet with
/etc/init.d/networking stop a cheap RS232IP converter if remote
/etc/init.d/networking start boot monitoring is needed.
Before connecting our BBB on a
Note: if you are editing the file via SSH, PC via this serial line, we need a
you will lose your connection right now! TTLRS232 converter. See some
You should do it with a keyboard and serial debug references on
display or the serial access instead. eLinux at http://elinux.org/
Beagleboard:BeagleBone_Black_Serial.

88 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 88 9/17/14 4:50 PM


You can purchase a PL2303HX
USB to RS232 TTL auto
converter module—they are
very cheap. Just make sure
the end of the cable is made
of jumper wires and not a
fixed connector (Figure 2).
This Code Chief’s Space
page provides a very
thorough step-by-step guide:
http://codechief.wordpress.com/
2013/11/11/beaglebone-black-
serial-debug-connection.
Serial Login into the
System: You probably are
familiar with the text consoles
with Login: that you make
appear with Ctrl-Alt-F{1..6}. Figure 2. An Essential Accessory—PL2303HX USB
We wanted the same, but to RS232 TTL Converter
through our serial debug.
So, we configured a tty on
the BBB allowing us to connect to it Finally, to connect us to the
via the serial line when it is booted. BBB through our serial debug
Just add this line (if it’s not already line from another PC with a
present) to the end of /etc/inittab: USBRS232 adapter:

T0:23:respawn:/sbin/getty -L ttyO0 115200 vt102 $ screen /dev/ttyUSB0 115200

And, make sure the kernel knows Access the Input/Output Ports
the correct console on which to The Serial Ports: As you
output its messages. In the /boot/ previously saw, the serial port
uboot/uEnv.txt file, it should read: must be accessed with a TTL/RS232
adapter. In our project, we re-used
console=ttyO0,115200n8 some old Maxim MAX3232s to
#console=tty do it, and it works, of course,

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 89

LJ246-Oct2014.indd 89 9/17/14 4:50 PM


FEATURE Accessing the I/O Ports of the BeagleBone Black with Python

Figure 3. The Board “bbbO2” in situ with three serial ports and the serial debug
port, a temperature sensor on AIN0, a water detector on GPIO_48, a PPS input on
GPIO_49 and a POWER_RESET button.

for the other UARTs available on Q UART5 can’t be used altogether


the board. with the HDMI output.
The BBB comes with six UARTs, but
three of them can’t be addressed by So UART1, UART2 and UART4
our applications: are the ones available, and they
are addressed, respectively, as
Q UART0 is the serial debug on J1. /dev/ttyO1, /dev/ttyO2 and /dev/ttyO4.
Note that only UART1 and UART4
Q UART3 lacks an RX line. have CTS and RTS pins.

90 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 90 9/17/14 4:50 PM


Figure 4. Our CAPE with Two MAX3232s

Load the CAPE files for each UART: # dmesg |grep tty

...

for i in {1,2,4} [ 1.541819] console [ttyO0] enabled

do [ 286.489374] 48022000.serial: ttyO1 at MMIO \

echo BB-UART$i > /sys/devices/bone_capemgr.*/ \ 0x48022000 (irq = 89) is a OMAP UART1

slots [ 286.627996] 48024000.serial: ttyO2 at MMIO \

done 0x48024000 (irq = 90) is a OMAP UART2

[ 286.768652] 481a8000.serial: ttyO4 at MMIO \

The output of dmesg should show 0x481a8000 (irq = 61) is a OMAP UART4

a correct initialization:

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 91

LJ246-Oct2014.indd 91 9/17/14 4:50 PM


FEATURE Accessing the I/O Ports of the BeagleBone Black with Python

Now you can ask the kernel to


Passing Arguments load them at boot time. Edit
at Boot Time /boot/uboot/uEnv.txt and modify
the line with optargs , like this:
To give command-line options to the
kernel, modify the optargs variable in optargs=capemgr.enable_partno=BB-UART1, \
the /boot/uboot/uEnv.txt file. Only one BB-UART2,BB-UART4
optargs line is allowed, so if you need
several options passed to the kernel, just (See the Passing Arguments at
add them separated by a space like this: Boot Time sidebar.)
Okay, but Does It Work? To
optargs=quiet fixrtc \ test the serial lines, we just have
capemgr.enable_partno=BB-ADC,BB-UART1,\ to connect two of them together
BB-UART2,BB-UART4 (Figure 5).
Now, launch a screen session

Figure 5. Direct
Connection between
UART1 and UART4

92 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 92 9/17/14 4:50 PM


Table 1. Direct Connection of UART1 with UART4

UART4_Tx PIN __13__ of P9 A PIN __26__ of P9 UART1_Rx

UART4_Rx PIN __11__ of P9 A PIN __24__ of P9 UART1_Tx

on UART1 with screen /dev/ttyO1 check that what you type in one
115200 , split your window with a window appears in the other
Ctrl-A S, move to the next window (Figure 6).
with Ctrl-Tab, open a screen on From now on, you can use
UART4 with Ctrl-A :, then type the python-serial module to
screen /dev/ttyO4 115200 , and read and write on your serial ports,

Figure 6. ttyO1 and ttyO4 Screen Session

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 93

LJ246-Oct2014.indd 93 9/17/14 4:50 PM


FEATURE Accessing the I/O Ports of the BeagleBone Black with Python

like this: board to receive a signal, read a


frequency on input or drive a relay
import time on output.
from serial import Serial First we had to understand the
mapping between the pin on the
ctrl_panel = Serial(port=comport, baudrate=9600, P8 and P9 connectors and the GPIO
bytesize=8, parity='N', stopbits=1, timeout=0.25 ) numbers as seen by the kernel. The
BBB System Reference Manual gives
# send a commande the Expansion Header P9 pinout
ctrl_panel.write(pupitre_commande) (http://elinux.org/Beagleboard:
BeagleBoneBlack#Hardware_Files).
# read an answer For each GPIO, the name is made
buff = ctrl_panel.read(answer_size) up of the GPIO controller number
# as the serial port is configured non-blocking between 0 and 3 and the pin number
# with 'timeout=0.25', we make sure all the ON THE 3ITARA !-!: 4HE KERNEL
# bytes asked for are received. numbers the GPIO pin with PIN +
while len(buff) < answer_size: (GPIO controller number * 32). If
n = len(buff) we pick the GPIO1_16 on the pin 15
b = ctrl_panel.read(answer_size-n) of the P9 connector, the kernel will
buff += b see it as GPIO_48 (16+(1 * 32)). See
print "------",n,"------" Figure 7 to read the direct mapping
time.sleep(0.02) for all the GPIOs.
print "Serial IN: ", And, you can find a similar
print ' '.join(['%02X' % ord(c) for c in buff]) table for each kind of I/O port of
the BBB on this Cape Expansion
The python-serial module is Headers page: http://elinux.org/
quite efficient. We managed to Beagleboard:Cape_Expansion_Headers
read two serial ports refreshed at Operate the GPIO: The gpio_sysfs.txt
50Hz plus a third at 5Hz (on the file, provided with your kernel
same board and simultaneously) documentation, explains how to
with a few glitches between the work with GPIOs with a Linux kernel
timestamps, and the CPU load (https://www.kernel.org/doc/
stayed below 50%. Documentation/gpio/sysfs.txt).
The GPIO: The General-Purpose These steps are for Linux kernel
Input or Output pins allow the version 3.8.13. Each GPIO must be

94 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 94 9/17/14 4:50 PM


Figure 7. Mapping GPIO Kernel Numbers with P8 and P9 Pinouts

enabled independently, so for the # echo both > /sys/class/gpio/gpio48/edge


GPIO_48 on P9_15:
If you want to output signals,
# echo 48 > /sys/class/gpio/export you can choose “out” or one of
“high” or “low” (telling when the
Next, choose the way it will operate. signal is active):
If you want to process input signals:
# echo high > /sys/class/gpio/gpio48/direction

# echo in > /sys/class/gpio/gpio48/direction


And to stop emitting the signal:
Then choose if you want to detect a
“rising” or “falling” edge or “both”: # echo 0 > /sys/class/gpio/gpio48/value

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 95

LJ246-Oct2014.indd 95 9/17/14 4:50 PM


FEATURE Accessing the I/O Ports of the BeagleBone Black with Python

At the end, release the GPIO: line 58—there is a link to my GitHub


page with all the code for this article
# echo 48 > /sys/class/gpio/unexport in the Resources section.)
A Special Case, the PPS Signal:
Wait for a Signal on a GPIO from A GPS often delivers a PPS (Pulse
Python: We connected an optical Per Second) signal in order to
water detector to one of our BBBs synchronize with good accuracy
inside an enclosure, on the GPIO_48 the timing NMEA sentences, like
(P9_15) (Figure 3). The water detector '0:$! 4HE 003 SIGNAL IS A 44,
sends a TTL signal if there is water we can connect to a GPIO; we
passing through its lens. Here is how chose GPIO_49 (P9_23). Once
we wait for an event describing water wired, we check whether the signal
presence from Python using the is present and can be read:
BBB_GPIO class from bbb_gpio.py:
# echo 49 > /sys/class/gpio/export
from bbb_gpio import BBB_GPIO # echo in > /sys/class/gpio/gpio49/direction
# echo rising /sys/class/gpio/gpio49/edge
water = BBB_GPIO(48,gpio_edge='both',\ # cat /sys/class/gpio/gpio49/value
active_low=True) 1
for value in water:
if value: Be careful as to the output voltage
print "Water detected !" of the PPS, as the GPIOs of the BBB
else: accept a TTL of 3.3V max.
print "No more water !" The PPS signal is also a special
input understood by the Linux kernel.
The BBB_GPIO class is a generator. In order to enable our GPIO input
For each iteration, we wait for a as a PPS, we have to compile a dts
change on the GPIO and return (Device Tree Source file) into a dtbo
in value the GPIO status. When (Device Tree Binary Object file) with
the GPIO is waiting for an event, the dtc (Device Tree Compiler) tool
we don’t want to be polling (see the GPS-PPS-P9_23-00A0.dts file
aggressively on the system, but to on my GitHub page):
be awakened only when the event
occurs. That’s what the poll() # ./dtc -O dtb -o GPS-PPS-P9_23-00A0.dtbo -b 0 \

system call does. (See bbb_gpio.py -@ GPS-PPS-P9_23-00A0.dts

96 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 96 9/17/14 4:50 PM


Fetching a Good dtc
This one is tricky. One year ago, I successfully downloaded and patched dtc, but now
the patch is not synchronized with the versions of dtc I can find. Thanks to Robert
Nelson (https://eewiki.net/display/linuxonarm/BeagleBone+Black#BeagleBoneBlack-
Upgradedistro%22device-tree-compiler%22package), you just have to download and
execute his version:

# wget -c https://raw.github.com/RobertCNelson/\
tools/master/pkgs/dtc.sh
# chmod +x dtc.sh
# ./dtc.sh

The script will fetch the tools on-line, so if your BBB is not connected, you can compile
your dtbo file from another Linux machine.

Danger: the dtc program available # ppstest /dev/pps0

in Debian Wheezy is not able to write trying PPS source "/dev/pps0"

a dynamically loadable dtbo file. It found PPS source "/dev/pps0"

may lack the -@ option, depending ok, found 1 source(s), now start fetching data...

on the system you installed. Check source 0 - assert 1391436014.956450656, sequence:\

the output of dtc -h and whether 202 - clear 0.000000000, sequence: 0

the -@ is present. (See the Fetching a source 0 - assert 1391436015.956485865, sequence:\

Good dtc sidebar.) 203 - clear 0.000000000, sequence: 0

The dtbo file produced will then be source 0 - assert 1391436016.956517240, sequence:\

loaded to the kernel: 204 - clear 0.000000000, sequence: 0

source 0 - assert 1391436017.956552407, sequence:\

# cp GPS-PPS-P9_23-00A0.dtbo /lib/firmware 205 - clear 0.000000000, sequence: 0

# echo GPS-PPS-P9_23 > /sys/devices/\ ...

bone_capemgr.*/slots (Ctrl-C to end)

To verify that the PPS is seen You see here a signal received at
correctly by the Linux kernel, you need 1Hz, with a timestamp jitter less
the pps-tools package installed: than 1ms.

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 97

LJ246-Oct2014.indd 97 9/17/14 4:50 PM


FEATURE Accessing the I/O Ports of the BeagleBone Black with Python

The i2C Bus: Two i2c buses on Table 2. ds1307 Wiring on the BBB i2c_2 Bus
the BBB are available. The kernel sees
P9 ds1307
them as i2c-0 for I2C1 on P9_17(SCL)
and P9_18(SDA), and i2c-1 for I2C2 pin 1 GND
on P9_19(SCL) and P9_20(SDA). pin 5 5VCC
Add an RTC to the BBB: The pin 19 SDA
DS1307 or the DS3231 are RTC pin 20 SCL
modules with a battery keeping the
clock running when there is no power.
The ChronoDot RTC (with a ds3231) is the two 2.2k resistors (Figure 8). The
much more accurate, and the ds1307 internal resistors of the BBB i2c bus
is much less expensive. will then be used.
Wire the RTC on i2c: You can Danger: if you power the BBB over
feed the 5VDCC of the board to the USB, use P9_7 (SYS 5V) instead.
RTC module as long as you clip out Enable the New RTC: Declare the

Figure 8. The Adafruit RTC ds1307 Module Wired on the BBB

98 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 98 9/17/14 4:50 PM


new RTC to the kernel: permanently, as soon as the system
boots, modify the /etc/init.d/hwclock.sh
# echo ds1307 0x68 > file with this little dirty hack. Add to
/sys/class/i2c-adapter/i2c-1/new_device the end of the file:
[ 73.993241] rtc-ds1307 1-0068: rtc core: \

registered ds1307 as rtc1 echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/\

[ 74.007187] rtc-ds1307 1-0068: 56 bytes \ new_device

nvram HCTOSYS_DEVICE=rtc1

[ 74.018913] i2c i2c-1: new_device: \ hwclocksh "$@"

Instantiated device ds1307 at 0x68

Danger: I had to comment the


Push the current UTC date to udev part of the file, and I’m still
the ds1307: trying to figure how to do that part
in a cleaner way:
# hwclock -u -w -f /dev/rtc1
#if [ -d /run/udev ] || [ -d /dev/.udev ]; then

Verify the clock: # return 0

#fi

# hwclock --debug -r -f /dev/rtc1

hwclock from util-linux 2.20.1 If Something Goes Wrong


Using /dev interface to clock. with a Component on i2c: If the
Last drift adjustment done at 1406096765 seconds \ kernel can’t see the ds1307, for
after 1969 example, try to detect it on the i2c
Last calibration done at 1406096765 seconds after\ bus with this:
1969

Hardware clock is on UTC time # i2cdetect -y -r 1

Assuming hardware clock is kept in UTC time. 0 1 2 3 4 5 6 7 8 9 a b c d e f

Waiting for clock tick... 00: -- -- -- -- -- -- -- -- -- -- -- -- --

...got clock tick 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Time read from Hardware Clock: 2014/07/23 15:42:51 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Hw clock time : 2014/07/23 15:42:51 = 1406130171 \ 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

seconds since 1969 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Wed Jul 23 17:42:51 2014 -0.438131 seconds 50: -- -- -- -- UU UU UU UU -- -- -- -- -- -- -- --

60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --

To benefit from the new RTC 70: -- -- -- -- -- -- -- --

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 99

LJ246-Oct2014.indd 99 9/17/14 4:50 PM


FEATURE Accessing the I/O Ports of the BeagleBone Black with Python

If 68 is not here, but UU is pin on the MCP4725. Thus, you can


printed, the kernel already keeps use two MCP4725s on the same bus,
hold of the ds1307 with a driver. so with two i2c buses, you easily can
Recheck your kernel messages and output four independent voltages
try to unload the driver for the from your BBB.
ds1307 with the following, and Write a Value to the MCP4725:
then retry: To set a voltage ouput on the
MCP4725, write to the i2c bus. So
# echo 0x68 > for a value of 0x0FFF (4095) at the
/sys/class/i2c-adapter/i2c-1/delete_device address 0x60 on i2c-1:
# rmmod rtc_ds1307
$ i2cset -f -y 1 0x60 0x0F 0xFF
If this is just -- instead of 68 ,
recheck your wiring. Write to the MCP4725 from
Add a DAC, the MCP4725, Python: The Python module to
on i2c: The MCP4725 is a 12-bit access the MCP4725 (see the
digital analog converter, allowing i2c_mcp4725.py file on my GitHub
you to output a voltage from a page) is a bit more complex,
numerical value between 0 and because we try to handle all the
4095 (2 12 - 1). Its EEPROM allows functionalities of the DAC. It
you to store a value in a register depends on the python-smbus
that becomes the default value package. Here is how we use it:
as soon as the DAC is powered
on. When you want to drive a import time

motor with it, you then can store from smbus import SMBus

a default safe value in EEPROM, from i2c_mcp4725 import MCP4725

and then make certain that when


the power is restored, your motor dac = MCP4725(SMBus(1), int('0x60', 16))

doesn’t start at full speed. safe_value = 2047

The wiring is almost identical # write to the DAC and store the value in EEPROM

as for the ds1307 module; take dac.write_dac_and_eeprom(safevalue, True)

the 3.3V VDD (P9_3) as VREF


for the MCP4725. # read the value ouput by the dac and the content

The MCP4725 address on i2c is # of its EEPROM

0x60 or 0x61; select it with the A0 dac.read_and_eeprom()

100 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 100 9/17/14 4:50 PM


print dac send is:

# send a mid-ramp 1.69V to 3.38V

for value in range(2048,4096):

# write to the DAC without storing value The vRef for the AIN is always 1.8V, so
dac.write_dac_fast(value) in order to convert our 12-bit numerical
time.sleep(0.2) value into a voltage reading, we have:

Python subtleties allow us simply to


do this:
For a numerical raw value “out”, we
# send a new value to output a voltage must read a numerical raw value “in”,
dac(new_value) such as:
# check the value currently ouput by the DAC
current_value = dac()

How to Read and Verify the Read AIN0 from sysfs: If the BBB
Output Voltage? The BBB has ADC kernel driver is not loaded, load
seven analog input ports named it now with:
AIN{0..6}. They are 12-bit analog
digital converters, and they accept # echo BB-ADC /sys/devices/bone_capemgr.8/slots

a max voltage of 1.8V. To read


the voltage from an analog input, If you need it loaded automatically at
wire the GND (P9_1) and the + of boot, do like we did for the BB-UARTs
the voltage you want to measure. (see the Passing Arguments at Boot
We re-inject the output of our Time sidebar).
MCP4725 in AIN0. In this case, the To read a raw numerical value on AIN0:
VDD for the MCP4725 is 3.38V
(the 3.3V of the PIN 3 and 4 of $ cat /sys/bus/iio/devices/iio\:device0/\
P9). We divide it by two with two in_voltage0_raw
resistors, as it must not be greater 3855
than 1.8V. And, we wire the output $
of the resistors to P9_39 (AIN0).
The vRef for the MCP4725 is Is the Input Consistent with the
VMAX (3.38V), so the voltage we Output? We can see that the value

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 101

LJ246-Oct2014.indd 101 9/17/14 4:50 PM


FEATURE Accessing the I/O Ports of the BeagleBone Black with Python

Table 3. Discrepancies between DAC Output and ADC Input

OUT raw value IN theoretical raw value IN read raw value


255 239 243
2047 1927 1929
3839 3614 3613
4095 3855 3835

sent to the MCP4725 is correctly configuration. Our control loop driving


reread on AIN0 (Table 3). our propeller’s speed can better handle
The values match, but there still the re-injection of the output voltage.
are some inaccuracies. We need to Read AIN0 from Python: To read
record a table of corresponding values a temperature sensor wired on AIN0
between the MCP4725 and AIN0 in this giving 1mV for 0.1°C, we use the

Figure 9. Bipolar Operation Circuit

102 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 102 9/17/14 4:50 PM


BBB_AIN class from the bbb_ain.py file at each iteration. The only catch is the
(see my GitHub page): error “Resource Temporarily unavailable”
(error=11), which may occur occasionally.
import time How We Use It: To pilot our
from bbb_ain import BBB_AIN propellers, we need to output a
voltage between –10 V and 10 V. We
tempe = BBB_AIN(0, valeurmax=180) use two MCP4725s on i2c_1: one
for value in tempe: with A0 on V~SS~ (0x60) and the
print "%.4f" % value other with A0 on V~DD~ (0x61). We
time.sleep(0.5) use a bipolar operation type circuit to
output –10V/10V from the MCP4725’s
Once again, we use a generator. At 0/3.3V output (Figure 9).
each iteration, we read a value on the The MCP4725 outputs are re-injected
AIN. There is no interrupt mechanism on into AIN0 and AIN1 in order to improve
the AIN; we read at the frequency of the the control loop accuracy. And, we
“for loop”—that’s why we have to pause read the speed of the propellers back

Figure 10. The Box in Charge of the Propellers

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 103

LJ246-Oct2014.indd 103 9/17/14 4:50 PM


FEATURE Accessing the I/O Ports of the BeagleBone Black with Python

with two frequency/voltage converters, good RTC wired to the BBB for a
which we feed to AIN2 and AIN3 real NTP server, so choose one
(Figure 10). like the Adafruit Chronodot
The BBB as Time Server from a (http://www.adafruit.com/
GPS: What if you put together the products/255) rather than the
interface to your GPS, the NTP server simple DS1307.
of your Linux machine equipped with GPSd: Now that you know how to
an RTC and the accuracy provided handle a serial port, you can install
with the PPS signal? You can build the GPSd software. GPSd connects to
an NTP server for other CPUs in your a local GPS, as the one we wired to
network, and with good accuracy, as UART4, and serves GPS data to clients:
soon as the GPS is aligned.
Keep in mind that you need a # apt-get install gpsd python-gps gpsd-clients

Figure 11. A Session with gpsmon

104 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 104 9/17/14 4:50 PM


Edit the /etc/default/gpsd.conf file, access my GPS, like this:
modify it to connect to your serial
port (here ttyO4), and tell GPSd to $ ipython

listen to all network interfaces ( -G ): Python 2.7.8 (default, Jul 22 2014, 20:56:07)

Type "copyright", "credits" or "license" for more \

START_DAEMON="true" information.

GPSD_OPTIONS="-G -n" ...

DEVICES="/dev/ttyO4" In [1]: from gpsd_client import GPSd_client

USBAUTO="false"
GPSD_SOCKET="/var/run/gpsd.sock" In [2]: gps = GPSd_client('bbb02')

Then restart it: In [3]: for gpsdata in gps:

print gpsdata

# /etc/init.d/gpsd stop ...:

# /etc/init.d/gpsd start GPS(time=u'2014-07-24T08:53:54.000Z', latitude=\

48.3938485,longitude=-4.505373, altitude=\

By now, your GPS is available to all 30.4, sog=0.051, cog=187.71, ept=0.005, mode=3)

clients on your network, and you can GPS(time=u'2014-07-24T08:53:55.000Z', latitude=\

TRY TO CONNECT TO '03D WITH 1')3 OR 48.393848, longitude=-4.505373167, altitude=\

OpenCPN, for example, but a rather 30.3, sog=0.067, cog=194.8, ept=0.005, mode=3)

simple solution is with gpsmon. On GPS(time=u'2014-07-24T08:53:56.000Z', latitude=\

another machine with the gpsd-clients 48.393847667, longitude=-4.505373167, altitude=\

package installed, launch: 30.2, sog=0.062, cog=184.8, ept=0.005, mode=3)

GPS(time=u'2014-07-24T08:53:57.000Z', latitude=\

$ gpsmon tcp://bbb02:2947 48.393847333, longitude=-4.505373167, altitude=\

30.2, sog=0.036, cog=189.77, ept=0.005, mode=3)

And, you should see a screen like GPS(time=u'2014-07-24T08:53:58.000Z', latitude=\

the one shown in Figure 11. 48.393847167, longitude=-4.505373, altitude=\

Connect to GPSd from Python: 30.1, sog=0.041, cog=175.46, ept=0.005, mode=3)

The python-gps package provides ^C---------------------------------------------\

what you need, but the dialog ------------------------------

sequence with GPSd is not trivial. I


wrote a little Python class GPSd_client Again, we use a generator. For
(see the gpsd_client.py file on my each iteration, the GPSd_client class
GitHub page) in order to be able to opens a session with GPSd, listens

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 105

LJ246-Oct2014.indd 105 9/17/14 4:50 PM


FEATURE Accessing the I/O Ports of the BeagleBone Black with Python

for a report with position and time fudge 127.127.22.0 flag2 0 flag3 1 refid PPS

information, closes the session and


returns a namedtuple with the # allow ntpd to serve time if GPS is OFF

information we wanted. tos orphan 5

NTPd: One of these GPSd clients


is NTP. NTPd processes the NMEA The 0.040 might need adjusting
GPS timing sentences to set the relative to your GPS, but it’s a safe
date and uses the PPS signal to bet. The 127.127.22.0 is the NTPd
be more accurate. The handling reference to /dev/pps0. If your GPSd
of the PPS signal is available only declares a /dev/pps to the kernel, your
in the development versions of real PPS signal might become /dev/pps1.
NTPd, not the version in the Debian The bottom line is try to load your PPS
repositories. The version we installed signal before starting GPSd.
is ntp-dev-4.2.7p416. Grab it and Verify that NTPd has started and
compile it like this: serves the time with ntpq:

# apt-get install libcap-dev # ntpq -p

# wget http://www.eecis.udel.edu/~ntp/ntp_spool/\ remote refid st t when poll \

ntp4/ntp-dev/ntp-dev-4.2.7p416.tar.gz reach delay offset jitter

# tar xf ntp-dev-4.2.7p416.tar.gz ================================================\

# cd ntp-dev-4.2.7p416/ ==============================

# ./configure --enable-all-clocks --enable-\ *SHM(0) .GPS. 0 l 13 64 \

linuxcaps 377 0.000 -50.870 0.886

# make oPPS(0) .PPS. 0 l 12 64 \

377 0.000 -1.419 0.128

Modify the /etc/ntp.conf file for


the connection to GPSd and the PPS You can see here that .GPS. is
signal listening: identified as the system peer by
ntpd (*), and .PPS. is also correctly
# Server from shared memory provided by gpsd recognized and valid (o).
server 127.127.28.0 prefer

fudge 127.127.28.0 time1 0.040 refid GPS The PRU, a Very Hot Topic
The two Programmable Realtime
# Kernel-mode PPS ref-clock for the precise seconds Units of the BBB can work
server 127.127.22.0 independently of the main CPU

106 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 106 9/17/14 4:50 PM


on I/O ports, AINs and PWM. They acquainted with usually.
are sophisticated enough to share I want to thank my co-worker,
memory with a CPU up to 300MB, Rodolphe Pellaë, whose skills
have a rich instruction set and can in electronics were essential in
trigger or receive interrupts. connecting all the components to the
Recently, some hard workers board. He did our four homemade
managed to make the use of the Capes in no time and did them well.
BBB PRUs more accessible. And, The community orbiting the BBB
there is this great promising is large with a lot of good on-line
GSOC 2014 coming, BeagleLogic: resources. We managed to learn
https://github.com/abhishek-kakkar/ some complex stuff in very little
BeagleLogic/wiki. time and with almost no confusion,
See also the work of Fabien Le because we can profit from the work
Mentec: “Using the BeagleBone of those people and from the Linux
PRU to achieve real time at low cost” and Python ecosystems. Q
(http://www.embeddedrelated.com/
showarticle/586.php). Samuel Bucquet is a system developer and a sysadmin on
robotic platforms in the French DOD. He is married with four kids
Conclusion and lives in Brest, France, and he is a longtime Linux aficionado.
The BeagleBone Black is a very fun
platform to play with. As a Linux
sysadmin for nearly 20 years, I’m Send comments or feedback via
very comfortable using it to access http://www.linuxjournal.com/contact
electronic hardware I’m not so well or to [email protected].

Resources
You will find the source of the Python code used in this article on my GitHub account:
https://github.com/samgratte/BeagleboneBlack.

PyBBIO is a Python Library for the BBB mimicking the Arduino IO access by Alexander Hiam:
https://github.com/alexanderhiam/PyBBIO.

Of course, there is also the Python Adafruit Library, initially for the Raspberry Pi, now for
the BBB: https://github.com/adafruit/adafruit-beaglebone-io-python.

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 107

LJ246-Oct2014.indd 107 9/17/14 4:50 PM


KNOWLEDGE HUB

WEBCASTS
Learn the 5 Critical Success Factors to Accelerate
IT Service Delivery in a Cloud-Enabled Data Center
Today's organizations face an unparalleled rate of change. Cloud-enabled data centers are increasingly seen as a way to accelerate
IT service delivery and increase utilization of resources while reducing operating expenses. Building a cloud starts with virtualizing
your IT environment, but an end-to-end cloud orchestration solution is key to optimizing the cloud to drive real productivity gains.

> http://lnxjr.nl/IBM5factors

Modernizing SAP Environments with Minimum


Risk—a Path to Big Data
Sponsor: SAP | Topic: Big Data
Is the data explosion in today’s world a liability or a competitive advantage for your business? Exploiting massive amounts
of data to make sound business decisions is a business imperative for success and a high priority for many firms. With rapid
advances in x86 processing power and storage, enterprise application and database workloads are increasingly being moved
from UNIX to Linux as part of IT modernization efforts. Modernizing application environments has numerous TCO and ROI
benefits but the transformation needs to be managed carefully and performed with minimal downtime. Join this webinar to
hear from top IDC analyst, Richard Villars, about the path you can start taking now to enable your organization to get the
benefits of turning data into actionable insights with exciting x86 technology.

> http://lnxjr.nl/modsap

WHITE PAPERS
White Paper: JBoss Enterprise Application
Platform for OpenShift Enterprise
Sponsor: DLT Solutions
Red Hat’s® JBoss Enterprise Application Platform for OpenShift Enterprise offering provides IT organizations with a simple and
straightforward way to deploy and manage Java applications. This optional OpenShift Enterprise component further extends
the developer and manageability benefits inherent in JBoss Enterprise Application Platform for on-premise cloud environments.

Unlike other multi-product offerings, this is not a bundling of two separate products. JBoss Enterprise Middleware has been
hosted on the OpenShift public offering for more than 18 months. And many capabilities and features of JBoss Enterprise
Application Platform 6 and JBoss Developer Studio 5 (which is also included in this offering) are based upon that experience.

This real-world understanding of how application servers operate and function in cloud environments is now available in this
single on-premise offering, JBoss Enterprise Application Platform for OpenShift Enterprise, for enterprises looking for cloud
benefits within their own datacenters.

> http://lnxjr.nl/jbossapp

108 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 108 9/17/14 4:50 PM


KNOWLEDGE HUB

WHITE PAPERS
Linux Management with Red Hat Satellite:
Measuring Business Impact and ROI
Sponsor: Red Hat | Topic: Linux Management

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to de-
ploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT
organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility
workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows
in importance in terms of value to the business, managing Linux environments to high standards of service quality —
availability, security, and performance — becomes an essential requirement for business success.

> http://lnxjr.nl/RHS-ROI

Standardized Operating Environments


for IT Efficiency
Sponsor: Red Hat
The Red Hat® Standard Operating Environment SOE helps you define, deploy, and maintain Red Hat Enterprise Linux®
and third-party applications as an SOE. The SOE is fully aligned with your requirements as an effective and managed
process, and fully integrated with your IT environment and processes.

Benefits of an SOE:

SOE is a specification for a tested, standard selection of computer hardware, software, and their configuration for use
on computers within an organization. The modular nature of the Red Hat SOE lets you select the most appropriate
solutions to address your business' IT needs.

SOE leads to:

s $RAMATICALLY REDUCED DEPLOYMENT TIME

s 3OFTWARE DEPLOYED AND CONFIGURED IN A STANDARDIZED MANNER

s 3IMPLIFIED MAINTENANCE DUE TO STANDARDIZATION

s )NCREASED STABILITY AND REDUCED SUPPORT AND MANAGEMENT COSTS

s 4HERE ARE MANY BENEFITS TO HAVING AN 3/% WITHIN LARGER ENVIRONMENTS SUCH AS

s ,ESS TOTAL COST OF OWNERSHIP 4#/ FOR THE )4 ENVIRONMENT

s -ORE EFFECTIVE SUPPORT

s &ASTER DEPLOYMENT TIMES

s 3TANDARDIZATION

> http://lnxjr.nl/RH-SOE

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 109

LJ246-Oct2014.indd 109 9/17/14 4:50 PM


EOF
Learn DOC SEARLS

GNU/Linux
the Fun Way
A great “hello world” from rural Utah.

S
ometimes a gift just falls in here’s how it went.
your lap. This month, it came
in the form of an e-mail out DS: What got you going on this?
of the blue from Jared Nielsen, one
of two brothers (the other is J.R. JN: Growing up, we wanted to be
Nielsen) who created The Hello making creative media, such as
World Program, “an educational games, videos, animations, etc.,
web series making computer but in the days before the Internet,
science fun and accessible to all” training was either difficult or
(http://www.thehelloworldprogram.com). expensive to find, especially in
If it had been just that, I might not small-town Utah. We figured things
have been interested. out on our own, through trial
But when I looked at it, I saw it and error, visits to the library and
was hugely about Linux. And the countless hours watching PBS. The
human story was interesting too. Hello World Program is the show
Wrote Jared, “Working in rural Utah we wish we watched as kids.
with minimal resources, we combine
technology and craft to make DS: Do you or your brother have
educational yet entertaining videos kids yourselves?
and tutorials. Learn to code with
our cute and clever puppets.” So I JN: Neither of us have kids, but we are
said I’d like to interview them, and both kids at heart.

110 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 110 9/17/14 4:50 PM


EOF

DS: How long have you been the air: https://www.flickr.com/


doing it? search/?text=Utah&user_id=52614599
%40N00&sort=interestingness-desc.)
JN: We started kicking around
ideas for an educational Web series JN: Our home is Richfield, the gateway
in January 2012. Then we sat on to adventure in Southern Utah.
our hands for a few months. We
published our first video, “What Is DS: Cool! I shot your house
a Robot?” in May of that year. Since from the sky just this past
then, The Hello World Program has May 4th, in fact. (Here it is:
significantly evolved. We introduced https://www.flickr.com/photos/
several new characters and docsearls/14861798514/in/
expanded our scope to include Web set-72157646284287131).
development and programming. So, why Linux? We love Linux
here, but not all computer
DS: Where in rural Utah are science education starts with
you? (A side thing—I love Utah Linux, especially for kids. But you
and have shot it a lot from started there, which is very cool.

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 111

LJ246-Oct2014.indd 111 9/17/14 4:50 PM


EOF

Between the two poles of servers and


smartphones—and the ubiquity of
computers—we think the majority of users
will eventually run a Linux distribution.

JN: Linux is the future! So we of our media using Linux machines.


hope. Between the two poles of We edit our videos with Lightworks
servers and smartphones—and the (http://www.lwks.com). Our
ubiquity of computers—we think computer graphics are rendered in
the majority of users will eventually Blender (http://www.blender.org).
run a Linux distribution. One of our Our audio is processed using Audacity
goals is to remove the economic (http://audacity.sourceforge.net) and
barrier associated with learning Ardour (https://ardour.org), and our
computer science. Not only are stopmotion animations are created using
the majority of Linux distros free, Entangle (http://entangle-photo.org)
they are amazingly powerful and and compiled with avconv
customizable and can breathe new (https://libav.org/avconv.html).
life into old hardware.
Linux is also very hands-on, and DS: Why puppets? (Side thing—
learning it is also learning how a my daughter Colette is a college
computer works. Other popular professor who teaches puppet
operating systems obscure the inner theater: http://www.umbc.edu/
workings of the computer from theatre/searls.html.)
the user. With Linux, students can
choose how deep they want to dive JN: We learned about the world
into their machines. by watching Sesame Street,
The Muppets and Mr. Rogers’
DS: And you do all your production Neighborhood. We wanted to create
on Linux? a show in the same vein with a
contemporary sensibility. We loved
JN: Yes. We have such an appreciation the idea of merging analog craft
for this operating system that we with digital technology. In addition
challenged ourselves to produce all to puppets, a lot of our new content

112 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 112 9/17/14 4:50 PM


features stopmotion and hand-drawn
animation as well as 3-D computer- Advertiser
generated animation.
Index
DS: Why Python? We can guess, Thank you as always for supporting our
but we’d rather ask anyway. advertisers by buying their products!

JN: Python is an excellent choice for a


beginner because it issues immediate
ADVERTISER URL PAGE #
results, it’s very easy to read, and
it can be used for a wide variety of All Things Open http://allthingsopen.org 2

applications. Best of all, it is included


with most Linux distributions. Drupalize.me http://www.drupalize.me 7

EmperorLinux http://www.emperorlinux.com 21
DS: Do you teach locally as well
as on-line (for example, in local Silicon Mechanics http://www.siliconmechanics.com 3

schools)? If so, how and where?

JN: We ran workshops with hacker/


Makerspaces in the past, but found
that our two-man team didn’t have ATTENTION ADVERTISERS
the time and resources necessary to
teach and continue producing new The Linux Journal brand’s following has
grown to a monthly readership nearly
content for our site.
one million strong. Encompassing the
magazine, Web site, newsletters and
DS: Do you have commercial or
much more, Linux Journal offers the
other ambitions besides what
ideal content environment to help you
you’re doing now? (Such as seeing reach your marketing objectives. For
these adopted in schools?) more information, please visit
http://www.linuxjournal.com/advertising.
JN: We would love to see our
curriculum adopted in schools, though
our ambitions are more autodidactic.
Our primary goal is to empower young
people to make their own media.

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 113

LJ246-Oct2014.indd 113 9/17/14 4:50 PM


EOF

DS: Do you have a business with DS: You identify on Twitter as a


this as well? “Creative media company and
think tank” (https://twitter.com/
JN: Yes. We’re bundling our videos dotototdotcom). Tell us more
and selling them as a digital about both (especially the think
download. Our first complete tank part).
segment, Daisy’s Web Dev Diary, is
available for purchase via Gumroad JN: The Hello World Program is
(https://gumroad.com/l/daisy). our first project. As a creative
We’re also planning to release media company, we are producing
e-books for each of the four tracks an educational and entertaining
of The Hello World Program. And series of videos and tutorials
we’re slowly building a merchandise combining art and technology.
store, for fans to purchase Hello As a think tank, we recognize
World-themed T-shirts, stickers and that understanding the basics
posters (http://www.zazzle.com/ of computer science will be
dototot). a necessary skill set for the

114 / OCTOBER 2014 / WWW.LINUXJOURNAL.COM

LJ246-Oct2014.indd 114 9/17/14 4:50 PM


EOF

future. Through STEM initiatives, DS: Good. That’s just in advance


technological literacy will be of this issue of the magazine. Any
taught to students at a younger other projects?
age and eventually incorporated
in standard curriculum. We’re JN: We’re launching a new
predicting that Linux and Python segment, “Superusers: The
will be at the forefront of this Legendary GNU/Linux Show”
movement. We support an (https://www.youtube.com/watch?v=
open-source future and consider DQbODhkyA4g&feature=youtu.be).
our current project a contribution
to furthering the cause. DS: Excellent! I like Aramis the
Otherwise, we’re perpetually Gnu and Adalie the penguin!
brainstorming new endeavors
beyond puppets and video. But JN: We’re also launching a
we’re not ready to talk about crowdfunding campaign on
them yet. Indiegogo that should be up by
the time you read this.
DS: Can you give us some success
stories with kids? DS: Where can readers follow you?

JN: Our booth at Maker Faire Bay JN: Find us at http://www.dototot.com


Area 2013 was wildly successful. and on Twitter at https://twitter.com/
It was titled “Robot Puppet dotototdotcom or https://twitter.com/
Party”, and we invited young helloworldshow.Q
makers to use our puppets to
create their own short videos. Doc Searls is Senior Editor of Linux Journal . He is also a
We were awarded two Editor’s fellow with the Berkman Center for Internet and Society
Choice blue ribbons. But more at Harvard University and the Center for Information
important, the kids loved it. Technology and Society at UC Santa Barbara.
We’re also launching an Indiegogo
campaign called “Hands-On
Computer Science: The Hello World
Program”, which should go up Send comments or feedback via
in September (http://igg.me/at/ http://www.linuxjournal.com/contact
hello-world). or to [email protected].

WWW.LINUXJOURNAL.COM / OCTOBER 2014 / 115

LJ246-Oct2014.indd 115 9/17/14 4:50 PM

You might also like