AJBUCH
AJBUCH

Reputation: 1

Why cant I connect to the hands free service on my device?

I have my gear s2 watch (tizen 2.3.2) connected to my samsung galaxy s3 (android 4.3) over bluetooth using Tizen Bluetooth API. Using the MAC address of the phone, I am able to "discover" 16 different UUIDs, including 0000111F-0000-1000-8000-00805F9B34FB, the UUID for the HFP service, as I understand. But when I attempt to connect to that service, I get no response, neither the successCallback nor the errorCallback. Interestingly, doing the same for the Serial Port UUID (1101), I'm able to connect to the service and even get messages through the socket when my phone receives a call or text, no problem. So, why do I get no response when attempting to connect to the Hands-free service (UUID 111F)?
Here's the code I'm using:

function getPhoneBatteryLevel()
{
    try {
        writeLog("Initializing.");          
        bluetoothAdapter = tizen.bluetooth.getDefaultAdapter();
        bluetoothAdapter.getDevice("50:A4:C8:D4:95:E2",onGetDeviceSuccess,onGetDeviceError);
        writeLog("Looking for device.");
    }
    catch (err)
        {writeLog("getPhoneBatteryLevel-ERROR:"+err);}
}

function onGetDeviceSuccess(device)
{
    try {
        if (device.isBonded && device.isConnected){
            writeLog("Found connected Device.");
            var uuidStr="";
            for (var i=0;i<device.uuids.length;i++)
                {
                    if (device.uuids[i].substr(4,4)==="111F")
                        {
                            uuidStr = device.uuids[i];
                            writeLog("Found UUID at "+i+":"+uuidStr);
                            break;
                        }
                }
            if (uuidStr.length>0)
                {
                    device.connectToServiceByUUID(uuidStr, onServiceConnectSuccess, onServiceConnectError);             
                    writeLog("Attempted Connect To Service.");
                }
        }
        else {
            writeLog("Device not connected.");
            }
    }
    catch (err)
        {writeLog("onGetDeviceSuccess-ERROR:"+err);}
}
function onServiceConnectSuccess(socket)
{
    writeLog("Connected to service UUID="+socket.uuid);
}

After running this code, my log file looks like this:

Initializing. 
Looking for device. 
Found connected Device.
Found UUID at 6:0000111F-0000-1000-8000-00805F9B34FB
Attempted Connect To Service.

and that's it... I expected/hoped to also see "Connected to service UUID=0000111F-0000-1000-8000-00805F9B34FB" upon a successful connection via the successCallback..or at least a similar error written to the log via the errorCallback, but I got neither. Yet, the hands-free service appears to be running on the phone. And of course, when the phone is in my car, the hands free functions work fine, so I know the phone supports it. Where am I going wrong?

UPDATE: After a few more tests, I have some additional clues. I have two devices: an iPhone S5 (iOS 11.2.6) and a Galaxy S3 (android 4.3). After "discovering" and connecting to each, I was able to loop through the services (uuids). 0x111F is on both. And there are several other uuids that these two devices have in common. I tried connecting to all of these common services on both devices. The results relative to the two devices were identical - on both, I was able to connect to some services, got NotFound errors on others and on the one I'm really interested in, I got no callback at all. So, allow me to refine my question. I was able to connect to the following services that my two devices have in common: 110A [A2DP], 110C [AVRCP], 112F [PBAP], 1132[MAP]

But, even though UUID 0x1200 is in both devices' lists of available UUIDS, the response to my attempt to connect to the service called my errorCallBack routine with a "Not Found" error. This happened on both devices. Why would this be Not Found when it was in the list of valid UUIDs?

And most disappointing of all (to me, anyway), is that I still get no response at all (no success callback and no error callback) when I attempt to connect to the Hands Free Profile service, 0x111F. Why wouldn't I get a response - either a success call back or an error call back?

Upvotes: 0

Views: 618

Answers (1)

Iqbal hossain
Iqbal hossain

Reputation: 1816

I tried to connect Gear S3 to hands free service of my Galaxy S6 Edge. At first i tried to get the list of available service of my device. I have found a list of uuid. Here are the prefix of these

1103
1105
110A
110C
1112
1115
1116
111F
112D
112F
1200

I have seen 111F is available here. I thought i would be able to connect that. This log was shown on error callback of connectToServiceByUUID

Error while connecting: 0000111F-0000-1000-8000-00805F9B34FB service Not found 

After that i tried with 112F ( which is Phonebook Access Profile). In this case i have successfully connected to the service and got a popup message on my S6 Edge to allow the request ( That means the code is correct). But i have found empty data by calling readData function.

Entered BluetoothDevice.connectToServiceByUUID()
socket connected on service 0000112F-0000-1000-8000-00805F9B34FB 
Opened connection to remote device Galaxy S6 edge 
Entered BluetoothSocket.readData()
[] 

And my main code snippet is here, var adapter = tizen.bluetooth.getDefaultAdapter();

    adapter.getDevice('08:EE:8B:40:E9:38', onBondingSuccessCallback, onErrorCallback);

       function onBondingSuccessCallback(device) { 
              console.log(device.uuids.join("\n"));
              var serviceUUID = '0E4D4A34-00A0-B708-EAAC-6043A45596ED';
              device.connectToServiceByUUID(serviceUUID,function(sock{
              console.log('socket connected on service '+ serviceUUID);
              console.log ("Opened connection to remote device " + sock.peer.name);
             console.log(sock.readData());
           // socket = sock;
             console.log ("The socket is " + sock.state + " and service's UUID to which it is connected is  " + sock.uuid);
        }, function(error) {
             console.log('Error while connecting: '+ serviceUUID+ ' service ' + error.message);
        });
    }

    function onErrorCallback(e) {
        console.log('Cannot get a bonded device , reason: ' + e.message);
    }

Later i tried with Samsung Z3 instead of S6 Edge. Result was same. So i am not sure if the API is buggy or i am doing something wrong. I have posted it as answer as your were requesting to post my code.

Upvotes: 0

Related Questions