Perl scripts analyze Jawbone UP data
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  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.
Under the Hood
As a specialist in lifestyle gadgets, Jawbone is not exactly a proponent of open hardware; but in a YouTube video , 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.
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).
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.
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 . Running
./uptest at the Linux command line allows the experiment-friendly fitness enthusiast to quickly query the data they have already uploaded:
01 #!/usr/local/bin/perl -w 02 ############################# 03 # uptest - Get Jawbone data 04 # Mike Schilli, 2013 05 # (email@example.com) 06 ############################# 07 use strict; 08 use WWW::Jawbone::Up; 09 use DateTime::Duration; 10 11 my $email = 'firstname.lastname@example.org'; 12 my $pass = 'changeme'; 13 14 my $up = 15 WWW::Jawbone::Up->connect( 16 $email, $pass); 17 18 my $user = $up->user(); 19 my $score = $up->score(); 20 21 print $user->name 22 . ' walked ' 23 . $score->move->distance 24 . 'km today', "\n"; 25 26 my $dtd = 27 DateTime::Duration->new( 28 minutes => 29 $score->sleep->asleep() / 30 60); 31 32 print $user->name 33 . " slept for ", 34 $dtd->hours(), "h", 35 int($dtd->minutes()), 36 "m", " last night\n";
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.
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
Innovative system adds a hard drive and Ubuntu Core to the RPi for an IoT hub.
Linux is two weeks younger than we thought!
The Apache Software Foundation considers retiring OpenOffice
Adobe won’t kill the plugin in 2017
Linux Foundation's big event celebrates the 25th anniversary of Linux
Competitors get in the game with RHEL without Red Hat
Security researchers have already notified Microsoft; some fixes are available
The company is collaborating with Google and Intel to use Kubernetes as an engine for Fuel