Bluetooth RfcommService

0 votes

I've two devices running Windows on them; a Raspberry PI 3B + with Windows 10 IoT and a Surface pro with Windows 10. Now, I'm attempting to establish a communication between the two. 

Here's my server at the Raspberry Pi:

private readonly Guid _rfcommChatServiceUuid = Guid.Parse("34B1CF4D-1069-4AD6-89B6-E161D79BE4D8");

private async void CreateServer()
    {
        _provider = await RfcommServiceProvider.CreateAsync(RfcommServiceId.FromUuid(_rfcommChatServiceUuid));
        _listener = new StreamSocketListener();

        _listener.ConnectionReceived += OnConnectionReceived;
        await _listener.BindServiceNameAsync(_provider.ServiceId.AsString(),SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);

        InitializeServiceSdpAttributes(_provider);
        _provider.StartAdvertising(_listener);
    }

    const uint SERVICE_VERSION_ATTRIBUTE_ID = 0x0300;
    const byte SERVICE_VERSION_ATTRIBUTE_TYPE = 0x0A;   // UINT32
    const uint SERVICE_VERSION = 200;
    void InitializeServiceSdpAttributes(RfcommServiceProvider provider)
    {
        var writer = new DataWriter();
        writer.WriteByte(SERVICE_VERSION_ATTRIBUTE_TYPE);
        writer.WriteUInt32(SERVICE_VERSION);
        var data = writer.DetachBuffer();
        provider.SdpRawAttributes.Add(SERVICE_VERSION_ATTRIBUTE_ID, data);
    }

 async void OnConnectionReceived(
StreamSocketListener listener,
StreamSocketListenerConnectionReceivedEventArgs args)
    {

        _provider.StopAdvertising();
        _listener.Dispose();
        _listener = null;
        _socket = args.Socket;

And, here's my client at the Surface Pro:

   var services = await DeviceInformation.FindAllAsync(
              RfcommDeviceService.GetDeviceSelector(RfcommServiceId.FromUuid(_rfcommChatServiceUuid)));

I don't understand why the services collection is still empty, can anyone tell me what's going on here?

Nov 2, 2018 in IoT (Internet of Things) by Bharani
• 4,660 points
1,074 views

1 answer to this question.

0 votes

Hard code the address on your client side. Here's the  RFCOMM connections' C code for both server and client: https://people.csail.mit.edu/albert/bluez-intro/x502.html

Also, here's a chat sample of Bluetooth RFCOMM for Windows(universal), that you can check out. 

answered Nov 2, 2018 by nirvana
• 3,130 points

Related Questions In IoT (Internet of Things)

0 votes
2 answers

PWA bluetooth: automatic connection and multiple connections at the same time

You can refer this:https://www.bluetooth.com/blog/how-one-wearable- ...READ MORE

answered Oct 6, 2020 in IoT (Internet of Things) by Niroj
• 82,880 points
1,426 views
0 votes
1 answer

Pair and connect new devices using Bluez5 DBUS API with C++

Although high-level APIs like Qt5, which also ...READ MORE

answered Oct 8, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
5,822 views
0 votes
1 answer

PWA : Using Bluetooth in my phone in Progressive Web Apps

Yes, you can access in Geo Location(for ...READ MORE

answered Dec 20, 2018 in IoT (Internet of Things) by Shubham
• 13,490 points
6,448 views
0 votes
1 answer

Multiple beacons for Articulation of Accurate User Location

Bluetooth really isn't ideal but there can ...READ MORE

answered Mar 15, 2019 in IoT (Internet of Things) by Upasana
• 8,620 points
675 views
0 votes
0 answers
0 votes
0 answers

Bluetooth 4.0 / Smart / Low energy on Samsung Galaxy S3

I'm trying to develop a Bluetooth 4.0 ...READ MORE

Apr 25, 2022 in AWS by Soham
• 9,710 points
393 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP