Saturday, December 19, 2015

Pebble Battles

I was hoping to get allot of programming done on my Pebble yesterday.  Not so.

I left off Thursday with a working app, started up Friday morning to this.  It's telling me that pebble.h doesn't exist.  Sort of a fundamental problem.  So I scour the internets to see what's going on, nothing.  Send an email to support, then consider my options.

The last time CouldPebble was down I developed on my Mac, so back to that.  Fumble around for a while, it's been almost a year.  Load app on my watch, mistakenly putting it on the one I'm wearing, and not the development model...  App doesn't work.  Try to load onto my original pebble, just get this message "Couldn't install app".  Dead.  Nothing.  Try app in emulator, works fine.

After an hour or two of this, I notice that pebble is on a new SDK release.  Start fiddling around with the command line:
->pebble sdk list

Tells me I'm on 3.8.1.   Hmm, lets try 3.7.
->pebble sdk install 3.7
->pebble activate 3.7

I like the way you can easily switch and install SDK's, beats the hell out of Java and hunting around for the correct version.
Then build, install and success!  Most of my day is gone, but the watches are back to working.
As of today, CloudPebble is still wasted.  I really liked this tool, and the mbed site as well, good for casual use I suppose.  Looks like I'm officially done with CloudPebble for development.

Thursday, December 17, 2015

Working Prototype

Bread boarded and working.
Now to get this on a PCB, and figure out what kind of battery I'm going to need.

Final build:
- BLE Nano
- Sparkfun Bluetooth Mate Gold
- Teensy 3.1
- A couple of discrete components so I can control the Bluetooth Mate

The Nano, like the RFDuino, can't run at 115k with the radio on, so I have to have the Teensy around to coordinate everything.
Cool thing with the nano, is I have it in Central Mode.  My CGMS devices pair directly with this if the phone isn't available.

So it's:
Sensor->CGMS->iPhone-> Watch


Sensor->CGMS->"The new device"->Watch

Also this device will pair and/or wait to pair for as long as it has power.  No issues with something shutting down the "process" like the iPhone does if the BLE connection has been idle for more than a few minutes.

Thursday, December 10, 2015

More on Pebble

Connecting an Arduino to a Pebble.

I'm using a sparkfun, bluetooth mate, GOLD.  I don't believe the Silver will work.  A big issue with this process is what type of bluetooth dongle you have, I'm sure they all work differently.

The guy here:, has some basic working(for him) code.  What's left out, is the initial pairing.  With the Mate, you are better off not trying to control it programatically.  After many hours, it just doesn't seem consistent and tends to be unresponsive.  It is meant to be configured over serial from a lengthy command set.  Most of the settings don't appear to "take" until you reboot the device, and just power cycling may blow them away.  Also, some important settings don't persist.  The big one that comes to mind is baudrate, so assume you are going to be at 115200.

Before you do anything with the arduino, configure the Mate, you aren't done until the Mate stops flashing red and the green light stays on, indicating you are paired.  From that point forward, the mate should automatically pair with the pebble until the end of time (although it may take as long as a minute, or never)...

The commands you should send to the Mate:
SF,1         //factory reset
SP,9999   //takes care of the pairing code
SM,6        //pairing
SY,0000   //power
SW,0640  //sniff mode
R,1            //reset so settings are saved/active and pebble should ask to connect

Once the light hits green, pairing with the watch will take place, the first time the watch will ask, any time after that it will be silent.  The watch will send you a version request.  You need to send two packets in reply, screw this up and the watch will just ignore you.

I send:
//          //phone version
{0x00, 0x02, 0x00, 0x30, 0xff, 0x08};

Followed 100ms later with:
//                                  0x11 = 17 = Phone Version endpoint
//                                             phone version
//                                                        remote capabilities  Telephony.SMS.Android
//                                                                                              //session capabilities............
{0x00, 0x0d, 0x00, 0x11, 0x02, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32};

You shouldn't send the above again, unless you "forget" the bluetooth device from your watch.

Once that's complete you can ping the watch:
//                    endpoint
//                    2001=ping
{0x00, 0x05, 0x07, 0xd1, 0x00, 0xde, 0xad, 0xbe, 0xef};

Send a notification:
//this says BG 115  
//                                                                       B      G                   1        1         5
 {0x00, 0x1A, 0x0B, 0xB8 , 0x01 , 0x02, 0x42, 0x47, 0x03 , 0x31 , 0x31 , 0x35, 0x11, 0xFF, 0xFF , 0xFF , 0xFF , 0xFF, 0xFF, 0xFF, 0xFF , 0xFF , 0xFF, 0xFF, 0xFF , 0xFF, 0xFF , 0xFF , 0xFF, 0xFF};

Note: the above packet has a header and body.  The header is 2 bytes and says "BG".  The body is 3 bytes and says "115".  The 0x11, signifies 17 bytes until the end of the message.

Or, and this is the big one, send an application message.
For this one you need the UUID of the app, which you can see in Cloud Pebble.

With that, I can send an integer value of 120 to the first element(tuple?) in my applications dictionary.
//app messages to uuid, glucoseKey
//001b 0030 0100 7f7a38901a1c43a3adf121449e4f352d 040100 0000 03:01:00:78
//msg  app    push UUID................................................... key                     len      120
//         msg                                                                                                int (0x03)
//                                                                                               dict element (0x01)

I may have to update this one.

Can't use the RFDuino.  Number of serial ports is one issue, the bigger one though is you can't run the Radio and Serial at 115200, 9600 works, but 115200 will cause the app to hang.

Turning one off and the other on, also doesn't work, doing a Serial.end / Serial.begin appears to glitch the serial line to the mate and causes it to disconnect.

It looks like this project will be continuing with a Teensy.  One serial for debug, the second for the Mate, SPI for the CC2500, maybe a third serial to run an RFDuino if I want BLE.

See github ( for a working sample.

Friday, December 4, 2015

Direct control of Pebble with Arduino

Slow week, and I was cleaning up the bench.  Stumbled on one of my Sparkfun Bluetooth Mates.
I used these with the metawatch a few years ago.  I was never able to work out the pairing to get these to connect to the Pebble.  Well, I know a bit more, and I'm probably even more persistent these days...

I need to work out how to send an application message, then I can go phoneless.  I might have to use the Wixel again, could keep my parts count down.  This will net me a larger carry, but no phone requirement for extended periods.  Still need to get calibrations in somewhere, though.

This guy (here) was close.  But he's leaving out the initial pairing step.  The packets have changed since this was published also.  Allot of strange details, probably bluetooth device dependent.  I'll post more when I can sort through all the details, but I can reliably pair with the watch and send a notification to it.