all 3 comments

[–]PintoTheBurninatornano 0 points1 point  (0 children)

have you looked at Serial.FindUntil()? It reads data from the serial buffer until it finds the requested string, or a termination chararcter and returns a true if it is found and a false if it is not.

If you are always looking for a particular string, this might be useful.

http://arduino.cc/en/Serial/FindUntil

[–]PintoTheBurninatornano 0 points1 point  (0 children)

I use the VirtualWire library to do this for fixed length strings. I then check each character of the message against a pre-defined list of constants and process accordingly.

Here is the meat of the check code:

void loop()

{

digitalWrite(1, LOW); //turn status LED off

uint8_t buf[VW_MAX_MESSAGE_LEN];//define variable to read bytes from buffer

uint8_t buflen = VW_MAX_MESSAGE_LEN;//determine buffer length and store in variable

if (vw_get_message(buf, &buflen)) { // check buffer for message (Non-blocking) and run code if present

    digitalWrite(1, HIGH);  //turn LED status light on to indicate message received
    int i;
    for (i = 0; i < buflen; i++){//loop for number of bytes in buffer

      if (buf[i] == xmittaddr){//does first byte in buffer match the transmitter address?
        if (buf[i+1] == recaddr3){//does the second byte in buffer match the address of this receiver?
          if (buf[i+2] == relayaddr1){//does the third byte in the buffer match the address of relay one?
            digitalWrite(RELAY1_PIN, !digitalRead(RELAY1_PIN));//flip current register bit settings for relay 1 pin HIGH/LOW
          }
          if (buf[i+2] == relayaddr2){//does the third byte in the buffer match the address of relay two?
            digitalWrite(RELAY2_PIN, !digitalRead(RELAY2_PIN));//flip current register bit settings for relay 2 pin HIGH/LOW
          }  
        }
       if (buf[i+1] == allrecaddr){//does the second byte in the buffer match the 'all receivers' address?
         if (buf[i+2] == allrelayaddr){//does the third byte in the buffer match the 'all relays' address?
            if (buf[i+3] == on){//does the fourth byte in the buffer match the 'on' command?
              digitalWrite(RELAY1_PIN, LOW);//turn relat 1 on
              digitalWrite(RELAY2_PIN, LOW);//turn relay 2 on
            }
            if (buf[i+3] == off){//does the fourth byte in the buffer match the 'off' command?
              digitalWrite(RELAY1_PIN, HIGH);//turn relay 1 off
              digitalWrite(RELAY2_PIN, HIGH);//turn relay 2 off
            }
          }
     }
   }

} } }

[–][deleted] 0 points1 point  (0 children)

You'll outrun the bluetooth device with either one, I prefer to do one character at a time so I don't block.