HTTP Server with option to edit content of page.
HTTP Server with option to edit content of page.
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.
Eg. I want to place the edit tekst field in the page body to change the name of any variable.
Re: HTTP Server with option to edit content of page.
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.
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.
Re: HTTP Server with option to edit content of page.
Thanks for your response but I need to place the edit text field to be able to set eg. a password to my program.
Re: HTTP Server with option to edit content of page.
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.
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.
Re: HTTP Server with option to edit content of page.
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.
Re: HTTP Server with option to edit content of page.
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.
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.
Re: HTTP Server with option to edit content of page.
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/>"
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/>"
Re: HTTP Server with option to edit content of page.
I changed the CONFIG_HTTPD_MAX_URI_LEN makro on higher and it is working ))
Thx you for help.
Thx you for help.
Re: HTTP Server with option to edit content of page.
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?
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?
Re: HTTP Server with option to edit content of page.
Check AP config, there is max connected clients option.
Who is online
Users browsing this forum: No registered users and 104 guests