WiShield - How to Post Data from HTML Buttons

Discussions related to the WiServer add-on code for WiShield. WiServer is a friendly, easy-to-use front end for webserver and webclient usages.

Moderator: shard7

WiShield - How to Post Data from HTML Buttons

Postby shartke » Thu May 13, 2010 5:53 am

I wanted to have 4 buttons on a html page and when a user clicks a button it does something like turn a servo etc...


I got it to work using the thread here viewtopic.php?f=15&t=94

However the person mentioned that using a href is not elegant and there is a better method.... He mentions:

While this is quick and dirty, it's not really elegant. A nicer solution would be to have 5 form buttons on a webpage, all nicely laid out, and each button push would send a post data request back to the Arduino. You'd then have to parse the post data coming back to find the message you are looking for, and what the command is.

Anyway, hope this helps you out a bit. Let us know how the hamster does.


I have searched for about 2 days now trying to find something that explains how to "post" to an arduino using a webpage.. I looked at the wiki and even the example sketches included on the wiki. I didn't want to use a socket sketch with an app on my pc I prefered to use a webpage local to the arduino.. Can someone assist?
shartke
 
Posts: 1
Joined: Thu May 13, 2010 5:46 am

Re: WiShield - How to Post Data from HTML Buttons

Postby rock » Thu May 27, 2010 6:37 pm

Well, doing a POST *to* the arduino is really a lost cause, and a lot more work than it's worth. There's nothing in the API for *receiving* POST data (although there is for sending). Using links isn't really inelegant, just different. Essentially, you are doing a GET request instead of a POST, and there's nothing at all wrong with doing that. Heck, this forum is using a GET right now (that's the ?key=value&key2=value2 stuff at the end of the URL). It's also a LOT easier to get at the data, because you are parsing the URL that gets sent to your sendPage().

Basically, here is the difference, visually:

GET URL: http://yourWiServer/1
POST URL: http://yourWiServer/

big deal. The problem is, internally, a POST is a lot uglier. A GET has all the info in the URL, so all you have to do is parse the URL variable and get the data you need out of it. To get the same data out of a POST, you have to scan the contents of the entire data blob (including getting past the header data). That's a lot more work, and honestly, I don't think it's worth it.

You don't even need to use buttons or a form at all, just simple links that have the data preloaded would work just fine. The only value using a form has is you can get actual submit buttons displayed on your browser without using CSS to create it. The end result is essentially the same: A URL that has the value you want, ready to be plucked out of the array.

I assume, looking at the referred post, that "not really elegant" means "I'm displaying text links instead of fancy submit buttons". If you create a form as a GET or a POST, it will look the same, including the fancy buttons. Only the URL will be different.

I personally ditched the form altogether and just used text links with a little CSS to make them *look* like buttons.
rock
 
Posts: 13
Joined: Tue May 25, 2010 11:33 pm


Return to WiServer

Who is online

Users browsing this forum: No registered users and 1 guest