Tuesday, December 12, 2017

Android Wear (Finally)

So, I left this project alone for a while, then started it up again yesterday, and now, it just works.
I'll attribute this to problems with knowing if the updated code actually makes it onto the watch.
Maybe a restart caused the new code to run.

I have it running both as a watchface and as a complication.  Downside to the complication is vibration alerts don't work.   Alerts are good.  Also, I can't see it if I look quickly.

The watchface design, leaves allot to be desired for now, but that's on me.

Again, not sure why this works now.  Maybe the watch OS got updated...
My last change was to shutdown the ble connection every few minutes and force the watch to reconnect.  I'm hoping this forces the app to stay "awake", which it appears to do.  It's good for about 12 hours, I can probably improve that by leaving the ble up longer, but who knows at what point the device will go to sleep...  Other downside to the watch, it's only good to about 35% of battery and it doesn't alert when the battery level is low, it just dies.

Also, I did away with the Sweetblue api's and wrote the bluetooth from scratch.  There was too much going on there that I couldn't follow.

12/29 update
Getting up to 15 hours of use now.  Have to remember to turn WIFI off, sometimes it defaults to on after a restart.  Works reliably for days.  Can also run the battery down closer to zero.
Currently, stopping and restarting the Service that holds my Bluetooth intent every 10 minutes(this is in the code).
Somewhere between 10 and 15 minutes is the tipping point, where Bluetooth becomes unusable after several hours.

2/25 update
Looks like watch firmware improved, no longer having WIFI turn on.  Battery life is 30+ hours.

Friday, October 20, 2017

Android Wear Success ( or Not)

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.
11/27... Basically, this is a failure.  Only works for a few hours at best, appear to be fighting with power management.  Most telling thing I've noticed, at some point when the watch has been untouched, the "Tick" event stops (every minute an event normally fires).

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 192.xxx.xxx.xxx".  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: http://www.keyglove.net/2011/03/24/bluegiga-wt12-bluetooth-module-connection/ , this guy also sells a development board for the WT12 which makes it breadboard friendly.