×
Namespaces

Variants
Actions

Introduction to Bluetooth support on Windows Phone 8

From Nokia Developer Wiki
Jump to: navigation, search

This article aims to briefly explain the current WP8 Bluetooth capabilities and later focuses on exploring the near future opportunities that a WP8 developer should keep in mind with regards to Bluetooth 4.0 and more specifically Bluetooth Low Energy feature.

See Also

Warning.pngWarning: At time of writing (31st October 2013) no public APIs are available for accessing features of Bluetooth 4.0 LE on any device.
Underlying support (without public APIs) for Bluetooth 4.0 LE is enabled on all Nokia Lumia devices via the Nokia Lumia "Black" update.

WP Metro Icon WP8.png
Article Metadata
Compatibility
Platform(s):
Windows Phone 8
Article
Created: Aady (09 Dec 2012)
Last edited: influencer (19 Mar 2014)

Contents

Introduction

Bluetooth is a wireless communication technology through which devices within 1 meter (class 3), 10 meter (class 2) or 100 meter (class 1) proximity can communicate with each other. It is a simple, secure, and widely adopted technology. It can handle both data and voice for wireless communication which facilitates its real world application in various areas from hands-free headsets, file transfers, health sensors,printing, synchronizing desktop and mobile phones, and the list goes on.
Windows Phone always had this technology inbuilt but was having limited Bluetooth capabilities. But with WP8 this scene has changed dramatically and it adds much more functionality to the Bluetooth stack.

Why Bluetooth when NFC is around?

NFC is relatively a new technology to Bluetooth and WP8 developers are more enthusiastic in exploring its features. Well certainly this is great and we must explore NFC capabilities, but at the same time we should not ignore the opportunities that Bluetooth 4.0 and especially BLE will be offering.
In upcoming 4-6 months the market will be flooded with sensor devices enabled with BLE due to its 'unique' low energy communication, efficiency and cheap production. WP8 developers should keep an eye on this and be ready to make use of the opportunity and 'Time It Correctly' to the market of Smart Bluetooth Ready devices like WP8.

WP8 Bluetooth communication

WP8 supports two Bluetooth communication scenarios: app to app, and app to device. The communication is established using a StreamSocket connection.

App to App

In this communication, one phone will be a “server” — listening to incoming requests and responding to them — and another phone will be the “client” — connecting to the server and issuing requests. When both apps accept the connection, a stream socket is opened between them, through which the apps communicate.
App to App Bluetooth communication only needs the ID_CAP_PROXIMITY capability, so it can be used by internetworking-free apps.
Example code can be found on the below link which is developed by Windows Phone SDK Team and demonstrates basics of app to app communication: Bluetooth-app-to-app-sample

App to Device

In this communication, an app uses Bluetooth to find a device that is offering a service that the app wants to access. When both the app and device accept the connection, a stream socket is opened between them, through which the app and the device communicate.
App to device apps need ID_CAP_PROXIMITY and ID_CAP_NETWORKING capabilities.
Example code can be found on the below link which is developed by Windows Phone SDK Team and demonstrates basics of app to device communication: Bluetooth-app-to-device

For more information on Bluetooth API, see Bluetooth for Windows Phone 8

Serial Port Profile (SSP)

A Native SSP API doesn’t exist out of the box in WP8 SDK as of now, but that doesn’t limit the developers from using SSP. Developer needs to push a bit more and can built a self-implementation of SSP using RFCOMM and getting a socket via peerfinder.

Although the focus of this article is about understanding the WP8 & BLE opportunities, the below small code snippet will help developers in avoiding a common mistake while implementing SSP:

STEP 1: Connect to the desired device over RFCOMM

PeerFinder.AlternateIdentities["Bluetooth:PAIRED"] = ""; 
var available_devices = await PeerFinder.FindAllPeersAsync();
if (available_devices.Count == 0)
{
return false;
}
else
{
PeerInformation pi= // Get the required device using
// index or searching for the device name
}
StreamSocket socket = new StreamSocket();
await socket.ConnectAsync(pi.HostName, "1");

STEP 2: Direct winsock to perform an SPP lookup

await socket.ConnectAsync(pi.HostName, pi.ServiceName);

Note.pngNote: More likely, developers get stuck at Step 2 and get empty ServiceName. This can be easily resolved by passing the service GUID. Unfortunately this alternative is not documented well in MSDN and hence I thought it is good to mention here.

Example:

await socket.ConnectAsync(pi.HostName, "{21EC2020-3AEA-1069-A2DD-08002B30309D}");

WP8 and Bluetooth 4.0

