Bluetooth drive with 32feet.net and C #

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); // Begin Edit ------------------------------------------------------------ Byte[] sResponse = new Byte[100]; peerStream.Read(sResponse, 0, 99); TextBox1.Text = System.Text.Encoding.ASCII.GetString(sResponse); // End Edit -------------------------------------------------------------- peerStream.Close(); cli.Close(); MessageBox.Show("Done"); 

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(); 
+6
source share
2 answers

Try to find which answer is for AT \ r (or) ATH \ r. If the answer is "OK \ r \ n", try the dial command without a space after ATD and the number.

+3
source

As supporting 32feet.NET, I would like to find the answer to this question. Hopefully someone with knowledge of HSP / HFP will explain why this does not work. My only general assumption is that since we do not accept / create an SCO channel for an audio channel, the phone refuses to connect.

As soon as the matter is in your case ... AT commands end with CR (0Dh); or does the semicolon act the same?

+1
source

Source: https://habr.com/ru/post/887793/


All Articles