Getting Started with the Microsoft Band SDK

I’ve finally jumped into the ‘wearable’ world by purchasing the Microsoft Band 2. Practical use of this particular genre of technology had escaped me but I felt differently about Microsoft’s Band product since it seemed to do more than similar products. After a few days of use I became interested in what else I could do with it. A few short minutes later I was up and running in Visual Studio. Let’s get started!


The first thing to to is download the Microsoft Band SDK. You’ll have a few options depending on your platform; use Nuget (https://www.nuget.org/packages/Microsoft.Band/) or download the zip of the SDK located at https://developer.microsoftband.com/bandSDK. I’d recommend downloading the SDK for later reference for the fantastic examples provided by Microsoft.

Next, we’ll create a new Universal App that will run on your device and add a reference via NuGet and we’re ready to write some code.

01.NuGet-Reference
Microsoft.Band SDK works for Band 1 and Band 2

When the new project is created its a few lines of code from the SDK sample to ensure there is at least one paired Band to work with, connect to it, and collect samples.

 IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();
if (!pairedBands.Any())
{
    System.Diagnostics.Debug.WriteLine("No paired bands found.");
    return;
}

// Connect to the Microsoft Band.
using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
{
if (!bandClient.SensorManager.Altimeter.IsSupported)
{
System.Diagnostics.Debug.WriteLine("Altimeter sensor is not supported with your Band version. Microsoft Band 2 is required.");
return;
}

// the number of Altimeter samples received
int samplesReceived = 0;

// Subscribe to Altimeter data.
bandClient.SensorManager.Altimeter.ReadingChanged += (s, args) =>
{
System.Diagnostics.Debug.WriteLine(args.SensorReading.FlightsAscended);
System.Diagnostics.Debug.WriteLine(args.SensorReading.FlightsDescended);
System.Diagnostics.Debug.WriteLine(args.SensorReading.StepsAscended);
System.Diagnostics.Debug.WriteLine(args.SensorReading.StepsDescended);
samplesReceived++;
};
await bandClient.SensorManager.Altimeter.StartReadingsAsync();

// Receive Altimeter data for a while, then stop the subscription.
await Task.Delay(TimeSpan.FromSeconds(5));
await bandClient.SensorManager.Altimeter.StopReadingsAsync();

System.Diagnostics.Debug.WriteLine("Done. {0} Altimeter samples were received.", samplesReceived);
}

The above code snippet can act as a template for how you will work with the other sensors. The payloads will be different and others such as the Heart Rate sensor will require user consent before being able to read data. These are clearly defined in the SDK documentation.

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s