In the code below, what causes the text above the button to display off or on?
Specifically the line <p>GPIO 26 – State</p> .
I see that it should display “GPIO 26 – State”, but where does the off or on text come from?
<body> <h1>ESP32 Web Server</h1> <p>GPIO 26 - State</p> <p><a href="/26/on"><button class="button">ON</button></a></p> <p><a href="/26/off"><button class="button">OFF</button></a></p> <p>GPIO 27 - State</p> <p><a href="/27/on"><button class="button">ON</button></a></p> <p><a href="/27/off"><button class="button button2">OFF</button></a></p> </body>
Hi.
That part is just HTML text. That’s just to give you an idea on how you would build a page for your web server. That doesn’t update the value.
To update the value, in the Arduino code, we should concatenate a variable that holds the state of the GPIO, as follows:
client.println("<p>GPIO 27 - State " + output27State + "</p>");
In this case, the output27State is the variable that holds the GPIO state and we’re concatenating that variable with the rest of the HTML text.
I hope this is clear.
Regards,
Sara