Currently Windows Phone 8 supports Bluetooth 3.1 and includes compatibility with following profiles:

  • Advanced Audio Distribution Profile (A2DP 1.2)
  • Audio/Video Remote Control Profile (AVRCP 1.4
  • Hands Free Profile (HFP 1.5)
  • Phone Book Access Profile (PBAP 1.1)
  • Object Push Profile (OPP 1.1)
  • Out of Band (OOB) and Near Field Communications (NFC)

But the good news for the developers is that both the Lumia 820 and 920 will support Bluetooth 4.0 as per Bluetooth.org. Bluetooth WCN3660 chipset exists in Lumia 820 and 920 which not only has Bluetooth 4 capabilities but also has an FM transceiver, so it’s just the matter of time that WP8 will get a stack update. And due to its real world need and demand Microsoft will certainly put the required update soon.

There are two important terms that need to be understood:

Bluetooth Smart Ready Devices
These devices that receive data sent from Bluetooth/ Bluetooth Smart devices and with the help of sophisticated software mechanism transform this data into useful information. So when our WP devices will receive the BT 4.0 support they will fall in this bucket and be known as Bluetooth Smart Ready Devices.
SmartReady.png

Bluetooth Smart Devices
These are the devices which gather the raw data and sent it to Smart Ready devices for further processing of the retrieved raw data.
Examples: Heart-rate monitors, blood-pressure meters, sport gadgets, etc.
Smart.png

WP8 and Bluetooth Low Energy (BLE)

Bluetooth 4.0 includes various improvements (like fast speed) but most significant feature is the support for Bluetooth Low Energy (BLE) devices. It will enable to aggregate data from various Smart Bluetooth devices, like heart rate monitors, sport gadgets, thermometers, etc. Devices using BLE are expected to consume much less power and faster set-up time as compared to the older Bluetooth devices. Now with BT 4.0, your Bluetooth devices are expected to work for years using the small button battery.
The Lumia devices are specified to have BLE capabilities and as mentioned above we expect a stack upgrade coming to WP8 and then the WP8 devices will be ‘Bluetooth Smart Ready’. Once this is done it will open immense opportunities for WP8 developers to interact with a lot of ‘Bluetooth Smart’ devices which will change the way people interact with objects in real world.

Let’s have a look at the various kinds of WP8 applications that can be developed to take benefit of this technology:

Home Automation & Security

It will be cheap and easy for companies to add the wireless connectivity to home appliances and all those smart devices can connect to your WP8 Smart Ready devices to take the appropriate actions as specified by the users.

Following WP8 apps can be developed:

  • Morning TeaMaker - An app that will trigger the TeaMaker once the morning alarm in your phone is activated.
  • Home Security – An app will receive data from web cam for movement and triggers alerts based on that. The same app can also receive data from door (equipped with Bluetooth chipset) movements.
  • Auto Lights on/off - An app that will trigger the lights of lamps inside your room as you enter or leave the room.
  • Room Temperature control - An app that reads from thermometer and sends appropriate adjustment signals to you Air conditioner.
  • Multimedia control – An app to control your T.V/Music/Radio systems. Now all have just a single common remote control i.e WP8 device. App can also be programmed smartly to auto shutdown media devices at a specific time at night.

BTsmartReady.png

Health Monitoring

Health segment will be the most important market that WP8 developers should target. In a study, analysts predicts that Global Wearable Wireless Sensors market to grow at a CAGR of 110% over the period 2010–2014. WP8 apps can receive data from this body sensors and process the data.

  • Heart Rate monitor – An app that tracks your heart rate through the Heart rate sensor device.
  • Glucose meter - An app that tracks your glucose level through the Glucose level sensor device.
  • Calorie Tracker - An app that tracks your calorie burned through Trade Mills, cycling, etc.
  • Blood pressure monitor - An app that tracks your blood pressure through the Blood-pressure sensor device.

Sports Monitoring

Athletes and sports professionals take their sports activities very seriously and technology is striving to help them to track their improvements and activities to give them concrete results to analyze their performance.

  • Pedometer - An app to track daily exercise.
  • GPS Activity Tracker - An app to track how far you can walk, run or cycle and store your daily records.
  • Heart Rate monitor – An app that tracks your heart rate through the Heart rate sensor device.

And even as we speak, we can see some great gadgets already in market manufactured by leading sports company – Nike.

  1. Nike+ basketball and training shoes
  2. Running Tracker


All the above App development scenarios are just a few samples; possibilities and real world opportunities are endless.

WP8 and Bluetooth Low Energy (BLE) (continue)

New BT 4.0 APIs (including BLE) are located in \Windows\BLUETOOTHAPIS.DLL on your phone (native code only). These API are similar to the Windows 8/8.1 and well documented on MSDN. For example, see Bluetooth Low Energy Functions

Summary

BLE has a lot of potential to change the way we interact with devices and the way devices interact with each other. With Smart Ready WP8 we can make life of common man even better and in a cost effective way.

References:
Bluetooth for Windows Phone 8
Bluetooth
Nokia_Lumia_920_and_820_certified for Bluetooth 4.0

This page was last modified on 19 March 2014, at 22:22.
2180 page views in the last 30 days.
×