Microsoft Band is a wearable device form Microsoft, which has 10 inbuilt sensors which provides health related information about the wearer. Microsoft Band SDK allows developers to access the sensors available on the band, and built our own application out of it. In this post you will see how to connect a windows app to Microsoft band and read Heart Rate sensors data from the band.
Prerequisite
Hardware
- Microsoft Band
Software
- Microsoft Band SDK
- You can install Microsoft Band SDK through nuget
- Go to Manage NuGet
- Search for Microsoft.Band
- install it.
Note: At present there is no Simulator for Microsoft band. You need actual Device for the development.
Here is a few simple steps that will get you started with developing application using Microsoft Band.
Step 1
Start Visual Studio 2013 and got to File-> New ->Project, where you can see the section Visual C# Templates -> Store Apps -> Universal then select Blank Apps(Universal Apps).
Step 2
Get the list of Microsoft Bands paired to the device ( Phone / Tablet) , to do this we need to call the method GetBandsAsync from the BandClientManager Class.
IBandInfo[] bandsPaired = await BandClientManager.Instance.GetBandsAsync();
Now the bandsPaired contains the list of all bands paired. Multiple Microsoft bands can be connect to a single phone. In our sample we are going to connect to the first band.
Step 3
Connecting the App to the paired Band. In order to connect the band we need to pass the band info as parameter to the ConnectAsync from the BandClientManager Class.
bandClient = await BandClientManager.Instance.ConnectAsync(bandsPaired[0]);
Now the band gets connected to the app.
Step 4
Check whether the user has given permission for the app to read band’s sensor data. If the permission is not provided then request or the permission
if (bandClient.SensorManager.HeartRate.GetCurrentUserConsent() != UserConsent.Granted) { await bandClient.SensorManager.HeartRate.RequestUserConsentAsync(); }
Step 5
Subscribe for the reading changed Event of the HeartRate Sensor.
bandClient.SensorManager.HeartRate.ReadingChanged += HeartRateReceived; private void HeartRateReceived(object sender, BandSensorReadingEventArgs<IBandHeartRateReading> e) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this.Heartrate.text = e.SensorReading.HeartRate.ToString(); }); }
Step 6
Start Reading the HeartRate sensor, the app start listening to the ReadingChanged event after this method call.
await bandClient.SensorManager.HeartRate.StartReadingsAsync();
Step 7
If you want to stop reading from the sensor, then use the following method.
await bandClient.SensorManager.HeartRate.StopReadingsAsync();
I hope this post might help in getting started in creating apps to connect with Microsoft Band. Stay tuned to get more post on developing app using Microsoft Band and Band SDK.
Pingback: Dew Drop – July 23, 2015 (#2059) | Morning Dew
Pingback: .NET Tips and Tricks from Daily .NET Tips – ( Visual Studio 2015, Windows Universal App Development, Microsoft Band, Xamarin ) – July 2015 Links | Abhijit's World of .NET
Pingback: Internet of Things (IoT), Mobility, Azure, Universal Windows Platform and Devices – The Daily Developers Links – #1 | Abhijit's World of .NET