Perl scripts analyze Jawbone UP data

Moving Circle

Article from Issue 156/2013
Author(s):

The Jawbone UP electronic bracelet measures the wearer's daily activity and nocturnal sleep patterns. If you are bored by the official smartphone app, you can create your own Perl scripts and access your data via the unofficial web API.

To counter the widespread tendency to excessive body fat, many smartphone owners now carry little gadgets around with them, reminding them of their lack of physical activity during the day. If you sit motionless for hours in front of the screen, the idea is that such a device could motivate you to walk around the block more often, or at least use the upstairs bathroom. This trend toward self-measurement – known as quantifying yourself – has grown very popular lately.

An electronic bracelet like the UP [1] by Jawbone measures the steps you take and shows the distance traveled and calories burned in the associated smartphone app (Figure 1). The accessory is available in three sizes and several colors and costs about US$ 130. From a functional point of view, the device seems to capture only instantaneous acceleration values and accumulates them over time. The geographical position of the wearer could be determined with a GPS chip, but this added function would probably drain the device's small battery in next to no time.

Figure 1: The Jawbone UP bracelet tallies its wearer's physical activity during the day by tracking acceleration.

Under the Hood

As a specialist in lifestyle gadgets, Jawbone is not exactly a proponent of open hardware; but in a YouTube video [2], an inquisitive geek slit open the outer rubber shell of the bracelet to reveal the waterproof sealed components inside (Figure 2). In the course of this operation, the bold explorer found half a dozen smaller mini-PCBs with SMD components, but apart from an accelerometer, the lithium-ion battery and charger chip, a vibration device, and components for docking to the audio port of the smartphone, nothing flashy was revealed.

Figure 2: On YouTube, a hobbyist demonstrates how to dissect a Jawbone UP band and explains its components.

In other words, after connecting to the smartphone, the bracelet simply sends the timed acceleration data to a machine learning system in the Jawbone cloud, which then looks at the movement patterns and guesses by the type of movement (walking, running, elliptical trainer) how many steps the wearer managed and what distance was covered.

Sleep of the Just

If you wear the UP band at night, you can marvel at your sleep patterns in the morning. The app shows graphically when you went to bed, when you fell asleep, and how many times you woke up or got up during the night. Upon request, the band can wake you with a gentle vibration within a 20-minute period in the sleep cycle when waking up will cause the least pain.

To detect the sleep pattern, however, you first need to press a button to switch the device manually to sleep mode. If you do not move for a long time after this, you are probably fast asleep; if smaller movements are detected, you are in a lighter phase of sleep.

The built-in battery lasts for about a week without recharging. To read the data, you need to pull the silver cap off one end of the UP to reveal an audio connector. You then plug the connector into the audio port on your smartphone (Figure 3) and launch the app. The UP sends the movement data to the app, which forwards it to the server in the Jawbone cloud. The app receives the processed data and displays it in nicely arranged graphs (Figures 4 and 5).

Figure 3: If the bracelet audio plug is plugged into the socket of the smartphone while the UP app is running, it transmits the data.
Figure 4: The smartphone indicates not enough sleep, but the wearer has almost reached his goal of 10,000 steps per day.
Figure 5: Got to bed at 1:20am, then woke up at 6:30am, started reading a book, then dozed off and woke up again at 10:00am.

You can share the information that UP gathers with other users. For example, runners can invite friends to join their "team" and organize fitness competitions. If you prefer not to let your colleagues know that you spent the whole night tossing and turning in bed, you can exclude this delicate information from publication in the Sharing section.

Open Data

The device is interesting for hobbyists because the step and sleep data is available not only via the app but also in a raw format. To access the data, the script in Listing 1 calls on the CPAN WWW::Jawbone::Up module, and thus indirectly an unofficial web API that imports the transaction data into a Perl script [3]. Running ./uptest at the Linux command line allows the experiment-friendly fitness enthusiast to quickly query the data they have already uploaded:

Listing 1

uptest

 

Mike Schilli walked 8.597km today
Mike Schilli slept for 6h19m last night

Listing 1 starts by loading the CPAN module and then logs in to the UP cloud using the connect() method. You need to replace the email address and password in lines 11 and 12 with your UP user account credentials, which you created when you activated your UP. The user() method retrieves the registration data of the logged in user. The name() method extracts the user's first and last name.

The score() method then pulls the processed motion data from the UP server. The distance traveled by the wearer in the past 24 hours can be queried in kilometers using move()->distance(). If you prefer miles, you can simply multiply the value by 0.62.

The sleep duration in seconds is provided by sleep()->asleep(). The next line divides the value by 60 to arrive at minutes, and the CPAN module DateTime::Duration converts the resulting value to hours and minutes. It refuses to cooperate with seconds because this could lead to errors in special cases (because of leap seconds), so you need this trick to get it to cooperate.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Data Visualization in Python

    Python's powerful Matplotlib, Bokeh, PyQtGraph, and Pandas libraries lend programmers a helping hand when visualizing complex data and their relationships.

  • Google Chart

    The Google Chart API lets you draw custom graphs, charts, maps, and barcodes through a simple web interface.

  • Perl: Google Chart Instructions

    A CPAN module passes drawing instructions in object-oriented Perl to Google Chart, which draws visually attractive diagrams.

  • Tutorial – LibreOffice Charts

    Everybody needs charts sooner or later, and LibreOffice Calc is the easiest way to create them with free and open source software.

  • Wanderlust

    For running statistics on his recorded hiking trails, Mike Schilli turns to Go to extract the GPS data while relying on plotters and APIs for a bit of geoanalysis.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News