Hi,
I like to add more GPIO using example 2_1_Web_Server_Outputs without JS.
How to make it in the simplest way?
3 Answers
Hi.
Duplicate the whole <div class=”card”> div. You’ll have another card with two more buttons.
Give new names to the buttons and assign different URLs. For example:
<p>
<a href="on2"><button class="button-on">ON 2</button></a>
<a href="off2"><button class="button-off">OFF 2</button></a>
</p>
Then, make sure you add a new placeholder variable for this button, for example:
<p class="state">State: %STATE2%</p>
And add this in the processor function.
Additionally, in the ESP32 code, add server.on() functions for those new button URLS:
server.on("/on2", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(ledPin2, HIGH);
request->send(SPIFFS, "/index.html", "text/html", false, processor);
});
// Route to set GPIO state to LOW
server.on("/off2", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(ledPin2, LOW);
request->send(SPIFFS, "/index.html", "text/html", false, processor);
});
Try these suggestions by yourself and see if you can make it work.
Let me know if you need further help.
Regards,
Sara