Dynamic HTML web server using ESP8266

I used WS2812FX library esp8266_webinterface example sketch.
i added a line server.on("/settings", srv_handle_settings_html); and defined a function void srv_handle_settings_html(){ server.send(200, "text/plain", "OK"); }
it works perfectly fine.
the problem is i cant't figure out how can make html dynamic.
it's always sending static html.
what i need is like this:
some html
some code that returns some html (for loop example)
some more html

Any Idea?
thanks for your help

what do you mean by "dynamic html" exactly? What is dynamic?

If you want to add some sketch variables to the generated HTML just add the content of the variable to your HTML.

See my demo

ESP8266 ESP32 webserver maxi

example 30. And if that is working for you example 70.

i couldn't find the code but i think example 30 be the answer.

format i need is:

<some html>
<ul>

and the some arduino code like:

for (int i = 0; int < 10; i++){
    echo ("<li>");
    echo (i);
    echo("</li>");
}

and then:

</ul>
and then <some more html>

of course there is no echo function or command but it was good word for demonstration

please read the full page.

and surprise, at the end of the page

Thanks a lot now i know what to do :grinning:

1 Like

I belive you are looking for an interactive webserver, which responds based on the input you give to the page.
If that is the case, you can check my tutorial on ESP32 webserver where I have controlled an LED from a web server the buttons on the webserver are interactive.
The procedure will be mostly the same for ESP8266 as well

You can also check out AJAX web server after this if you want your page to re-load automatically this was your sensor values or any dynamic values will automatically be visible without you having to refesh the page everytime

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.