Handling Webduino web_parms

web_parmsI'm using the example from the Webduino library to access http GET parameters in a URL:

I can do this just fine:
http://192.168.2.10/parsed.html?foo=10
and the returned web page correctly says:
foo = '10'

The code in the example generating that is:

server.print(name);
server.printP(Parsed_item_separator);
server.print(value);
server.printP(Tail_end);

Fine and dandy. Now what I want to do is to react if the value of foo is greater than say 5. So under that block I've added :

        if(String(name) == "foo"){
          int fooval =  (int)value;
          server.print(fooval);
          if(fooval > 0) {
            server.print("<p>got foo</p>");
          }

        }

This is not giving me expected results. server.print(fooval) emits 2129, not 10. Am I casting correctly? Any idea what I'm doing wrong here?

Thanks.

You'll need to use atoi() - http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/

Hmm, OK now I'm using

int fooval =  (atoi) value;

and this fails the compile check with

invalid conversion from 'int (*)(const char*)' to 'int'

I'm not sure how to interpret that. Does it mean that 'value' is not a string to begin with? If not, what is it? (remember, 'value' comes from a URL parameter). How do you determine the existing type of a variable in Arduino?

Thanks from a newbie.

atoi() is a function.

int fooval =  atoi(value);

Oh! Duh :slight_smile:

Thanks much, working now.