2

I have a task to communicate with a Bluetooth device (which is not Low Energy - BLE) from a Windows Phone 8 App and latter from Surface App.

I came across this link http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207007(v=vs.105).aspx which does mention about Bluetooth integration, however it doesn't clearly says if this is for only BLE devices or not?

Please can someone point me to a code sample which I can use to interface (send and receive) data from Bluetooth device. Esp, a RFCOMM e.g., if possible

Really appreciate.

Guru Kulkarni
  • 153
  • 3
  • 10
  • If it is not possible, please can someone point me to a link which explains the reasons why it is not possible. And worst case can I achieve this through Windows 8 Desktop Application? – Guru Kulkarni May 31 '13 at 14:47

1 Answers1

5

The following example shows how to create a Bluetooth RFCOMM socket connection to connect your app to a device:

Windows Phone 8 Networking Samples

Basically, you have to create a socket connection with a paired Bluetooth device:

PeerFinder.AlternateIdentities["Bluetooth:PAIRED"] = ""; 
var available_devices = await PeerFinder.FindAllPeersAsync(); 
if (available_devices.Count > 0) 
{            
   PeerInformation pi= // Select the device  
}
StreamSocket socket = new StreamSocket(); 
await socket.ConnectAsync(pi.HostName, "1");

This example was shown in Build 2012 conference. You will find the video of the presentation here:

Windows Phone 8: Networking, Bluetooth, and NFC Proximity for Developers (Build 2012)

anderZubi
  • 6,414
  • 5
  • 37
  • 67
  • Do you know if the same PeerFinder class can be used on Surface RT tablet app if I wanted to connect to a Bluetooth Enabled external device (not BLE)? Or are there different RT API's for communicating with Bluetooth enabled devices in Windows RT 8? Basically I need to know if there is a unique way in which I can achieve this for a) Windows Phone 8 App, b) Surface Pro and c) Surface RT app and d) Windows 8 desktop application. If not can someone specify which ones are appropriate for a, b, c and d – Guru Kulkarni Jun 03 '13 at 10:33
  • I haven't been able to connect to a bluetooth device from a Windows Store app. Althought it has the same `PeerFinder` class, it seems that it cannot connect to bluetooth devices. At least I haven't been able to do so. For desktop apps you can use `SerialPort` class. There is not unique way to achieve that in all platforms. However, you could wrap the PeerFinder functionality in a class called SerialPort to use it the same way you would in a desktop app. – anderZubi Jun 03 '13 at 10:44
  • Thanks for info. Do you know (or have you found) of any link which confirms that PeerFinder cannot be used with Windows Store Apps (Win RT)? – Guru Kulkarni Jun 03 '13 at 10:46
  • No I haven't found such confirmation, and it is not clear in official documentation, but havn't been able to use `PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";` in a Windows Store app. – anderZubi Jun 03 '13 at 10:53
  • 1
    Windows Store apps (running in any target machine that supports it) do not support Bluetooth PeerFinder. A little more info [here](http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/b1f71dd4-ee75-4cd2-921f-5d4eadb31952) – Guru Kulkarni Jun 04 '13 at 12:57
  • 1
    @ anderZubi Is that possible to communicate with more then one winodws phone. i.e: One WP8 act as server and other two as client. If Client quits the communication then, it will sends to server and other client. like that.? – SaravanaKumar Oct 15 '13 at 11:34