I am trying to provide a βdialβ solution for someone on a Bluetooth device such as a mobile phone. I tried to do this using 32feet.net bluetooth api.
I have not done anything with bluetooth (since then, as in the commands via the bluetooth serial port), but I paired the device in question, which supports the speakerphone service with a PC. I have the following code to try to connect and send a dial command.
String deviceAddr = "11:11:11:11:11:11"; BluetoothAddress addr = BluetoothAddress.Parse(deviceAddr); BluetoothEndPoint rep = new BluetoothEndPoint(addr, BluetoothService.Handsfree); BluetoothClient cli = new BluetoothClient(); cli.Connect(rep); Stream peerStream = cli.GetStream(); String dialCmd = "ATD 0000000000\r\n"; Byte[] dcB = System.Text.Encoding.ASCII.GetBytes(dialCmd); peerStream.Write(dcB, 0, dcB.Length);
Since it seems to go through these lines of code, itβs the right time to connect in the appropriate place or crash if the device address is incorrect and it cannot connect. Obviously, the AT command is not suitable for sending.
Can someone enlighten me about what I might need to send to a Bluetooth device via the speakerphone profile to get it to dial?
Start editing -------------------------------------------
I decided to read from the stream and see if there is any answer after sending the AT command. Since I'm just testing if I can make it work, I just drop the answer into the text box.
The answer I read from the stream:
ERROR
There seems to be no error codes or anything else.
End Edit ---------------------------------------------
Edit ---------------------------------------------- --- -
Sent Command: AT + CMER \ r
Result: OK
then
Sent command: AT + CIND =? \ R
Result: + CIND: ("service", (0-1)), ("call", (0-1)), ("callsetup", (0-3)), ("battchg", (0-5 )) ("signal", (0-5)), ("wander", (0-1)), ("callheld", (0-2))
then
Send command: ATD 0000000000 \ r
Result: OK D: ("service", (0-1)), ("call", (0-1)), ("callsetup", (0-3)), ("battlechg", (0-5 )), ("signal", (0-5)), ("wander", (0-1)), ("callheld", (0-2))
Nevertheless, he actually does not dial: (
End Edit --------------------------------------------- -
Decision ----------------------------------------------
The following code now works for dialing through my iPhone. This is very rude at the moment, as I just tested so that I can get it to work. This is enough to get started for those who want to do this.
String deviceAddr = "00:00:00:00:00:00"; BluetoothAddress addr = BluetoothAddress.Parse(deviceAddr); BluetoothEndPoint rep = new BluetoothEndPoint(addr, BluetoothService.Handsfree); BluetoothClient cli = new BluetoothClient(); cli.Connect(rep); Stream peerStream = cli.GetStream(); String dialCmd1 = "AT+CMER\r"; String dialCmd2 = "AT+CIND=?\r"; String dialCmd3 = "AT+BRSF=\r"; String dialCmd4 = "ATD 0000000000;\r"; Byte[] dcB = System.Text.Encoding.ASCII.GetBytes(dialCmd1); peerStream.Write(dcB, 0, dcB.Length); Byte[] sRes = new Byte[200]; peerStream.Read(sRes, 0, 199); textBox1.Text = textBox1.Text + "\n\r----------\n\r" + System.Text.Encoding.ASCII.GetString(sRes); dcB = System.Text.Encoding.ASCII.GetBytes(dialCmd2); peerStream.Write(dcB, 0, dcB.Length); peerStream.Read(sRes, 0, 199); textBox1.Text = textBox1.Text + "\n\r----------\n\r" + System.Text.Encoding.ASCII.GetString(sRes); dcB = System.Text.Encoding.ASCII.GetBytes(dialCmd3); peerStream.Write(dcB, 0, dcB.Length); peerStream.Read(sRes, 0, 199); textBox1.Text = textBox1.Text + "\n\r----------\n\r" + System.Text.Encoding.ASCII.GetString(sRes); dcB = System.Text.Encoding.ASCII.GetBytes(dialCmd4); peerStream.Write(dcB, 0, dcB.Length); peerStream.Read(sRes, 0, 199); textBox1.Text = textBox1.Text + "\n\r----------\n\r" + System.Text.Encoding.ASCII.GetString(sRes); peerStream.Close(); cli.Close();