Microsoft Band API

So I just started looking at the SDK for the Microsoft Band. It’s pretty good, but bear in mind that there are limitations, for example, you can only gather “live” sensor data – there’s no way to get any cached stats that may (or may not) be on your device.

Having said that, here’s a quick overview of using the SDK.

Microsoft Band
The Band

Preparing the solution

First thing to do here is to make sure your band is paired with your phone, turned on and active. Once that’s done, open Visual Studio and create a new phone project.

The SDK is available via NuGet, so add a reference to it.

You should see that references have been added to the required assemnblies, but also your package.appxmanifest file will have been updated with the following device capabilities.

These allow the app to communicate with your Band.

Now you can get going.

Connecting to your Band

In your page, get a list of the paired band devices on the system with the following command. Note that I return from the method if there are no paired Bands. You’ll need to set a using reference to Microsoft.Band.

Once you have your list of Bands, you can connect to one. In this case, I’m assuming we always want to connect to the first connected device, but you can modify this bit to suit your needs.

Note: The tutorials suggest you wrap the returned client instance in a using block, but if you do that then later steps like collecting sensor data won’t work because the client is disposed when this method returns. I hold a local reference to the client object and dispose it in OnNavigatedFrom();

At this point we can start getting basic data back, like the hardware and software versions.

Gathering sensor data

Now we get to the fun stuff. Assuming you followed my advice above about holding a local reference to the client object, you can start getting sensor data back. In this case, the HeartRate data.

Add a using statement for Microsoft,.Band.Sensors, then you can subscribe to events.

Since all this work takes place on its own thread, you’ll need to do a little bit of juggling to get this data onto the screen. Specifically use the CoreDispatcher to invoke the action on the UI thread. You might like to set up a method to keep this simple…

and then call it like so…

for example.

Next time – more on sending notifications and personalising your Band.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">