SparkFun Forums 

Where electronics enthusiasts find answers.

All things pertaining to wireless and RF links
By enfoldu
#169582
The Goal:
I am trying to get the arduino (uno) to detect if the bluesmirf (silver) is connected or not by reading the status messages sent through serial (%CONNECT or %DISCONNECT)

What I've done:
Using the AT Command SO I have turned on "status messages" which sends a %CONNECT or %DISCONNECT string to the local serial port everytime the bluesmirf makes a connection or loses a connection.

The Problem:
I cannot figure out how to read those two different strings (%CONNECT/%DISCONNECT)

Side Notes:
I need the arduino to read either %CONNECT or %DISCONNECT and make a decision based on either finding.

Any help at all or a point in the correct direction would amazing. Thanks.
By enfoldu
#169759
Well since no one found anything I had to resolve this issue myself.

The answer:

In order to look for strings I had to use: find(string);

Here's an example:
Code: Select all
bluetooth.find("%DISCONNECT");
In that example find will look into the bluetooth for the string %DISCONNECT and if found will return true.

I have everything in a usable sketch on my website http://www.carduino.vonini.com (under arduino sketch) if anyone is interested in downloading the demo or seeing how I used it.

UPDATE:

Here is a sketch snippet from my website. It should give you a better idea of how I used find
Code: Select all
void loop()
{ 
                                                                 // LOCAL VARIABLES:
  char c = bluetooth.find("%CONNECT,30196692D7C0,0");    // Read bluetooth and find given string
  char d = bluetooth.find("%DISCONNECT");              // Read bluetooth and find %DISCONNECT string

  if(c){                                                                  // Find %Connect String...
    unlock();                                                             // Unlock the doors
  }else if(d){                                                            // Find %Disconnect String...
    lock();                                                               // Lock the doors
  }else{                                                                  // If you can't find either string then...
    if(ul){                                                               // Check if Car is Unlocked...
      if (dStatus()){                                                     // Now check to see if bluesmirf and phone are disconnected...
        lock();                                                           // If it's disconnected : Lock the doors
      }                                                                   // BUT
    }else{                                                                // If Car is Locked...
      if (cStatus()){                                                     // Check to see if bluesmirf and phone are connected...
        unlock();                                                         // If it's connected : unlock the doors
      }
    }
  }
  
  if(r){                                                                  // Check to see if r(reconnect) is true...
    reconnect();                                                          // If it is TRUE then reconnect
  }
  
}//END: loop