I bought myself a Pebble watch at Christmas and even wrote an app, wrist-spin, to display live cricket scores on the watch. Its a great device and its been fun to develop for, however the setup is not straightforward.

The Pebble SDK only runs on Mac OSX and Linux. Now given that 90% of desktop machines run Windows and that the life blood of a device like Pebble depends on the availability of a lot of high quality app this decision seems to border on lunacy, but that's the place we are in.

So if you are one of the 90% that run Windows what is the easiest way to get started writing apps for the Pebble. A virtual machine is the most obvious solution, which rules out Apple products.

Setting up Ubuntu

First select your virtual host, I have used VirtualBox for years and like it so I started with it. Next I decided that I would use the latest LTS (Long Term Support) version of Ubuntu from the downloads page, in my case this was 14.04. I wanted a newish stable version.

There are any number of guides on how to install Ubuntu in VirtualBox, I made it a dynamic disk and by the time I has finished it was 16GB. There are a few gotchas  by default the VirtualBox 3D acceleration is off and Ubuntu will run very slowly until you turn it on. Even when it is turned on you will sometimes see console errors however some of the errors are expected which does make this whole area confusing the best quote I found was in this article

General note to everyone commenting on this ticket. If 3D is working in your guest then the output of "glxinfo" should include:

OpenGL vendor string: Humper
OpenGL renderer string: Chromium

The following warnings will always appear, even when 3D is working, due to a problem in the way our driver is implemented which is not simple to fix:

libGL error: core dri or dri2 extension not found
libGL error: failed to load driver: vboxvideo

Installing the Pebble SDK

The Pebble SDK now comes in two parts, isn't that great. Actually it is a good idea to help you switch between SDK’s easily once you are up and going however it does make it a bit more complex to get going.

First of all I installed the stand alone PebbleTool SDK and following the installation instructions for  Linux. I found that adding the “pebble” command to the .bash_profile in the instructions did not work and I ended up adding the following two lines to my .bashrc file

export PATH=~/pebble-dev/pebble-sdk-4.2-linux64/bin:$PATH
export PEBBLE_EMULATOR=basalt

The installation is a little complex and needs to be done every time the PebbleTool is updated, including altering the .bashrc file so I tend to checkout the release log to see if there is enough in the release.

The PebbleTool command line can be used to build and deploy your app as well as download SDKs and switch between them. pebble sdk list will list all the SDKs you have downloaded as well as the available SDKs, you will need to download at least one to start work, probably the latest one by typing pebble sdk install

derek@ubuntu1-VirtualBox:~/pebble-dev/code/wrist-spin$ pebble sdk list
Installed SDKs:
3.11.1 (active)
3.10
3.9.2
3.8.2

Available SDKs:
3.11
3.10.1
3.9
3.8.1
3.8
3.7
3.6.2
3.4
3.3
3.2.1
3.1
3.0
2.9

Installing basic apps

Before installing pretty much anything you are going to need Java I installed the OpenJDK 1.7 and its worked pretty well so far, I used the instructions from the Ubuntu site.

I needed some form of editor to work with code and I’d used Atom so I installed that. Its not completely straightforward however following these instructions got it installed.

Pretty soon I got frustrated with Atom and decided to switch to Visual Studio Code. Its much faster and much less likely to crash the installation is pretty straightforward.

One of the real bonuses with Visual Studio Code has been that I can add build and test tasks by following the instructions here I created this file in .vscode/tasks.json in my application folder

// A task runner that calls the Pebble compiler (pebble) and
// compiles a program
{
  "version": "0.1.0",
  "command": "${workspaceRoot}/../../pebble-sdk-4.2-linux64/bin/pebble",
  "isShellCommand": true,
  "showOutput": "silent",
  "echoCommand": true,
  "tasks": [
    {
      "taskName": "build",
      "isBuildCommand": true
    },
    {
      "taskName": "install-aplite",
      "suppressTaskName": true,
      "args": [
        "install", "--emulator", "aplite"  
      ]
    },
    {
      "taskName": "install-basalt",
      "isTestCommand": true,
      "suppressTaskName": true,
      "args": [
        "install", "--emulator", "basalt"  
      ]
    },
    {
      "taskName": "install-chalk",
      "suppressTaskName": true,
      "args": [
        "install", "--emulator", "chalk"  
      ]
    }
  ]
}

Now I can just press CTRL-SHIFT-B to build and it even remembers to save my files first (something I keep forgetting to do). and CTRL-SHIFT-T runs the build in the emulator.

Next you are going to need some form of GIT client, I used SmartGit, instructions are here.

Building your first app

There are any number of tutorials on building “hello world”. I found this article had some good tips for extra libraries you might need and this one had some good skeleton code.

Development lifecycle

In general I would edit the code. Then save everything. Then

pebble build

in the root of the application. Then

pebble install –emulator basalt

or

pebble install –phone 1.2.3.4

If the code crashes then you are writing in C and there wasn’t a debugger, the emulator would just crash and you would get the sad face. If your app just crashes on your watch then make sure you have the latest SDK installed on your watch or at least the SDK you built with matches your watch.

 

Screenshot2

The later SDK release do seem to have some debugging support but I haven't tried it yet. In general I use a lot of logging like this

static void init(void) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "wrist-spin v %s", get_version());

  init_persistent_data();
  showMainWindow();
  init_app_sync();
  open_app_sync();
  init_timer_tick();
  init_bluetooth_event();
}

And then using include files I can make suppress the logging for a release build

#ifdef SUPRESS_LOGGING
#undef APP_LOG
#define APP_LOG(...)
#endif

The logging can be displayed from an emulator or the phone using the PebbleTool

pebble logs --emulator basalt

Its a bit primitive but I think that's part of the appeal of building apps for the pebble. The source for my first app is here.