ESP32 HotSpot using WebServer library, how to retrieve user inputs?

Thread Starter

ErnieM

Joined Apr 24, 2011
8,377
I’m attempting to tie up some last loose ends with a project I’ve been working on and off for a few years now. Four channel RGBW LED Controller, had to build over buy to get the “W” (White) channel to play with Alexa.

Rather than continue to hard code my network info, along with the channel names, I am attempting to serve out a web page to enter this info and persist it in flash memory. I have that much working but fer…

How does my webpage send back info so the Webserver server.on function to return the data in the input fields of the page?

I’ve read several dozen “tutorials” that don’t rise above the level of “love my code” without explaining in any detail what the process is. I'm stuck on adding a "Submit" button at the bottom of my form that actually does something.
 
Last edited:

Ya’akov

Joined Jan 27, 2019
9,170
I haven't used that library but it looks like it uses POST, and server.arg() will retrieve them, like

server.arg("SOMEFIELDONYOURFORM")

and assign them to a variable.

And, you can check for the existence with:

server.hasArg("SOMEFIELDONYOURFORM")

so that you don't try to do something with data that doesn't exist.
 

Ya’akov

Joined Jan 27, 2019
9,170
Not a criticism, but it would help if you knew CGI, which is pretty old school stuff at this point, but that's what's going on, in the language of the WebServer library. Maybe a tutorial on CGI and POST would help get you oriented.
 

Thread Starter

ErnieM

Joined Apr 24, 2011
8,377
My work was based on this tutorial. Here the author Veeru used the routine "server.on("/setting", []() {" placed in his createWebServer() routine to catch data sent from his page.

What I was not seeing was the need to put all my < input type="text"…> entries between the tags <form method='get' action='setting'> and </form>

Now I can catch the softly set settings, once I merge the test code into my project code.

Thanks all!
 

Ya’akov

Joined Jan 27, 2019
9,170
My work was based on this tutorial. Here the author Veeru used the routine "server.on("/setting", []() {" placed in his createWebServer() routine to catch data sent from his page.

What I was not seeing was the need to put all my < input type="text"…> entries between the tags <form method='get' action='setting'> and </form>

Now I can catch the softly set settings, once I merge the test code into my project code.

Thanks all!
Just a heads up in case you want to do more with the web front end. Javascript, HTML5, and CSS have gotten very powerful. With PWAs (Progressive Web Apps) you can do a lot of work on the front end and even a tiny ESP8266 backend can appear to the user to be a full blown application.

Even if you don't go that far, supplementing the MCU with front end Javascript can really make things work better. So, if you are inclined, take a look at that stuff. If you'd like pointers to some introductory video, let me know. There are some really good short ones.
 

Ya’akov

Joined Jan 27, 2019
9,170
Sorry, no interest here. I just need one simple web page where clarity is king, to be used once then never to be seen again.
I was mostly thinking of future projects. Since you now have the idea of interacting with the user, you might find you want to do it again in a different context.
 
Top