HTTP Server with option to edit content of page.

filipESP
Posts: 71
Joined: Tue Nov 06, 2018 12:42 pm

HTTP Server with option to edit content of page.

Postby filipESP » Wed Dec 19, 2018 11:25 am

I test the http_server example, named 'simple" and I would like to ask about the possibility to edit the content of the page.
Eg. I want to place the edit tekst field in the page body to change the name of any variable.

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Re: HTTP Server with option to edit content of page.

Postby PeterR » Wed Dec 19, 2018 11:44 am

Suggest you do some background reading on AJAX.

In essence Javascript embedded in your HTML will request another page from the ESP.
You will write a custom handler on the ESP which programmatically returns an XML or JSON 'file' when the Javascript requested file comes in. I put all my AJAX 'files' under path '/api/v1'
Basically you will printf() your variables to a string in XML or JSON format and return that string along with HTTP headers.
Your Javascript receives the XML/JSON file and uses the DOM (or JQuery) to find HTML property/class.
Once found you may then change the HTML object as you wish.

It sounds harder than it is.
https://www.w3schools.com/xml/ajax_intro.asp covers the HTML side and the HTTP Server theory.
There are plenty of ESP32 custom handler posts/links in this forum.

There are other approaches but AJAX is simplest I think.
Good luck.
& I also believe that IDF CAN should be fixed.

filipESP
Posts: 71
Joined: Tue Nov 06, 2018 12:42 pm

Re: HTTP Server with option to edit content of page.

Postby filipESP » Wed Dec 19, 2018 12:17 pm

Thanks for your response but I need to place the edit text field to be able to set eg. a password to my program.

gecko242
Posts: 18
Joined: Tue Oct 02, 2018 7:11 am

Re: HTTP Server with option to edit content of page.

Postby gecko242 » Wed Dec 19, 2018 12:34 pm

What PeterR has suggested will work.
You can also pass data around in an HTML Form, using POST/GET requests.
Handling it is relatively easy ESP side.
I suggest you read up on how websites/webservers talk. There are plenty of examples around doing what you want to achieve.

filipESP
Posts: 71
Joined: Tue Nov 06, 2018 12:42 pm

Re: HTTP Server with option to edit content of page.

Postby filipESP » Wed Dec 19, 2018 3:01 pm

I don't want to change the variable value in the program, I want change it when I connect with the server on my smartphone.

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Re: HTTP Server with option to edit content of page.

Postby PeterR » Wed Dec 19, 2018 4:13 pm

You need to be clearer ...

If you want to send from Webpage to ESP then (as suggested) look at POST/GET form actions. You can make your HTML form POST/GET from to any address. The ESP32 can then 'catch' the data because the ESP knows (you code that part) that POST/GET to '/my-location' is special and is a data exchange not a page request.

Now you could supply a page with fresh data. This is known as SSI. I think you would have to code that yourself on the ESP though & besides form actions and/or AJAX are quite easy & very, very well documented.

In all instances the Webpage must request refresh either full page refresh (not good) or by asking for new data.
In HTTP world once you have been given your webpage that's it. You don't get that page again unless you request it - which you could do.
Better just to exchange the data & non-static parts though.
& I also believe that IDF CAN should be fixed.

filipESP
Posts: 71
Joined: Tue Nov 06, 2018 12:42 pm

Re: HTTP Server with option to edit content of page.

Postby filipESP » Thu Dec 20, 2018 11:45 am

Okey, I edit the page in the .user_ctx variable (in /hello uri) and now I want to intercept the data in the /echo uri.
I get this LOG:

W (21076) httpd_parse: parse_block: response uri/header too big
W (21076) httpd_txrx: httpd_resp_send_err: 431 Request Header Fields Too Large -
Header fields are too long for server to interpret
W (21096) httpd_parse: parse_block: incomplete (0/65) with parser error = 16
W (21096) httpd_txrx: httpd_resp_send_err: 400 Bad Request - Server unable to un
derstand request due to invalid syntax

and this is the body of the page I made:

.user_ctx = "<h1>ZMIANA LOGINU</h1>"
"<form method=\"POST\" action = \"/echo\" >"
"<p>login<p/>"
"<input name=\"login\"/>"
"<p>pass<p/>"
"<input name=\"haslo\"/>"
"<button type=\"submit\">ZMIEN DANE</button>"
"<form/>"

filipESP
Posts: 71
Joined: Tue Nov 06, 2018 12:42 pm

Re: HTTP Server with option to edit content of page.

Postby filipESP » Thu Dec 20, 2018 12:47 pm

I changed the CONFIG_HTTPD_MAX_URI_LEN makro on higher and it is working :)))
Thx you for help.

filipESP
Posts: 71
Joined: Tue Nov 06, 2018 12:42 pm

Re: HTTP Server with option to edit content of page.

Postby filipESP » Fri Dec 21, 2018 6:50 pm

I have next issue with WiFi.
I set ESP as AP and when I try to connect with it a get this log in terminal: "wifi: max connection, deauth!"
What is the reason of this statement?

chegewara
Posts: 2230
Joined: Wed Jun 14, 2017 9:00 pm

Re: HTTP Server with option to edit content of page.

Postby chegewara » Sat Dec 22, 2018 10:29 am

Check AP config, there is max connected clients option.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot] and 157 guests