Pebble Smartwatch
Pebble Tricks
Using a couple of apps and a bit of coding, you can teach your Pebble smartwatch some clever tricks.
Although Pebble [1] isn't the most advanced and prettiest smartwatch out there, it has its advantages. Pebble is relatively inexpensive, and it has excellent battery life and a decent selection of apps (or watchapps in Pebble parlance). Of course, if you are proficient in C, you can write watchapps and watchfaces yourself. However, those without advanced coding skills are not precluded from devising clever Pebble-based solutions.
Sending Custom Push Notifications
Receiving and managing notifications from your wrist is probably the raison d'être of any smartwatch, including Pebble. The Pebble app for Android and iOS lets you receive notifications from practically any app installed on your Android phone or iPhone, but what if you want to send custom push notifications from other sources?
Suppose you build a web app, and you want to add the ability to send notifications to your Pebble smartwatch when a certain event occurs. One way to do that is to use a service like Pushover [2], which allows you to integrate notification functionality into your software projects. To use the service with your Pebble smartwatch, you need to create a Pushover account and install the Pushover app on your Android device. Next, open the Pebble app and switch to the Notifications section. Tap the All apps item and enable the Pushover app. Then open the Pushover app on your Android device and complete the setup.
Some applications and services provide support for Pushover, so you can enable notification functionality without writing a single line of code. GitHub, for example, allows you to enable Pushover notifications for any of your repositories (Figure 1). To do this, navigate to the repository's settings page, switch to the Webhooks & Services section, and add the Pushover service.
Pushover is also available as a channel on the popular IFTTT [3] service. This feature allows you to create so-called recipes that push notifications to your Pebble smartwatch when specific events occur.
When you create a Pushover account, the service automatically generates a unique user key. To use Pushover with your own software projects, you also need to obtain an API token. To do this, go to https://pushover.net/apps, click on the Create a New Application link, and fill out the required fields (Figure 2). Press the Create Application button to add the application and generate an API key.
Pushover provides a simple API that makes it possible to add notification functionality to your scripts and applications with a minimum of effort. To send notifications from shell scripts, you can use the curl
tool. All you have to do is specify a few mandatory values, such as the API and user keys and some notification text using the --form-string
option (it emulates a filled-in form in which a user has pressed the submit button):
curl -s --form-string "token=API_KEY" \ --form-string "user=USER_KEY" \ --form-string "message=Hello World! \ "https://api.pushover.net/1/messages.json
Using this simple command, you can instantly add notification capabilities to any shell script. If you run your own server and would like to be notified when it's down, you can whip up a simple shell script (don't forget to replace the target IP address as well as API_KEY
and USER_KEY
with actual values); see Listing 1.
Listing 1
Pushover Shell Script
The script pings the server and if the ping fails, the curl
command sends a notification. Save the script, make it executable, create a cron job that runs the script at predefined intervals, and your quick-and-dirty server monitoring system is ready to go. Next time the server is down, a notification will be delivered straight to your wrist.
Because Pushover is supported by IFTTT, you can create all kinds of recipes that deliver notifications to your Pebble. With a bit of Python scripting magic, however, you can replace this web service with your own homegrown solution and learn a couple of useful techniques in the process. For example, suppose you want to be notified when the temperature outside reaches a specific threshold. The simple Python script in Listing 2 can help you with that.
Listing 2
Python Temperature Notification Script
The script uses the OpenWeatherMap service [4] to fetch current weather conditions in the JSON format. The temperature = data['main']['temp']
statement extracts the current temperature from the obtained data. The if
condition then checks whether the current temperature exceeds the specified threshold, and if it does, the script sends a Pushover notification.
What else can you use notification functionality for? How about creating a simple web app that allows users to send short messages to your Pebble via a browser? You can use a Python script based on the Bottle framework (Listing 3) as a starting point. The script consists of a form containing a text field and a Submit button. When the user presses the button, the msg()
function processes the contents of the field (i.e., extracts and truncates the text) and pushes the result as a notification.
Listing 3
Send Message Python Script
Pebble My Data Watchapp
Pushing and receiving notifications is not the only thing you can do with your Pebble. Using the Pebble My Data watchapp [5], you can turn your smartwatch into a hub of useful information.
This watchapp fetches and displays custom data in the JSON format stored on a remote server. Moreover, the watchapp can be controlled through the supported options in the JSON file. To get started with the Pebble My Data watchapp, first install it on your smartwatch and create a text file with the JSON-formatted content shown in Listing 4.
Listing 4
JSON Content
Save the file under the text.json
name and move it to a web server. Then, point the Pebble My Data watchapp to the file, and you should see the Hello World! message. Besides the actual content, the JSON file has several options that control the watchapp's behavior. The refresh
option, for example, defines the interval between updates in seconds, whereas the blink
option forces the screen to blink the specified number of times. It's also possible to specify a font and a theme (light or dark) using the font
and theme
options. The watchapp supports options for controlling button behavior, too. You can specify the scroll offset using the scroll
option and use the updown
option to configure the Up and Down buttons for scrolling or polling the JSON file.
Using your favorite scripting language, you can pull data from different sources and generate a JSON file for use with the Pebble My Data watchapp. For example, because Python Bottle can output data directly in JSON format, you can use this lightweight framework to whip up a simple web app that fetches and processes weather data and serves it in the JSON format for use with the watchapp (Listing 5).
Listing 5
Python Script for the Pebble My Data Watchapp
Of course, you're not limited to weather data: With a bit of creative thinking and a few lines of code, you can make the script parse and serve practically any kind of data. For example, if you want to keep an eye on the server's uptime using your smartwatch, just add the following statements:
uptime = int(os.popen('cut -d. -f1 /proc/uptime').read()) days = uptime/60/60/24 hours = uptime/60/60%24 mins = uptime/60%60
This code obtains the uptime in seconds and then calculates the days, hours, and minutes values. Add
'Uptime: '.$days.' d '.$hours.' h '.$mins. ' min '
to the content
variable to display the uptime in the watchapp.
Naturally, you are not limited to Python either. If you already have Apache (or another web server) and PHP running on the remote machine, you can write a similar script in PHP (Listing 6).
Listing 6
PHP Script for the Pebble My Data Watchapp
Final Word
Pebble is not the most advanced smartwatch out there, but you can transform it into a genuinely useful companion using apps like Pebble My Data and a dash of scripting magic. Additionally, you can use the examples in this article as a starting point for your own creations. The scripts in this article are available on GitHub [6], so you can dissect, study, and improve them to your heart's content.
Infos
- Pebble smartwatch: http://getpebble.com
- Pushover: http://pushover.net
- IFTTT: http://ifttt.com
- OpenWeatherMap: http://openweathermap.org
- Pebble My Data watchapp: http://github.com/bahbka/pebble-my-data
- Article scripts on GitHub: http://github.com/dmpop/pebble-mydata
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
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.