135 lines
3.7 KiB
C++
135 lines
3.7 KiB
C++
![]() |
#include <Arduino.h>
|
||
|
|
||
|
#include <ESP8266WiFi.h>
|
||
|
#include <ESP8266WebServer.h>
|
||
|
|
||
|
#include "configuration.h"
|
||
|
|
||
|
|
||
|
tConfigBlock configBlock;
|
||
|
const uint32_t MAGIC = 0xC0DE0001;
|
||
|
extern ESP8266WebServer webServer;
|
||
|
|
||
|
void configServeIndex() {
|
||
|
webServer.send(200, "text/html", ""
|
||
|
"<!doctype html"
|
||
|
"<html lang=\"en\">"
|
||
|
" <head>"
|
||
|
" <title>ESP8266 Thermometer Configuration Page</title>"
|
||
|
" </head>"
|
||
|
" <body>"
|
||
|
" <h1>ESP8266 Configuration Page</h1>"
|
||
|
" <form action=\"/config\" method=\"GET\">"
|
||
|
" <table>"
|
||
|
" <tr>"
|
||
|
" <td>"
|
||
|
" <label for\"wifiSsid\">Wifi SSID</label>"
|
||
|
" </td><td>"
|
||
|
" <input type=\"text\" name=\"wifiSsid\" id=\"wifiSsid\"/>"
|
||
|
" </td>"
|
||
|
" </tr>"
|
||
|
" <tr>"
|
||
|
" <td>"
|
||
|
" <label for\"wifiKey\">Wifi Key</label>"
|
||
|
" </td><td>"
|
||
|
" <input type=\"text\" name=\"wifiKey\" id=\"wifiKey\"/>"
|
||
|
" </td>"
|
||
|
" </tr>"
|
||
|
" <tr>"
|
||
|
" <td>"
|
||
|
" <label for\"mqttBroker\">MQTT Broker</label>"
|
||
|
" </td><td>"
|
||
|
" <input type=\"text\" name=\"mqttBroker\" id=\"mqttBroker\"/>"
|
||
|
" </td>"
|
||
|
" </tr>"
|
||
|
" <tr>"
|
||
|
" <td>"
|
||
|
" <label for\"mqttUser\">MQTT Username</label>"
|
||
|
" </td><td>"
|
||
|
" <input type=\"text\" name=\"mqttUser\" id=\"mqttUser\"/>"
|
||
|
" </td>"
|
||
|
" </tr>"
|
||
|
" <tr>"
|
||
|
" <td>"
|
||
|
" <label for\"mqttPass\">MQTT Password</label>"
|
||
|
" </td><td>"
|
||
|
" <input type=\"text\" name=\"mqttPass\" id=\"mqttPass\"/>"
|
||
|
" </td>"
|
||
|
" </tr>"
|
||
|
" <tr>"
|
||
|
" <td>"
|
||
|
" <label for\"mqttClientId\">MQTT ClientId</label>"
|
||
|
" </td><td>"
|
||
|
" <input type=\"text\" name=\"mqttClientId\" id=\"mqttClientId\"/>"
|
||
|
" </td>"
|
||
|
" </tr>"
|
||
|
" <tr>"
|
||
|
" <td>"
|
||
|
" <label for\"mqttTopic\">MQTT Topic</label>"
|
||
|
" </td><td>"
|
||
|
" <input type=\"text\" name=\"mqttTopic\" id=\"mqttTopic\"/>"
|
||
|
" </td>"
|
||
|
" </tr>"
|
||
|
" <tr>"
|
||
|
" <td>"
|
||
|
" <label for\"mqttPort\">MQTT Port</label>"
|
||
|
" </td><td>"
|
||
|
" <input type=\"text\" name=\"mqttPort\" id=\"mqttPort\"/>"
|
||
|
" </td>"
|
||
|
" </tr>"
|
||
|
" <tr>"
|
||
|
" <td>"
|
||
|
" <label for\"measurePeriod\">Measure Period</label>"
|
||
|
" </td><td>"
|
||
|
" <input type=\"text\" name=\"measurePeriod\" id=\"measurePeriod\"/>"
|
||
|
" </td>"
|
||
|
" </tr>"
|
||
|
" <tr>"
|
||
|
" <td colspan=\"2\">"
|
||
|
" <button type=\"submit\">Save</button>"
|
||
|
" </td>"
|
||
|
" </tr>"
|
||
|
" </table>"
|
||
|
" </form>"
|
||
|
" </body>"
|
||
|
"</html>"
|
||
|
"");
|
||
|
#ifdef DEBUG
|
||
|
Serial.println("indexHtml request served");
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
void configServeGetConfiguration() {
|
||
|
String arg;
|
||
|
|
||
|
arg = webServer.arg("wifiSsid");
|
||
|
Serial.print("wifiSsid");
|
||
|
Serial.println(arg);
|
||
|
arg = webServer.arg("wifiKey");
|
||
|
Serial.print("wifiKey");
|
||
|
Serial.println(arg);
|
||
|
arg = webServer.arg("mqttBroker");
|
||
|
Serial.print("mqttBroker");
|
||
|
Serial.println(arg);
|
||
|
arg = webServer.arg("mqttUser");
|
||
|
Serial.print("mqttUser");
|
||
|
Serial.println(arg);
|
||
|
arg = webServer.arg("mqttPass");
|
||
|
Serial.print("mqttPass");
|
||
|
Serial.println(arg);
|
||
|
arg = webServer.arg("mqttClientId");
|
||
|
Serial.print("mqttClientId");
|
||
|
Serial.println(arg);
|
||
|
arg = webServer.arg("mqttTopic");
|
||
|
Serial.print("mqttTopic");
|
||
|
Serial.println(arg);
|
||
|
arg = webServer.arg("mqttPort");
|
||
|
Serial.print("mqttPort");
|
||
|
Serial.println(arg);
|
||
|
arg = webServer.arg("measurePeriod");
|
||
|
Serial.print("measurePeriod");
|
||
|
Serial.println(arg);
|
||
|
|
||
|
webServer.send(200, "text/html", "configuration saved");
|
||
|
}
|
||
|
|