Some stream parsing issue (RedFly WiFi)


I am issuing a GET request against a server component running on my Arduino Mega. The request is a simple test request:

When I simply output what is received via

    char cha;
    while (cha != '-1') {
     cha =;

I get what I expect:

GET /?q1=v1 HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en,en-us;q=0.9,sl;q=0.8,pt-br;q=0.7,pt;q=0.6,de;q=0.5,ca;q=0.4,he;q=0.3,ar;q=0.2,ja;q=0.1
Accept-Encoding: gzip, deflate
Connection: keep-alive

I am actually only interested in the 1st line.

So, my plan was to:

  1. Checking whether it is a GET, POST or whatever Request
  2. Checking which resource was adresses (/ in this case)
  3. Parsing the query parameters

This is the code:

void loop()
  char method[6], resource[32], param[64], *ptr, *p1, *p2, *p3;
  int len;
  int c;

    method[0] = 0;*)method, 4);   
    debugoutln("Determining type of request...");
    if(strncmp_P(method, PSTR("GET "), 4) == 0)

      //get addressed resource
      resource[0] = 0;
      ptr = resource;
        c =;
        if(isalnum(c) || (c == '/'))
          *ptr++ = c;
          *ptr   = 0;
        if (c == ' ') {
        if (c == '?') {
          debugoutln("QM ?");
        if (c == -1) {
      while((c != ' ') && (c != '?') && (c != -1)); // stop when we have read the addressed reasource
      debugoutln("Determining parameters specifiying commands...");

I never receive anything other than a -1 in the do-while loop. So the GET is detected, which means I have read GET (+1 blank).

But then, after having arrived in the do-while loop I immediately get -1 when doing a I would have expected to get a /, then a ? (which would let the loop end).

This is the output I see in the serial monitor:

Determining type of request...
Determining parameters specifiying commands...

Any idea?

I am usually coding Java and PHP, so it might be a stupid C issue...


Solved. The debugout function triggers a RedFly.disable() which causes the UART buffer to be emptied :) So I need to debug another way...