0

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?

AJBUCH
  • 1
  • 3
  • You may check Bluetooth sample app from Tizen Studio – Iqbal hossain Mar 29 '18 at 08:23
  • Thanks! The sample was helpful in that it confirmed what I was trying to do, but didn't go so far as to help me understand why 0x111F isn't found. I did fool around with it a bit more and got a few more clues. I edited my original question with this add'l info. – AJBUCH Mar 30 '18 at 02:06
  • In case of 111F i am getting Not Found message .... and for 112F i can connect but getting only "[]" by calling readData function ! Although i am getting a popup message in my Galaxy S6 phone to allow phonebook ( 112F) – Iqbal hossain Apr 02 '18 at 09:02
  • Thanks for trying it! That you got a different result gives me renewed hope. Would you mind posting the code you used? I want to see what I did differently. Also, I see you tested with a Galaxy S6...is this from a galaxy gear s2 or s3? If so, I assume you used Tizen Bluetooth API, yes? By the way, 112F is the Phonebook Access Profile. I get the same result as you in that case. – AJBUCH Apr 03 '18 at 10:52

1 Answers1

0

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.

Iqbal hossain
  • 1,778
  • 3
  • 17
  • 24
  • Thanks for posting this! I tried running your code. One problem is that in the anonymous function, you are missing ")" after the sock parameter. And, I assume you were trying to connect to a different service that I don't recognize. Aside from these minor things, I was able to run your code but got slightly different results...again, rather than the error callback when trying 111F, I got no response at all. On others, like 112F, I do get a response. BTW, your read should only be done when socket.onMessage is called. The phonebook profile may require you to send data before it will send a msg. – AJBUCH Apr 08 '18 at 02:34
  • I think where we're going is wrong is that, for the HFP, there are requirements prior to establishing the service connection. I was reading the [HFP 1.7 specification](https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=292287) . The relevant section begins at 4.2. – AJBUCH Apr 08 '18 at 16:02