Friday, October 20, 2017

Android Wear Success

Here's what happens when you make a device without any programmer access...
Luckily, hot glue is reversible with alcohol.

To make everything work, I needed to reprogram my device to send out the isig every 5 minutes.  This way, another device (the watch) can listen for a notification.  I originally wrote this, years ago, to only send a response to a request, but this isn't really how BTLE wants to work.

Finally success with android wear.  The end result looks exactly like my last post.  Unfortunately, I can't really see those numbers without reading glasses, so I'm stuck with a custom watch face and bigger numbers.  I'll work on that, I'm still trying to figure out complications, they only work by accident now.

As to the android studio issues, here's what to do when it starts acting up.
To connect to the watch you do "adb connect {watch ip address}".  This should connect quickly.
Signs that you're screwed are the following:
- can't connect to the watch, and you get various meaningless errors
- studio hangs, windows crashes etc
- studio tells you it can't put the apk on the watch etc.
- you deploy code, but the debugger doesn't stay connected so no logging

First, toggle wifi off/on on the watch, then try the connect statement.  That generally fixes things.  If problems persist, restart everything.  Your PC, the watch and your router.  It will work for up to a week after that.  Also, you probably need to wake the watch up to program, otherwise Android Stuido will just sit there.  Not exactly user friendly.

I'm using the Sweet Blue bluetooth libraries.  That got me around allot of headaches.  One strange thing, the device name has to be LOWER case.  The device is programmed in UPPER case, and you can confirm that with a bluetooth scanner, but you need lower case for sweet blue.

Complications, aptly named, when developing this, I had no issue pushing a value to the complication and having the screen refresh immediately.  In practice, there is a delay, not enough that I care, the vibratory alerts happen real time, and you can tap the display to get the current value, but they can lag a few minutes.  Another issue on the programming side, if I update the code on the watch, the bluetooth doesn't always start up again, it binds the device, but no values show up.  Solution, restart the watch.

Well, that's it, I'll  update this post when I've figured out what the battery life is going to be.  The CC2500/RFduino device is good for 24 hours, I'm hoping the watch will hold out for a full day.
10 hours, and the battery indicator was at 50%...  I'll try again with WIFI off.

Monday, October 9, 2017

Android Wear... Sort of

What it should be. 

My Pebble round lasted 1.5 years.  The replacement 3 months.  Now I'm using a Pebble Time, which is working great, but for how long?

Saw a good price on the Moto 360, so I ordered one.  Turns out I was early to the party.  Waited around a month for the 2.0 update to finally show up.  2.0 being important since that allows watch to bluetooth device communication, and not just a phone.

Programming this thing is impossible.  The connection between Android Studio and the Watch is sketchy at best.  You have to connect from the Terminal using something like "adb connect".  But allot of the time, it won't connect.  Sometimes it seems like maybe it's the watch has gone to sleep.  Other times, you toggle wifi on the watch and then the connect will work.  Who knows.  Buggy.  I had one magical day where it sat in the charger and worked flawlessly.  Today, I might get the APK deployed, but then the watch disconnects, so no debug.

I was very surprised when I switched to a Kindle tablet.  Infinitely easier.  The device just shows up when you click run, imagine that. 

Oh, and bluetooth.  I have it working, but after reinstalling the app on the watch, I'm getting messages that I need to grant access to bluetooth.  You have to do this multiple places. 
1. In the manifest
2. After the program is deployed, there's a permissions section
3. And it appears, you need to answer the dialogs asking for access to bluetooth as well.

There's the rub.  This is running as a complication, there's nowhere to pop-up a dialog, so you are dead in the water, stupid.  You can see the issues "they" are having with security on Android.

At the moment I'm not sure how I had bluetooth working, and since I can't get a reliable debug(today)...  I know some of my tests I had a basic watchface, then I loaded the complication, and it all worked.  Thinking I got lucky, and the authorization I provided for one app bled over to another.

Going to implement this on the kindle first, just to work out the coding issues and then keep my fingers crossed that I can get something to work on the watch.

On the plus side, Apple announced that their watch will soon communicate directly with the G5, at least the manufacturers are getting the message that people don't want to be tied to a phone.  I may get an iWatch, as soon as that update hits, probably better long term possibilities there, sounds(and looks) like Android Wear is DOA.

