Go Down

Topic: Adding token to end of URL (Read 1 time) previous topic - next topic


Dec 18, 2012, 01:37 am Last Edit: Dec 18, 2012, 01:43 am by ryanmcclure4 Reason: 1
I have an Ethernet shield and relay board hooked up to my Arduino.  I have a webpage set up and its working fine.  At the moment I have on/off buttons for the relay that, when clicked, append a couple letters with tokens onto the URL.  This is then tokenized using strtok, etc. and the switch is turned on or off...  

Code: [Select]

char *response = strtok(readString, "?");

         response = strtok(NULL, "=");
         if(strcmp (response, "A") == 0){
           val = 1;
         else {
           val = atoi(response);
         response = strtok(NULL, ".");
         tempHr = atoi(response);
         response = strtok(NULL, ".");
         tempMin = atoi(response);
         response = strtok(NULL, ";");
           if(strcmp (response, "T") == 0){
             trueFalse = 'T';
             trueFalse = 'F';

So now I'm working on a different part of the code where I need to have the user be able to set a weekly schedule for the relays.  I'd like to create text boxes for each day of the week in which the user can input a time like "5:30" and then a GET HTTP request will be sent so that the Arduino can change the time accordingly.
I have it somewhat working, however I'm having problems with tokenizing the requests. The following code sends the request and works fine:
Code: [Select]

         client.print("<form action='' method='GET'>");
         client.print("<input type='text' name='2' maxlength='5' size='5' />");
         client.print("<intput type='submit' value='Submit' /></form><br>");

But I don't know how I can tokenize it when I already have code in the loop that is tokenizing a different type of information for the individual on/off buttons.  For example, when the on/off button is pressed for relay 2 the URL will look like this:;

And when I type in the text box to change the time to "5:30" for relay 2the URL will be:

I realize the ":" is encoded to %3A so I will have to deal with that as well (although 5.30 works fine but I'd rather not use that);

So as you can see, my problem is that I need to tokenize the URL differently depending on the request.  Is there an easy way of doing this?

Thanks for any help!  I hope this all made sense...

EDIT: I've been thinking of adapting my project using the concepts here http://www.cs.helsinki.fi/u/ljlukkar/iot/#conclusions but I don't know anything about java.  Would it make more sense for me to try and learn to do this?


Suggest you print out a few examples of the URL that is submitted in the GET request. I would expect to find that the form field values are URL-encoded like

In that case you can split the URL at the first ? to separate the parameters assignments, split the parameter assignments at & to get the individual parameter assignments, and split each assignment at the first = to get the name and value. And then you would need to parse and validate the value. It would be user-friendly to validate the field values at the client before you do the submit so that you can warn the user of errors without doing a page turnaround (and save yourself the hassle of preserving the duff values and sending the same form out again for correction) but that's not essential.


In html forms, it seems that the get query string sent is different depending on weather the submit button is used or the enter key.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0


Code: [Select]
          client.print("<input type='text' name='2' maxlength='5' size='5' />");
The name attribute defines the part on the left side of the equal sign. It's hardly a good idea to name everything 2.

Try naming some of your fields 3. Or, maybe, possibly even something meaningful.
The art of getting good answers lies in asking good questions.


In html forms, it seems that the get query string sent is different depending on weather the submit button is used or the enter key.

That is down to the HTML author. The enter key does not implicitly submit the form so if you have a form which is submitted by the enter key (while the focus is not on a submit button) then it implies the author has included some client-side event handling code to recognise the enter key and respond by submitting the form. In that case, it's possible that the author would choose to submit the form differently from the way the submit field submits it, although that would be a strange thing to do.


For simple GET/POST parameter handling you will probably do with the Webuino library

Use unix style timestamps. JavaScript date object will be your friend.

I just wrote an examle how a pins high/low state can be controlled using a web interface but it doesn't have the timer functionality you are after.

Go Up