I am working on a wireless project in which I am using wt 32 of bluegiga as I need to send audio. I am almost done with it. Now the problem is that I need to use a microcontroller to code it so that it (bluetooth) automatically pairs up with the devices around it.
For that I have brought ARDUINO UNO. I am really not much into programming.
The routine which i need to code is :
1) INQUIRY 5 // command given
INQUIRY_PARTIAL 00:18:6b:af:d1:15 200404 // response from the WT 32 /Bluetooth add.(00:18:6b:af:d1:15)
INQUIRY_PARTIAL 00:22:5f:f7:92:8b 000000
INQUIRY 2 // no of decives found
INQUIRY 00:18:6b:af:d1:15 200404
INQUIRY 00:22:5f:f7:92:8b 000000
2) pair 00:18:6b:af:d1:15 // command given
PAIR 00:18:6b:af:d1:15 OK // response
00:18:6b:af:d1:15 this is the bluetooth address here.
So, basically its a variable/response I am getting back from my bluetooth which can change depending on the device. But its length will remain the same always.
Finally, I have some code. I think the logic is correct but I am not able to read the serial input i.e. Bluetooth Address.
The code is :
#include <string.h>
String Address;
void setup()
{
// start serial port at 115200 bps:
Serial.begin(115200);
}
String Inquiry()
{
String cmdInq="Inquiry 8 "; //Sets command for inquiry
Serial.println(cmdInq); //Sends command to Bluetooth
String Addrr = Serial.read(); //Reads Bluetooth Address
String Address=Addrr.substring(16,32); // Stores Bluetooth Device Addrress in the String Address
delay(5000);
return Address; // Returns Address
}
void Pair()
{
String cmdPair= "Pair "; //Creates the Command for Pair
Serial.print(cmdPair); //Sends the command to Bluetooth Module via Serial Connections
Serial.println(Address); // Sends the Address to Bluetooth Module
delay(10000);
}
void Call()
{
String cmdCall = "Call "; //Creates the Command for Call
Serial.print(cmdCall);//Sends the Command for Call to Bluetooth via Serial Port
Serial.print(Address);
Serial.println(" 1108 HSP-AG");
delay(15000); //Delays 15 Seconds
}
void SCO() {
String cmdSCO="SCO OPEN 0"; //Creates the Command for SC0 OPEN 0
Serial.println(cmdSCO); //Sends
delay(5000);
}
void loop(){
Inquiry();
Pair();
Call();
SCO();
}
Now when I connect Tx and RX of my Bluetooth after uploading the code to arduino. I don't see anything in serial monitor.
I think I am not able to send commands to my Bluetooth. Or may be something else is wrong.
Please help
String Addrr = Serial.read(); //Reads Bluetooth Address
String Address=Addrr.substring(16,32); // Stores Bluetooth Device Addrress in the String Address
delay(5000);
return Address; // Returns Address
The String, Addrr, is one byte long. You then expect to extract the 16th through 32nd characters from that one byte string, and then return a reference to a variable that goes out of scope. Neither of those will work.