-->
Page 1 of 1

webServer displaying page how to?

PostPosted: Fri Aug 19, 2016 11:05 pm
by EdCasati
Simple question that has me flummoxed.

I have a simple webpage that allows me to collect some text and send it back to the ESP8266. That works fine. It does it by generating a new URL such as http://192.168.0.103/msg?HR1=23&MIN1=01, which it tries to display in the browser, which of course does not exist on the ESP 8266 server, and I get an error screen on the browser in return.

How can I get it to return the data and still show a screen of my choice in response?
The HTML line used is:
"<form action= 'msg'>Reminder 3 - Hour:<input type='text' name='HR2' size='2' maxlength='2'>Min:<input type='text' name='MIN2' size='2' maxlength='2'> <input type='submit' value='Set'> </form>"

Re: webServer displaying page how to?

PostPosted: Sat Aug 20, 2016 2:32 am
by krzychb
Hi @EdCasati,

I would use ESP8266WebServer library. Try this example - https://github.com/esp8266/Arduino/blob ... Server.ino

Load it to module, enter your request (for this particular one use Chrome, not IE) and you should see:
not-found.png

This page is generated by function handleNotFound().

Using this function and function server.on("/inline", [](){ as examples, you can write similar code to capture values of HR1 and MIN1, that initially may look like below:

Code: Select all  server.on("/msg", []() {
    String message = "<form action= 'msg'>Reminder 3 - Hour:<input type='text' name='HR2' size='2' maxlength='2'>Min:<input type='text' name='MIN2' size='2' maxlength='2'> <input type='submit' value='Set'> </form>";
    message += "The form returned: ";
    message += "URI: ";
    message += server.uri();
    message += "\nMethod: ";
    message += (server.method() == HTTP_GET) ? "GET" : "POST";
    message += "\nArguments: ";
    message += server.args();
    message += "\n";
    for (uint8_t i = 0; i < server.args(); i++) {
      message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
    }
    server.send(200, "text/html", message);
  });


If you add it to the example sketch you should see:
the-form.png


Now the form returns the data and still show specific screen in response.

I hope this will give you initial idea / guidance.

Krzysztof

Re: webServer displaying page how to?

PostPosted: Sun Aug 21, 2016 2:35 am
by EdCasati
Great reply! Thank you very much! Your code example really made things very clear. :D