For my example, I worked off the Sensors example project for Windows Phone 8.1 and made some customizations. The app consist of a simple button that initiates our connection to the Band and starts taking readings. You can customize the Sensors project as well or you can grab my copy from GitHub. You can get the SDK from nuget by using the following command. This will add the necessary project references.
Install-Package Microsoft.Band -Pre
Start by editing the XML of the Package.appxmanifest file and add the DeviceCapability section for Microsoft Band inside the Capabilities element.
<DeviceCapability Name="bluetooth.rfcomm"xmlns="http://schemas.microsoft.com/appx/2013/manifest">
<Device Id="any">
<!-- Used by the Microsoft Band SDK Preview -->
<Function />
<!-- Used by the Microsoft Band SDK Preview -->
<Function />
</Device>
</DeviceCapability>
You also need to add the Proximity capability as well but you can do that through the UI.
Now, we’ll work on adding some functionality to MainPage.xaml. This consists mainly of a few TextBlocks and a Button. Clicking the button will invoke our code to connect to Band and take a reading. Create an event handling method for the button and mark it with async. Now, we first need to get the paired Bands to the phone. This assumes you have already paired your Band in the Bluetooth settings of the phone.
// Get the list of Microsoft Bands paired to the phone.
IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();
if (pairedBands.Length < 1)
{
this.textBlock.Text = "Band not paired.";
return;
}
To connect to Band we create an IBandClient in a using block.
using (IBandClient bandClient = awaitBandClientManager.Instance.ConnectAsync(pairedBands[0]))
{
}
Now we can read from the Skin Temperature sensor. To do this, we bind an event handling method to theReadingChanged event of the SkinTemperature class. We’ll cover the event handling method just below.
bandClient.SensorManager.SkinTemperature.ReadingChanged += SkinTemperature_ReadingChanged;
Finally, we call StartReadingsAsync to start taking readings from Band. We follow it with a delay of a minute before calling StopReadingsAsync to stop taking readings.
await bandClient.SensorManager.SkinTemperature.StartReadingsAsync();
await Task.Delay(TimeSpan.FromMinutes(1));
await bandClient.SensorManager.SkinTemperature.StopReadingsAsync();
In the event handling method, the value of e has a type ofBandSensorReadingEventArgs<IBandSkinTemperatureReading>. We can get the skin temperature in Celsius by using the SensorReading property. For us Americans, we can convert that to Fahrenheit. You know the formula right? C * (9/5) + 32. :). Using the Dispatcher, we then write the value of the reading to the UI.
private async void SkinTemperature_ReadingChanged(object sender,BandSensorReadingEventArgs<IBandSkinTemperatureReading> e)
{
IBandSkinTemperatureReading temperatureReading = e.SensorReading;
string text = string.Format("Temperature: {0}C", temperatureReading.Temperature);
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {this.textBlock.Text = text; }).AsTask();
}
Now you are ready to run the program on your Windows Phone and see how hot you are! Plug your Windows Phone into your PC via the USB port and then debug the program and be sure you choose Device in the options. You can’t do this with the emulator.
This example really has zero practical value but I expect that we’ll see more opened up in the API in future versions. If you have been interested in seeing what you can do with it as a developer, it’s worth checking out though. For more examples of working with Band across platforms, be sure and check out the published documentation.
References : http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2015/03/31/reading-your-skin-temperature-using-the-microsoft-band-sdk-preview.aspx