locked
Exception WP8.1 Bluetooth Connectivity using RFComm API RRS feed

  • Question

  • Hi,

    I am trying to connect BT SPP Device using WP8 SDK.

    Background: WP8 has connectivity issues but it needed encryption and StreamSocket wouldn't upgrade to SSL.. and we couldn't specify SSL in ConnectAsync ether.

    Today we upgraded the code to WP8.1. Here is the code snippet

    Full project can be downloaded from: http://1drv.ms/1gXN0qs

    DeviceInformationCollection DeviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
    
    var numDevices = DeviceInfoCollection.Count();
    
    if (numDevices == 0)
    {
        MessageDialog md = new MessageDialog("No paired devices found", "Title");
        await md.ShowAsync();
    
        return;
    }
    
    DeviceInformation DeviceInfo = DeviceInfoCollection[0];
    
    StreamSocket socket = null;
    try
    {
        var service = await RfcommDeviceService.FromIdAsync( DeviceInfo.Id);
    
        socket = new StreamSocket();
    
        // Note: If either parameter is null or empty, the call will throw an exception
        await socket.ConnectAsync(service.ConnectionHostName, service.ConnectionServiceName, service.ProtectionLevel);
    
    
        // If the connection was successful, the RemoteAddress field will be populated
        MessageDialog md = new MessageDialog(String.Format("Connected to {0}!", socket.Information.RemoteAddress.DisplayName), "Title");
        await md.ShowAsync();
    }
    catch (Exception ex)
    {
        socket.Dispose();
        socket = null;
    }

    There are two distinct errors I see

    1) No more data is available. (Exception from HRESULT: 0x80070103)

    2) A socket operation was attempted to an unreachable network

    Its worth noting that this is a Universal App solution and I can run / connect successfully if I run Windows 8.1 project. The same code however returns this error.

    Capabilities have been correctly defined.

    Capabilities for Windows Phone

    <Capabilities>
      <Capability Name="internetClientServer" />
      <DeviceCapability Name="proximity" />
      <m2:DeviceCapability Name="bluetooth.rfcomm">
        <m2:Device Id="any">
          <m2:Function Type="name:serialPort"/>
        </m2:Device>
      </m2:DeviceCapability>
    </Capabilities>

    Capabilities for Windows 8.1

    <Capabilities>
      <Capability Name="internetClient" />
      <Capability Name="privateNetworkClientServer" />
      <DeviceCapability Name="proximity" />
      <m2:DeviceCapability Name="bluetooth.rfcomm">
        <m2:Device Id="any">
          <m2:Function Type="name:serialPort"/>
        </m2:Device>
      </m2:DeviceCapability>
    </Capabilities>

    I am running out of ideas.


    Hermit Dave



    • Edited by Hermit DaveMVP Friday, May 23, 2014 10:12 PM added repro link
    Friday, May 23, 2014 9:08 PM

Answers

  • having said that, we tried on a device dev machine and connectivity is fine. I do occasionally get connectivity errors and uninstalling the app / restarting the device(s) helps

    Hermit Dave

    Wednesday, May 28, 2014 3:05 PM

All replies

  • I'm running into same problems. Did you have any luck with this? I've tried all different capability configurations, establishing connections in different way/order, etc. Nothing seems to work.
    Tuesday, May 27, 2014 8:47 AM
  • additionally using the same code in SL 8.1 app results in "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

    Hermit Dave

    Tuesday, May 27, 2014 8:54 AM
  • having said that, we tried on a device dev machine and connectivity is fine. I do occasionally get connectivity errors and uninstalling the app / restarting the device(s) helps

    Hermit Dave

    Wednesday, May 28, 2014 3:05 PM
  • Thanks for this post i have been getting access denied exception when i did nt use below line

    <m2:Function Type="name:serialPort"/>

    adding this solved my issue

    Friday, November 14, 2014 6:59 AM
  • Woah. You saved my life. Tried every possible way to overcome Bluetooth exception error 0x80070005.

    Finally saw this after 3 days of hard coding.

    You are awesome.

    Sunday, February 15, 2015 1:47 PM