I'm looking at a way to sniff serial data from the arduino and enable an output whenever a key phrase is found. For example, say I want to de-activate a lock whenever the code 12ab3 is sent, but I sent receive a message like "please unlock the door code is 12ab3 time is 15h13min..."
My question is when a given string is found on the serial data, mixed with something else without any deliminator characters.
In my case I'm looking for the passkey 12ab3, for example, but I have other text being sent before any termination characters like a comma, \CR or \n. I didn't found any (practical) option to extract my code, nor can I change the source to add strings. As such I use the bit of code below which checks every character, but surely there's a more user friendly alternative?
void loop()
{
if(Serial.available() >0)
{
inchar=Serial.read();
if (inchar=='1')
{
delay(10);
inchar=Serial.read();
if (inchar=='2')
{
delay(10);
inchar=Serial.read();
if (inchar=='a')
{
delay(10);
inchar=Serial.read();
if (inchar=='b')
{
delay(10);
inchar=Serial.read();
if (inchar=='3')
{
// now the key is matched, do something
doSomething();
}
}
}
}
}
}
}
True, any character can be defined as a delimiter if so wanted, but I don't always have spaces either, and checking for every combination would be more troublesome than my current code.
Sticking with the original question, I would be interested in Robin's suggestion, if anyone has an idea what that function will be...
Another question, how can I use arduino to send this?