Thursday, December 8, 2016


Been kind of done with the blog thing.  Reached my destination and all that.  And then...

Shouldn't be too surprised, did a year on Metawatch and 2 years on Pebble.  Now, looks like I need to find the next watch.

Although, no great rush.  Hoping to buy another Round at fire sale prices.  I can push my app changes directly to the watch from my Mac, note to self: test that process since it's been over a year.

Future platform, probably Android Wear.  Almost bought a Moto 360 sport last night, but the battery life on all of these watches is junk.  When using a watch as a CGMS, it's always working.  I can't leave it in a charger all night.  Really need 24+ hours of battery life, that means I can charge it for an hour once a day (say while reading before I fall asleep).  Anything less than that means having to charge multiple times a day, which is unacceptable, at least while I have another option.

Waiting for the next generation of Android Wear wearables at this point.

Saturday, May 14, 2016

Smartstrap Debugging

It's getting near to a year on the transmitter, so I needed to get my battery levels to the watch, where I can keep an eye on it.  The current plan is to add a battery to an old "thick" transmitter that I have saved.  This will give me a backup, while I try to change the batteries in my current "thin" transmitter.  There are some excellent tutorials out there, so expect to hear something about that over the next few months.  Currently the battery is at 0xD6.

Meanwhile, I needed to get the battery levels to the watch.  This didn't go smoothly, and I was frustrated by the lack of debugging information since I'm bound directly to the watch, so cloud pebble can't help me.  A while back I looked into the smartstrap functionality, but for day to day use, the amount of hardware would be bulky, and the connector looked problematic, and the parts are extremely small.  I went as far as having shapeways print the connector for me, but it didn't come out right.  Anyway, I realized this would be perfect for debugging.  So, above, you see a Teensy 3.1, a WT12 bluetooth module and a Wixel.  Took 2 days to get all this working, but I now have battery levels, and a way to see what's going on in the watch.

I also want to get the Pebble pairing code onto the Wixel, which would allow me to re-pair or add another watch to the module I carry, without hooking jumpers to everything and wiring up a Teensy when I need it.

The Pebble round is working great after some of the initial horrors.  Earlier, the Pebble update process was problematic, one update blew away my pairing to the WT12.  Also, the watch is stable now.  No guarantees, but I'm not seeing app restarts any longer, and I've got the calibration persisting.  It still appears possible to lose it, at least on my Pebble Time, possibly when bad code causes the app to crash outright.  Life on the bleeding edge, I can deal.

Another interesting feature, at least with the Round, the WT12 is paired using bluetooth, but the BLE channel is still accessible.  One day, I noticed by accident that the Pebble was still able to show me the Weather and Sunrise/Sunset day summary.  I should be able to pair the BLE Mini with the watch and maybe push glucose values to it.  Would allow me to store readings someplace (if I felt the need...), I add a custom alert device to really wake me up at night, the vibration on the Round doesn't wake me up as quickly as I'd like.  My other thought is changing the Pebble app to require a double tap to stop alerts.  I'll probably add this first, then do the hardware thing some rainy day.

Finally, thought I'd include a picture of the current device.  Similar to the part mockup in an earlier post.
This time, I used a small amount of hot glue to put the parts onto a piece of paper, then wired everything point to point.  This avoids the added thickness of a PCB.  If I do it again, I'll use smaller wires.  Also the "dead bugged" WT12 doesn't appear to interfere with the Wixel, which was a happy surprise.

Update:  Be careful when updating the Round with new code.  If it doesn't show you a status bar indicating an app is being loaded, it's not actually loading it.  Cloud Pebble will report the installation as successful.  From the Pebble app, you may see your application in the unsupported apps's category.  Remove it, then redeploy.

Friday, March 11, 2016

Smallest device with the smallest watch

I've always wanted the Analog watchface, probably why I put up with my ugly display for as long as I did.  Now with the the Pebble round, seemed appropriate to spend the time and get the Analog face working.

The 3'oclock position shows estimated time until 80/180.  Under the date will be the missed signal (!) and funny data(???) indicators.  12'oclock is the slope of the glucose readings followed by the Calibration slope.  9'oclock is Glucose.
The round pairs better with the Blugiga radio than it does with my iPhone, good thing.  It seems the best way to get paired to upgrade the App, is to reboot the watch.  Strange.

