-->
Page 1 of 1

ESP8266 Webserver server.on page config

PostPosted: Wed Nov 16, 2016 9:28 am
by noodlesuk
Hi

Hope this hasn't be covered before, didn't see anything in the search results. I have a sketch which runs a webserver, with multiple pages, using:-

Code: Select allserver.on("/", handleRoot);

Code: Select allserver.on("/config", handleConfig);


the config page has a form to submit data (via get) which is written to eeprom, an example field

Code: Select all<form method='get' action='a'><label>SSID: </label><input name='ssid' length=32><BR>"


once this form is submitted, how would I go about handling the request for the page which starts with "/a?ssid=" ? I want something that allows wildcards, as the data entered will vary, but not quite sure how to do this in code. Something like

Code: Select allserver.on("/a?ssid=***********", handleConfig)


I have seen an example where the request is monitored using an if statement, like this:-

Code: Select allif ( req.startsWith("/a?ssid=") ) {


But I wanted to use the server.on format. Any help much appreciated. :D

Re: ESP8266 Webserver server.on page config

PostPosted: Thu Nov 17, 2016 9:18 am
by martinayotte
server.on() should point to URL only without the arguments.
Code: Select allserver.on("a", saveConfig);

Then in your new saveConfig() handler you can grab value of arguments with server.args() to get the count, server.hasArg() to figure out if arg exist (such as checkbiox), and finally server.arg() to get the values.