Perl scripts analyze Jawbone UP data
Moving Circle
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.
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.
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.
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
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.