Hi Friends,
I have a question to programming a wWebserver. The complete code on the bottom.
My basic question is:
I wanna replace words, with strings in the index_html-String. For example:
%ReadTemperatur% replace it with String = analogRead(A0);
or
%ReadPinstatus% replace it with String = digitalRead(4);
I hope you understand what I mean
My aim is:
everytime I refresh the index_html, I need the Pin-Status.
Or is there another way ? For example, put a Sting between the index_html-String ?
Notice: I am using the <ESP8266WebServer.h> library.
Here is the full Code I am using:
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
char * ssid_ap = "MYSSID";
char * password_ap = "11111111";
IPAddress ip(192,168,11,4); // arbitrary IP address (doesn't conflict w/ local network)
IPAddress gateway(192,168,11,1);
IPAddress subnet(255,255,255,0);
ESP8266WebServer server;
const char index_html[] PROGMEM = R"rawliteral(<html>
<body>
<p>
<form action="/action_page"><input type="hidden" name="input" value="1"><input type="submit" value="Sensor On"></form>
</p>
<p>
<form action="/action_page"><input type="hidden" name="input" value="2"><input type="submit" value="Sensor On"></form>
</p>
<p>%FOR-EXAMPLE-THIS-COULD-BE-REPLACED%</p>
</body></html>)rawliteral";
String PageNotFound = "<center><p style=\"font-size:30px;\">Page not found!</p>";
String UnknownCommand = "<center><p style=\"font-size:30px;\">Unknown command</p>";
String InputReaktion1 = "<center><p style=\"font-size:30px;\">yeaaaaah.</p>";
String InputReaktion2= "<center><p style=\"font-size:30px;\">noooooo.</p>";
void notFound() {
server.send(200,"text/html",String(PageNotFound));
}
void handleForm() {
String CheckField = server.arg("input");
if(CheckField == "1") {
server.send(200, "text/html", InputReaktion1);
}
if(CheckField == "2") {
server.send(200, "text/html", InputReaktion2);
}
}
void setup() {
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(ip,gateway,subnet);
WiFi.softAP(ssid_ap,password_ap);
Serial.begin(115200);
server.on("/", HTTP_GET, []{server.send(200,"text/html",String(index_html));});
server.on("/action_page", handleForm);
server.onNotFound(notFound);
server.begin();
}
void loop() {
server.handleClient();
}