void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
pinMode(7, OUTPUT);
delay(1000);
Serial.println("Searching for device");
blueToothSerial.begin(9600);
Serial.println(" ");
This is our setup, and sets the master device's baud band to 9600. the pinMode originally was suppose to be hooked up to an alarm, but that was scrapped and I still haven't deleted it.
delay(1000);
Serial.println("Lemme set up real quick");
//this step tells me when the device is attempting to connect;
blueToothSerial.write("AT+IMME1\r\n");
Reply = blueToothSerial.readString();
Serial.print(Reply);
Serial.println("Auto connection is off");
//allows me to know if the command AT+IMME is sent;
delay(1000);
blueToothSerial.write("AT+ROLE1\r\n");
Reply=blueToothSerial.readString();
Serial.print(Reply);
Serial.println("Master Role set");
//allows me to know if the command AT+ROLE1 is sent, configues device to be master upon startup;
delay(1000);
These commands sets the HM bluetooth device, to the master role, and switches the auto connection off. That way I can connect the bluetooth device to the slave device specifically and not a random phone or TV.
void loop()
{
blueToothSerial.write("AT+DISC?");
Serial.println("Discovery on");
//lets me know if the device is starting discovery
delay(1000);
Serial.println("Connection found");
blueToothSerial.write("AT+CONE4E112960A56");
Reply=blueToothSerial.readString();
Serial.print(Reply);
{
for(Reply.startsWith("OK+CONN:E4E112960A56"));{
stop();
}
}
}
This is the part of the code I am having trouble with. What it is suppose to do is constantly search, constantly do the Discovery command "AT+DISC?" the master device will therefore try to find any signals from the slave device
The alarm is on the slave device, the slave bluetooth piece will not turn on until, the tripwire is tripped, when the tripwire is trip, the device will turn on and start sending out a signal. The master will therefore detect the, now on, slave device and connect to it. The "AT+CONN:E..." but the problem I'm having is that it will connect and then immediately disconnect because its a loop so it will disconnect and start discovery again. I want it to stop discovering once it connects to the slave device.
The tripwire when reloaded will shut off the slave device, which will disconnect the master, hence restarting the alarm.
Also forgive me for my poor English, it is not my first language.