• Blog
  • Research
  • Sending Messages to a Pebble from a Raspberry Pi

    28 August, 2018 | General Hackery

    The Pebble was always (and still is, in my opinion) the best smartwatch. Sadly it suffered from a common problem with IOT devices, that of server reliance. So when Fitbit bought Pebble and made the decision to discontinue it, everyone's watches suddenly stopped working because they shut the servers down. There is a project called Rebble, which aims to replace those servers, but surely a better idea is to not rely on a server in the first place?

    Not long ago, I realised that I'm in range of a Raspberry Pi almost as often as I'm in range of my phone. I have several at home, and one on my desk at work. So I figured that if I can get a RPi to send notifications to my watch, I wouldn't need to pair it with my phone at all. Obviously your mileage may vary, and SMS messages still need to be sent from a phone, but having a Raspberry Pi sending messages to a smartwatch is cool regardless. Once you get the basic principle working, you can have it alert you to emails, RSS alerts, Twitter mentions, or just about anything else that you can query via an API.

    I'm using a Raspberry Pi 3. This was the first Pi to have Bluetooth on-board. It actually supports Bluetooth LE, but LE, despite being much lower power, is very limited compared to 'full-fat' Bluetooth, so I've kept to that, as my Pebble happily supports it.


    I'm using the Pi headerless, so GUI settings aren't really practical. However, the blueman-manager application's dependences contain everything we might need, so run

    sudo apt-get install blueman

    to install these. We also need methods for talking to bluetooth serial devices, and a way of interfacing with the pebble from python. So install

    sudo pip install libpebble

    to make sure we have everything we need, in particular pyserial. That should be about it.


    Pairing can be done over the command line using bluetoothctl. Run

    sudo bluetoothctl

    to get a new command shell. From here type the following

    agent on
    scan on

    After a few seconds, your Pebble should appear. Again, we need the entry without 'LE' in the name. Get the MAC address (hex couplets seperated by colons) and type

    pair [mac_address]

    Ensure the six-digit code matches, and we should be good to go. Now we just need to give it a port to talk on.

    rfcomm bind 0 [mac_address] 1

    This will bind the Pebble to /dev/rfcomm0 on channel 1. Now it's paired and bound, we can simply send data to /dev/rfcomm0 and it'll get to the Pebble. Now we just need to send the data in the format the Pebble is expecting, and we've already installed libpebble2, a library for doing just that. So open Python's interactive shell by typing python at the command line. Then enter the following...

    from libpebble2.communication import PebbleConnection
    from libpebble2.communication.transports.serial import SerialTransport
    pebble = PebbleConnection(SerialTransport("/dev/rfcomm0"))

    Hopefully this should all return no errors. If so, then we've just connected to the Pebble and are now running an active connection. We can query this...


    Hopefully this should return the serial number of the watch. If we want to see the watch actually respond, we can send it a ping...

    from libpebble2.protocol import *
    pebble.send_packet(PingPong(message=Ping(), cookie=53))

    Sending Messages

    libpebble2 has quite a rich API, so I'll not cover it all here. However, if you just want the Pi to be able to send the Pebble messages and have them appear on the screen, then it's quite simple in Python.

    from libpebble2.services import *
    from libpebble2.services.notifications import Notifications
    n = Notifications(pebble, None)
    n.send_notification("Subject", "Message", "From")