Hello,
I'm trying to get some ESP8266 config values from a web page.
The ESP is powered on with a REED swith and stay powered by a GPIO higt level on a mosfet .
It send an SMS
After a predeterminated time it swith off hit's power
This process is automatic but I would like to read a value form a webpage and following the value configure or stay alive for update via OTA.
How to proceed to get a feedback form the web page (SetConfig)
What to put ine the "config.html" page
#include <WiFiManager.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
ESP8266WebServer server(80);
int IntTestMode = 10; // intervalle de 10S
unsigned long PrevMillis1 = 0;
const char* WifiPassword = "xxxxxxxx";
const char* WebHost = "http://192.168.12.200/config.html";
void SetConfig() {
Serial.println("***** Stay alive forever *****");
}
void setup() {
Serial.begin(115200);
WiFiManager wifiManager;
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
wifiManager.setConfigPortalTimeout(180);
if (!wifiManager.autoConnect(host, WifiPassword)) {
Serial.println("failed to connect and hit timeout");
ESP.restart();
}
server.on("/SetConfig", SetConfig);
server.begin();
}
void loop() {
server.handleClient();
if (millis() - PrevMillis1 >= (IntTestMode * 1000)) {
WiFiClient espClient;
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(espClient, WebHost);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String httpRequestData = "message";
Serial.println(httpRequestData);
int httpResponseCode = http.POST(httpRequestData);
Serial.println("HTTP Response code: ");
http.end();
}
PrevMillis1 = millis();
}
}
Web page :
<!DOCTYPE html>
<html>
<body onload="SetConf()">
<script>
function SetConf() {
var Config = "Test envoi config";
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "SetConfig?" + "Config=" + Config, true);
xhttp.send();
}
</script>
</body>
</html>