Search code examples
c#bluetoothtizen-wearable-sdktizen-web-app

How can I connect to a Bluetooth service on Gear S3?


I am writing a web app for the Gear S3 and a companion Win-App for UWP in C#. What I want it to do: S3 acting as a BT server, sending data, and the Win-App as a client, which is supposed to receive the data. In Tizen I used the registerRfcommServiceByUUID() function as below:

function publishTransferService() {

if(remoteDevice.isConnented){
    console.log("Connection Status: " + remoteDevice.isConnected);
    var TRANS_SERVICE_UUID = '5BCE9431-6C75-32AB-AFE0-2EC108A30860';
    adapter.registerRFCOMMServiceByUUID(TRANS_SERVICE_UUID, 'My Service', ServiceSuccessCb,
            function(e) {
        console.log( "Could not register service record, Error: " + e.message);
    });
}else{
    console.error("Connection Status: " + remoteDevice.isConnected);
    } 

In C# i try to connect to the service as follows:

        //to ulong converted MAC-Address of the Gear
        ulong gearBtAddress = 145914022804881;
        //create device-instance of the gear
        BluetoothDevice gearDevice = await  BluetoothDevice.FromBluetoothAddressAsync(gearBtAddress);
        //list the services found on the gear and connect to the one with
        //the same uuid as in tizen
        var gearServices = await gearDevice.GetRfcommServicesAsync();
        foreach (var service in gearServices.Services)
        {
            if(service.ServiceId == RfcommServiceId.FromUuid(Guid.Parse("5BCE9431-6C75-32AB-AFE0-2EC108A30860")))
            {
                _service = await RfcommDeviceService.FromIdAsync(service.ToString());
            }

        }

The Problem I am facing is, that the C# won't find the wanted Uuid, although it finds several other uuids. I don't see where it gets lost?

Thanks in advance.


Solution

  • I solved it myself, the problem was, that the UUID was uncached. Adding the following was all to do:

            var cacheMode = BluetoothCacheMode.Uncached;
            var gearServices = await gearDevice.GetRfcommServicesAsync(cacheMode);