Still need to design and print a charger base.  Good day today, the 3d printer is working!

Here's a better picture with more indicators in use.

Monday, March 7, 2016

Bluegiga WT12 Controls all Pebbles

Did some searching and found a bluetooth chip that does SSP Master, which is used by all the pebbles.  My existing code still works, just the initial configuration of the board (which you can do through serial) is different.

SET BT AUTH * 0000
CALL b0:b4:48:9d:cc:08 1101 RFCOMM

This configures the board to connect and automatically reconnect to a watch.  Power=0, gets translated to -2, which is still enough power to cover my house.  Once paired with the watch and the Wixel in sleep, it's around 5ma.  With the Wixel actively listening it's approx 27ma.  When the Bluetooth module receives data it's 35ma.  Generally you're running at 5ma, the higher numbers are for a few seconds every 5 minutes.  The pebble appears to be "chatty", so you see frequent 35ma bursts, this may be an issue, but I think I can get 20 hours out of a 110 mAh battery.

I'll probably make this over the weekend:

That's the WT12 "dead bugged" on top of the Wixel.  Curious to see if I can get away with that.

Allot of useful information here: , this guy also sells a development board for the WT12 which makes it breadboard friendly.

Friday, February 26, 2016

More BLE Central

I would still like a "Band"...  I really can't wear the watch when doing hand to hand stuff etc.  A band is a little easier to get away with, and less likely to hurt someone.

A few weeks ago I stumbled on some posts for the Xiomi MI, band.  Cheap thing $30, Amazon gets it to me in 2 days.  I found websites that detailed how to communicate with it from a BLE Central device, so I thought cool, I'll get one.  Impulse buy.

This was the perfect use for my BLE Nano.  I already had some BLE Central code written that worked for communicating with the RFDuino.  Of course, this wouldn't work...
After about 8 hours, it came down to a parameter change on the connect, ex.>peerAddr,  Gap::ADDR_TYPE_PUBLIC, NULL, NULL);

My original code had a random address type.  This was quite maddening because I could connect with the MI from both Unix and my iPhone using "LightBlue".  

It wasn't until I connected that I realized the communication protocol's for the MI had changed. 
The current protocol is actually more standardized.  All alerts (buzzing) are through a standard BLE endpoint for "Immediate Alert".   LED control, not so much, I now realize LED control isn't exposed to an external device.  My plan had been to use the 3 led's as a sort of traffic light, or:
- led 1 = >200mg/dl
- led 2 = >100mg/dl
- led 3 = blink out the 10's every minute or so.

Or something like that, coupled with buzzing to queue me in on what's going on.  
If you look around for posts on the MI, you'll see the lights don't really work anyway.  They're triggered by an accelerometer that only responds to some bizarre form of hand waving, I got them to light up once or twice, the motion required being way to ridiculous for public presentation.

That said, could be an excellent vibrating alert device that can go a month on a charge.

Some other notes from this experience:
1. The BLE Nano (with MBED) doesn't really work with Windows 10, unless you're comfortable restarting windows frequently.  The Arduino version may be fine, I have one of each, but I have issues with BLE Central on the Arduino version.  In the end, I moved my development over to the Mac.  Additionally, opening and closing serial windows and dragging/dropping hex files is a PIA.  I was able to automate this to some extent with the Mac, one of the reasons I purchased a Mac, nice to finally put that to use.  See my github for a basic script.  In a nutshell, it's a ksh that watches the download folder for a hex file, moves it to the Nano, and launches a serial window.

2.  I don't think BLE sniffing is all it's cracked up to be.  I have an Ubertooth and a Nordic device and can hook them up to Wireshark.  With an RFduino I can see all the "Magic" packets (ATT etc).  With more proprietary devices like the MI or the Pebble, once these things pair, I don't see anything.  If you want to hack a BLE device, decompile the Android APK if one is available.

On to the Pebble watch.  Still going strong.  Found out from Pebble support that the aplite versions of the pebble support "Pin" pairing via bluetooth.  The new models only support ssp (simple secure protocol).  They also pointed out the mfg'r note for nRF51, which indicates that while ssp is in the command set, it doesn't actually work.  Allegedly there's a beta that will support ssp, and will pair with the Pebble Time.  Wait and see.