Connecting Pebble to Squirro

March 20, 2013

by Patrick Stählin

Last week I’ve received my Pebble, a smart watch that had its roots on Kickstarter. As any watch it displays the time, but it can also notify you on certain events like incoming mails. It doesn’t talk to Squirro out of the box, but here is how I got it to.

Pushover

The only way the Pebble can communicate is via Bluetooth, so there is no way to talk to it directly from the Internet. It is however, paired with my Phone which is always online. Not wanting to write (or rather learn how to write) an App that talks to the Pebble, I’ve searched for a generic solution and discovered Pushover.

Pushover is a paid application available for Android/iPhone. It lets you register your own Apps and pushes notifications directly to your phone. As Squirro, it has an open API which makes it very easy to integrate.

I’ve registered an App that’s called ‘SQ Alert’ (you see where this is going). This gave me an application token which can be used in combination with any user-token to send messages. As you can see from the following lines it’s very easy to use:

curl -d 'token=pushover_application_token' 
     -d 'user=pushover_user_token' 
     -d 'message=Testing' 
     -d 'title=World is ending' 
     https://api.pushover.net/1/messages.json

This is how it looks on the phone:

image

And it also gets pushed to the Pebble:

image

The only thing left to do, is to connect Pushover and Squirro.

Get Squirro talking

In my previous post I’ve described how to use webhooks to talk to your application, now we’re going to use the same technique to talk to Pushover and display Squirro Alerts on the Pebble. Although we don’t have a nice user-interface to configure webhooks yet, we do have an API for setting up triggers.

Each trigger consists of a query, and various actions that get executed should an item match the query. The action type we’re looking at here is webhook (documentation). A webhook calls a uri for each item that matches the query. It takes a dictionary of fields to be sent along. These fields are a template for the request sent out for each item. What we’re ending up with is:

curl -X POST http://topic-api.squirro.com/v0/linkedin-vmr1SvM-kp/filters 
  -u 3806c71b3bd520...: 
  -H 'Content-Type: application/json' 
  -d '{"query": "squirro",
       "name": "Pebble trigger",
       "operator": "OR",
       "type": "trigger",
       "actions": [
         {"type": "webhook", 
          "config":
            {"uri": "https://api.pushover.net/1/messages.json",
             "method": "POST",
             "fields": {"token": "pushover_application_token",
                        "message": "{summary}",
                        "user": "pushover_user_token",
                        "title": "{title}",
                        "url": "{link}",
                        "timestamp": "{created_at_timestamp}"}}}]}'

The part after -u is your user token. If that doesn’t ring a bell, this blog post might get you up to speed.

All we need to now is to wait for some articles being published that contain the word “Squirro”. Sure enough after testing the first item quickly arrived:

image

…and on the Pebble:

image

Outlook

It still requires command-line access to configure these kind of notifications. Once we have a nice GUI and some service templates we should be able to make this a one-click solution.