problem with strstr() function in Arduino

I have connected my Linuxed router wrt54gl and a serial connection is also between them up and running.

I'd like the Arduino to work as a servo controller and also report the reading of sensors. All other processing of my robot will be done in the router.

For this, I have to write a command analyzer, so that to get commands from serial, extract commands from patterns and perform them.

I did this once by Java and my commands had such a pattern: xx@yyy. I used this:

             strSplit = new StringTokenizer(inputLine, "@");
             strCmd = strSplit.nextToken();
             strCmdVal = strSplit.nextToken();

where my strSplit and inputLine were both of String class. It worked fine. For Arduino I have to use C, and I don't know what is the best solution!

First thing that came to my mind was to use strstr() function to find a substring (command) inside what I got from the serial, and then just perform the command, delete it from input string, and back to the loop to analyze further substrings. I first tested the strstr() with a C compiler on my PC:

#include <stdio.h>
#include <string.h>
  int main(void)
    char *p;

    p = strstr("this is a test", "is");
      printf("it is null\n");

    return 0;

and it returned as expected: "is is a test".

Next I tried it with Arduino, in a test:

#include <string.h>

   int val =;

  char *cval = (char*)val;
  char *cmd;
  cmd = strstr(cval, "my test");
  if(cmd )

Finally to test it, in my Linux command line I issued:

echo 'this is my test!' > /dev/tts/1

and it failed!

As I said, the serial connection is tested and every other thing works fine. The only problem is probably with strstr() usage or the solution method totaly.

Please let me know what my problem is if you see it, or suggest a better solution to write a command analyzer, using other functions.

Thank you! only reads 1 byte at a time. You need to accumulate those bytes into a buffer before processing them as a string.

like with a:

byte b[256];

and gather them in b?

That is the reason why my test didn't work?

Yep. You need the equivalent of "readline" ...