Hardware Reference
In-Depth Information
Because there's a dedicated connection
between the two radios, you need to keep track
of the connection status. When a new connec-
tion is made, the Bluetooth Mates send a serial message
before dropping into data mode, thanks to your last con-
figuration change. The serial message looks like this:
TRYING\r
You can ignore the TRYING message because it'll always
be followed by CONNECT or—if the Mate doesn't succeed
in connecting—it sends:
CONNECT failed\r
BTCONNECT\r
Look for these to come in and use them to track the con-
nection status. The Bluetooth Mates drop into data mode
immediately after sending either of these two messages,
so they're a handy way to keep track of the mode as well.
The BTConnect() , BTDisconnect() , and handleSerial()
methods use these strings to do their work, as follows.
When the connection's broken, it sends this message and
stays in command mode:
BTDISCONNECT\r
While trying to connect, the Mate sends:
8
BTConnect() checks the
command/data mode status, then tries
to make a connection. If the attempt
fails, it stays in command mode.
void BTConnect() {
// if in data mode, send $$$
if (!commandMode) {
Serial.print("$$$");
// wait for a response:
if (finder.find("CMD")) {
commandMode = true;
}
}
// once you're in command mode, send the connect command:
if (commandMode) {
Serial.print("C," + remoteAddress + "\r");
// wait for a response:
finder.find("CONNECT");
// if the message is "CONNECT failed":
if (finder.find("failed")) {
connected = false;
}
else {
connected = true;
// radio automatically drops into data mode
// when it connects:
commandMode = false;
}
}
}
 
Search WWH ::




Custom Search