5

im trying to control a bluetooth bracelet with vibration function via HFP (hands free profile) in Android. I've been able to connect to the bracelet and access the input- and outputstream.

My goal is to simulate an incoming call so that the bluetooth bracelet starts vibrating (which seems to be the only way to do that). To do this, im using AT commands. In the bluetooth specs at https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=238193 on page 22 you can see the handshake to establish service level connection. I need to establish this connection to use the "+CIEV" command (see handshake page 48).

But when my bracelet returns the command "AT+CIND=?" I dont know how to respond. I can't find any hints on how to answer with the "CIND:" command. Also I dont know how to send the acknowledgement (is it just "OK"?).

That might even be the completely wrong way to do this. Every suggestion is appreciated. I only found one post on stackoverflow that helped me in some way, rest of the posts I found were unanswered. By the way, im using a smartphone with Android 4.1.2. The bracelet supports HFP and HSP. Thanks in advance.

UPDATE 10/29/2014

Service Level Connection Procedure

===== Connection through RFCOMM Socket established at this point =====

        // read AT+BRSF=0 from device
        byte[] buffer = new byte[200];
        mBluetoothSocket.getInputStream().read(buffer);
        Log.d(TAG, new String(buffer).trim());

        //write answer BRSF: ...
        mBluetoothSocket.getOutputStream().write("+BRSF=20\r".getBytes());
        mBluetoothSocket.getOutputStream().write("OK\r".getBytes());

        // read AT+CIND=? command
        buffer = new byte[200];
        mBluetoothSocket.getInputStream().read(buffer);
        Log.d(TAG, new String(buffer).trim());

        //write answer CIND: ...
        mBluetoothSocket.getOutputStream().write("+CIND: (\"battchg\",(0-5)),(\"signal\",(0-5)),
           (\"service\",(0,1)),(\"call\",(0,1)),(\"callsetup\",(0-3)),
           (\"callheld\",(0-2)),(\"roam\",(0,1))".getBytes());
        mBluetoothSocket.getOutputStream().write("OK".getBytes());

        // read AT+CIND?
        buffer = new byte[200];
        mBluetoothSocket.getInputStream().read(buffer);
        Log.d(TAG, new String(buffer).trim());

Following the procedure of the protocol, I should receive the "AT+CIND?" command and then I could send the command "+CIND: 5,5,1,0,0,0,0", but...I dont receive the "AT+CIND?" command. Actually im not receiving anything. Am I missing something? Sending an "OK" doesnt change anything btw...

Community
  • 1
  • 1
V1nc3nt
  • 369
  • 4
  • 11

3 Answers3

2

I was fiddeling with exaclty the same problem. After days of trial and error, I finally got it to work. I think it depends on the speed at wich you answer the HF's commands, as well as on the correct line-endings ("COMMAND").

Here is my DroidScript which works. It's not cleaned up, but it works.

https://gist.github.com/t-oster/68a568ac4c4e133f67ac

Thomas Oster
  • 421
  • 2
  • 10
  • Thank you, I will try that as soon as im back from India - so in 1 year... Didn't take that bracelet with me, but maybe I'll just buy another one. What android version do you run that code on? – V1nc3nt Feb 21 '15 at 15:57
  • I run it on Android 4.3, but I used the JavaScript environment "DroidScript" (avaliable in the Play Store) for prototyping. But it should neither depend on the language, nor on the android specification, because I am not using any Bluetooth Profile, but a raw RFCOMM connection. On Java you have to use the right UUID, on JavaScript the right Channel. I found them via linux and the rfcomm command. – Thomas Oster Feb 23 '15 at 13:10
2

Also, the one example I found that seemed to almost work, it's expecting the responses to be top and tailed with crlf: "\r\n+BRSF=20\r\n" "\r\nOK\r\n"

Still struggling with the rest of it myself.

Robbie Matthews
  • 1,404
  • 14
  • 22
0

refer to bluetooth hfp 1.5 spec in which you can understand CIEV response normally when not in any call setup, response can be +CIND = 1,0,0,0,5,0,5 Note these values are based on the hfp spec, on incoming call return +CIEV: , ind- indicator for callsetup and value as 1 and then RING commands to the bracelet

ashish
  • 1,384
  • 1
  • 12
  • 21
  • Hey, im very sorry for my late comment on your post. I tried what you said, but the device doesnt return anything as result to this command. Ill add my code in my answer, maybe im doing something else wrong. Thanks so far. – V1nc3nt Oct 29 '14 at 09:47