2016-10-28 18:02:39 +02:00
|
|
|
#ifndef CONFIG_DISABLE_WEB
|
2017-03-29 21:55:14 +02:00
|
|
|
#include <ESP8266HTTPUpdateServer.h>
|
2016-03-30 00:44:37 +02:00
|
|
|
|
2017-03-29 21:55:14 +02:00
|
|
|
ESP8266HTTPUpdateServer httpUpdater;
|
2016-09-28 15:28:02 +02:00
|
|
|
String gpioControlHTML = "";
|
2016-09-28 15:45:45 +02:00
|
|
|
String pwmControlHTML = "";
|
2016-09-16 11:42:33 +02:00
|
|
|
|
2016-12-14 22:19:17 +01:00
|
|
|
|
2019-06-03 00:07:12 +02:00
|
|
|
void WebBuildGpioObserved(String &html) {
|
|
|
|
if (NB_ELEMENTS(gpioObserved) > 0) {
|
2016-12-14 22:19:17 +01:00
|
|
|
html += "<fieldset>"
|
2019-06-03 00:07:12 +02:00
|
|
|
"<legend>Detector</legend>";
|
2016-12-14 22:19:17 +01:00
|
|
|
for (uint i = 0 ; i < NB_ELEMENTS(gpioObserved) ; i++) {
|
|
|
|
html += "Sensor " + String(gpioObserved[i]) + ": " + digitalRead(gpioObserved[i]) + "<br/>";
|
|
|
|
}
|
|
|
|
html += "</fieldset>";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-09-28 15:28:02 +02:00
|
|
|
void WebHandleRoot() {
|
2016-12-14 22:19:17 +01:00
|
|
|
String gpioObserved = "";
|
2018-12-19 22:36:19 +01:00
|
|
|
String optimiseConfig = "";
|
2016-12-14 22:19:17 +01:00
|
|
|
|
|
|
|
WebBuildGpioObserved(gpioObserved);
|
2019-06-03 00:07:12 +02:00
|
|
|
if (WiFi.status() == WL_CONNECTED) {
|
2018-12-19 22:36:19 +01:00
|
|
|
optimiseConfig = "<a href=\"/setupPreConfig\">Optimize Config</a><br/>";
|
|
|
|
}
|
2016-09-16 11:42:33 +02:00
|
|
|
|
2016-03-17 01:05:19 +01:00
|
|
|
server.send(200, "text/html",
|
2016-03-30 00:44:37 +02:00
|
|
|
"<head><meta http-equiv=\"refresh\" content=\"" + String(CONFIG_SAMPLING_PERIODE_MS / 1000) + "\" ></head>"
|
2016-11-20 00:06:31 +01:00
|
|
|
"<h1>You are connected to " + String(conf.host) + "</h1>"
|
2016-03-26 01:26:36 +01:00
|
|
|
"<fieldset>"
|
|
|
|
"<legend>Sensors</legend>"
|
2016-04-07 15:45:55 +02:00
|
|
|
#ifdef CONFIG_ENABLE_BMP180
|
2020-02-28 23:40:35 +01:00
|
|
|
"" + (BMP180IsConnected() ? "<h6>BMP180</h6>Temperature " + String(temp, 2) + "C<br/> Pressure " + String(pressure, 2) + "hPa<br/>" : "BMP180 Disconnected" ) + ""
|
2016-04-06 15:51:27 +02:00
|
|
|
#endif
|
2016-04-07 15:45:55 +02:00
|
|
|
#ifdef CONFIG_ENABLE_DHT
|
2020-02-28 23:40:35 +01:00
|
|
|
"" + (DHTIsConnected() ? "<h6>DHT</h6>Temperature " + String(dhtTemp, 0) + "C<br/> Humidity " + String(dhtHumidity, 0) + "%<br/>" : "DHT Disconnected" ) + ""
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ENABLE_BME680
|
|
|
|
"" + (BME680IsConnected() ? "<h6>BME680</h6>Temperature " + String(bme680T, 2) + "C<br/> Pressure " + String(bme680P, 2) + "hPa<br/> Humidity " + String(bme680H, 2) + "%<br/> Gaz " + String(bme680G, 2) + "kOhm<br/>" : "BME680 Disconnected" ) + ""
|
2016-06-04 18:45:11 +02:00
|
|
|
#endif
|
2020-07-28 19:37:19 +02:00
|
|
|
#ifdef CONFIG_BME680_BSEC_ENABLE
|
|
|
|
"" + (BME680BSECIsConnected() ? "<h6>BME680 BSEC</h6>Temperature " + String(bme680BSECT, 2) + "C<br/> Pressure " + String(bme680BSECP, 2) + "hPa<br/> Humidity " + String(bme680BSECH, 2) + "%<br/> Indoor Air Quality " + String(bme680BSECIaq, 2) + "/500<br/> IAQ Accuraccy" + String(bme680BSECIaqAcc) + "/3<br/>": "BME680 Disconnected" ) + ""
|
|
|
|
#endif
|
2016-06-04 18:45:11 +02:00
|
|
|
#ifdef CONFIG_ENABLE_DRY_SENSOR
|
2019-06-03 00:07:12 +02:00
|
|
|
"Dryness " + String((dryness * 100) / 1024) + "%<br/>"
|
2016-04-07 15:45:55 +02:00
|
|
|
#endif
|
2016-12-14 22:19:17 +01:00
|
|
|
"</fieldset>" + gpioControlHTML + gpioObserved + pwmControlHTML + "<fieldset>"
|
2016-03-26 01:26:36 +01:00
|
|
|
"<legend>Settings</legend>"
|
|
|
|
"<a href=\"/setup\">Enter Setup</a><br/>"
|
2018-12-19 22:36:19 +01:00
|
|
|
"<a href=\"/upload\">Update firmware</a><br/>" + optimiseConfig +
|
2016-03-24 14:54:55 +01:00
|
|
|
"MQTT Status: " + (MqttIsConnected() ? "Connected" : "Disconnected") + "<br/>"
|
2016-09-21 16:02:52 +02:00
|
|
|
"Wifi Strength: " + WiFi.RSSI() + "dBm<br/>"
|
2016-03-26 01:26:36 +01:00
|
|
|
"Free space: " + ESP.getFreeSketchSpace() + "<br/>"
|
|
|
|
"Free heap: " + ESP.getFreeHeap() + "<br/>"
|
2016-04-10 00:37:41 +02:00
|
|
|
"Build the " + __DATE__ + " at " + __TIME__ + "<br/>"
|
2016-03-26 01:26:36 +01:00
|
|
|
"</fieldset>"
|
2016-03-11 00:43:24 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-04-07 16:14:19 +02:00
|
|
|
void WebSendError(const char *error) {
|
2016-04-07 02:02:51 +02:00
|
|
|
server.send(500, "text/plain", error);
|
|
|
|
}
|
|
|
|
|
2019-06-03 00:07:12 +02:00
|
|
|
void WebBuildSSIDList(String &datalist) {
|
2016-07-08 16:04:20 +02:00
|
|
|
int n = WiFi.scanNetworks();
|
|
|
|
datalist = "<datalist id=\"scan_ssid\">";
|
|
|
|
// sort by RSSI
|
|
|
|
int indices[n];
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
indices[i] = i;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
for (int j = i + 1; j < n; j++) {
|
|
|
|
if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) {
|
|
|
|
std::swap(indices[i], indices[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-03 00:07:12 +02:00
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
datalist += "<option value=\"" + WiFi.SSID(indices[i]) + "\">";
|
2016-07-08 16:04:20 +02:00
|
|
|
}
|
|
|
|
datalist += "</datalist>";
|
|
|
|
}
|
|
|
|
|
2018-12-19 22:36:19 +01:00
|
|
|
void WebHandleSetupPreConfig() {
|
2019-06-03 00:07:12 +02:00
|
|
|
conf.bssid = strdup( WiFi.BSSIDstr().c_str());
|
|
|
|
conf.channel = WiFi.channel();
|
|
|
|
conf.ip_mode = 1;
|
|
|
|
conf.ip = WiFi.localIP();
|
|
|
|
conf.mask = WiFi.subnetMask();
|
|
|
|
conf.gw = WiFi.gatewayIP();
|
|
|
|
conf.dns = WiFi.dnsIP();
|
|
|
|
conf.dns2 = WiFi.dnsIP(1);
|
|
|
|
WebHandleSetup();
|
2018-12-19 22:36:19 +01:00
|
|
|
}
|
|
|
|
|
2016-03-24 14:54:55 +01:00
|
|
|
void WebHandleSetup() {
|
2016-07-08 16:04:20 +02:00
|
|
|
String ssidlist;
|
|
|
|
WebBuildSSIDList(ssidlist);
|
2019-06-03 00:07:12 +02:00
|
|
|
String dhcpChecked = conf.ip_mode == 0 ? "checked" : "";
|
|
|
|
String staticChecked = conf.ip_mode == 1 ? "checked" : "";
|
2016-07-08 16:04:20 +02:00
|
|
|
|
2016-03-14 17:36:56 +01:00
|
|
|
|
2016-03-11 00:43:24 +01:00
|
|
|
server.send(200, "text/html", "<form action=\"/save\" method=\"get\">"
|
2016-03-14 17:36:56 +01:00
|
|
|
"<fieldset>"
|
|
|
|
"<legend>Wifi configuration:</legend>"
|
2018-12-19 22:36:19 +01:00
|
|
|
"<div><label for=\"ssid\">Wifi SSID: </label> <br/><input list=\"scan_ssid\" type=\"text\" name=\"ssid\" value=\"" + String(conf.ssid) + "\" /></div>"
|
2016-07-08 16:04:20 +02:00
|
|
|
"" + ssidlist + ""
|
2019-06-03 00:07:12 +02:00
|
|
|
"<div><label for=\"password\">Wifi Password: </label><br/><input type=\"password\" name=\"password\" style=\"border-color:red\" value=\"" + String(conf.password) + "\"/> </div>"
|
2018-12-19 22:36:19 +01:00
|
|
|
"<div><label for=\"host\">Hostname: </label><br/><input type=\"text\" name=\"host\" value=\"" + String(conf.host) + "\" /> </div>"
|
|
|
|
"<div><label for=\"channel\">Channel (0 for auto): </label><br/><input type=\"text\" name=\"channel\" value=\"" + String(conf.channel) + "\" /> </div>"
|
|
|
|
"<div><label for=\"bssid\">BSSID (Empty for auto): </label><br/><input type=\"text\" name=\"bssid\" value=\"" + String(conf.bssid) + "\" /> </div>"
|
2016-03-14 17:36:56 +01:00
|
|
|
"</fieldset>"
|
|
|
|
"<fieldset>"
|
2016-04-06 19:34:29 +02:00
|
|
|
"<legend>IP Configuration</legend>"
|
2019-06-03 00:07:12 +02:00
|
|
|
"<div><input type=\"radio\" name=\"ip_config\" value=\"0\" " + dhcpChecked + ">DHCP <input type=\"radio\" name=\"ip_config\" value=\"1\" " + staticChecked + ">Static</div>"
|
|
|
|
"<div><label for=\"ip\">Ip :</label><br/><input type=\"text\" name=\"ip\" value=\"" + (conf.ip == 0 ? WiFi.localIP().toString() : IPAddress(conf.ip).toString()) + "\" /> </div>"
|
|
|
|
"<div><label for=\"gw\">Gateway :</label><br/><input type=\"text\" name=\"gw\" value=\"" + (conf.gw == 0 ? WiFi.gatewayIP().toString() : IPAddress(conf.gw).toString()) + "\" /> </div>"
|
|
|
|
"<div><label for=\"mask\">Netmask :</label><br/><input type=\"text\" name=\"mask\" value=\"" + (conf.mask == 0 ? WiFi.subnetMask().toString() : IPAddress(conf.mask).toString()) + "\" /> </div>"
|
|
|
|
"<div><label for=\"mask\">DNS :</label><br/><input type=\"text\" name=\"dns\" value=\"" + (conf.dns == 0 ? WiFi.dnsIP().toString() : IPAddress(conf.dns).toString()) + "\" /> </div>"
|
|
|
|
"<div><label for=\"mask\">DNS2 :</label><br/><input type=\"text\" name=\"dns2\" value=\"" + (conf.dns2 == 0 ? WiFi.dnsIP(1).toString() : IPAddress(conf.dns2).toString()) + "\" /> </div>"
|
2016-04-06 19:34:29 +02:00
|
|
|
"</fieldset>"
|
|
|
|
"<fieldset>"
|
2016-03-14 17:36:56 +01:00
|
|
|
"<legend>MQTT:</legend>"
|
2016-11-20 00:06:31 +01:00
|
|
|
"<div><label for=\"mqttServer\">Server :</label><br/><input type=\"text\" name=\"mqttServer\" value=\"" + String(conf.mqttServer) + "\" /> </div>"
|
|
|
|
"<div><label for=\"mqttUser\">Username :</label><br/><input type=\"text\" name=\"mqttUser\" value=\"" + String(conf.mqttUser) + "\" /> </div>"
|
2019-06-03 00:07:12 +02:00
|
|
|
"<div><label for=\"mqttPasswd\">Password :</label><br/><input type=\"password\" name=\"mqttPasswd\" style=\"border-color:red\" value=\"" + String(conf.mqttPasswd) + "\" /> </div>"
|
2016-11-20 00:06:31 +01:00
|
|
|
"<div><label for=\"mqttPort\">Port :</label><br/><input type=\"text\" name=\"mqttPort\" value=\"" + String(conf.mqttPort) + "\" /> (8883 for secure Mqtts) </div>"
|
2016-03-14 17:36:56 +01:00
|
|
|
"</fieldset>"
|
2016-03-11 00:43:24 +01:00
|
|
|
"<div class=\"button\"> <button type=\"submit\">Save</button></div>"
|
|
|
|
"</form>");
|
|
|
|
}
|
|
|
|
|
2016-03-24 14:54:55 +01:00
|
|
|
void WebHandleGpio() {
|
2016-03-11 00:43:24 +01:00
|
|
|
if (!server.hasArg("gpio") || !server.hasArg("value")) {
|
|
|
|
server.send(500, "text/plain", "Bad arguments\r\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-24 14:54:55 +01:00
|
|
|
MqttChangeGpioValue(server.arg("gpio").toInt(), server.arg("value").toInt());
|
2016-03-11 00:43:24 +01:00
|
|
|
server.send(200, "text/html", "<h1>GPIO" + server.arg("gpio") + " changed to " + server.arg("value") + "</h1>");
|
|
|
|
}
|
|
|
|
|
2016-09-28 15:45:45 +02:00
|
|
|
void WebHandlePWM() {
|
|
|
|
if (!server.hasArg("gpio") || !server.hasArg("value")) {
|
|
|
|
server.send(500, "text/plain", "Bad arguments\r\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MqttChangePWMValue(server.arg("gpio").toInt(), server.arg("value").toInt());
|
|
|
|
server.send(200, "text/html", "<h1>PWM" + server.arg("gpio") + " changed to " + server.arg("value") + "</h1>");
|
|
|
|
}
|
|
|
|
|
2016-04-07 16:14:19 +02:00
|
|
|
boolean WebSetIp(IPAddress &addr, const char *id, const char *error) {
|
2016-04-07 02:02:51 +02:00
|
|
|
if (server.arg(id) != "" && !addr.fromString(server.arg(id).c_str())) {
|
|
|
|
WebSendError(error);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-24 14:54:55 +01:00
|
|
|
void WebHandleSave() {
|
2016-04-07 02:02:51 +02:00
|
|
|
IPAddress ip;
|
|
|
|
IPAddress gw;
|
|
|
|
IPAddress mask;
|
|
|
|
IPAddress dns;
|
|
|
|
IPAddress dns2;
|
2016-03-11 00:43:24 +01:00
|
|
|
|
2016-04-06 19:34:29 +02:00
|
|
|
if (!server.hasArg("ssid") || !server.hasArg("password") || !server.hasArg("host")
|
|
|
|
|| !server.hasArg("mqttServer") || !server.hasArg("mqttUser") || !server.hasArg("mqttPasswd")
|
|
|
|
|| !server.hasArg("mqttPort") || !server.hasArg("ip_config") || !server.hasArg("ip")
|
|
|
|
|| !server.hasArg("gw") || !server.hasArg("mask") || !server.hasArg("dns")
|
2018-12-19 22:36:19 +01:00
|
|
|
|| !server.hasArg("dns2") || !server.hasArg("channel") || ! server.hasArg("bssid")) {
|
2016-03-11 00:43:24 +01:00
|
|
|
server.send(500, "text/plain", "Bad arguments\r\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-07 02:02:51 +02:00
|
|
|
|
|
|
|
//Check Ip configuration
|
|
|
|
if (server.arg("ip_config").toInt() == 1) {
|
|
|
|
if (!WebSetIp(ip, "ip", "Incorrect IP") || !WebSetIp(gw, "gw", "Incorrect Gateway") || !WebSetIp(mask, "mask", "Incorrect NetMask") ||
|
|
|
|
!WebSetIp(dns, "dns", "Incorrect DNS") || !WebSetIp(dns2, "dns2", "Incorrect DNS2")) {
|
2018-12-19 22:36:19 +01:00
|
|
|
server.send(500, "text/plain", "Bad arguments\r\n");
|
2016-04-07 02:02:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-20 00:06:31 +01:00
|
|
|
productConfig newConf = {BOOTMODE_NORMAL, strdup(server.arg("ssid").c_str()), strdup(server.arg("password").c_str()),
|
2019-06-03 00:07:12 +02:00
|
|
|
strdup(server.arg("host").c_str()), strdup(server.arg("mqttServer").c_str()), strdup(server.arg("mqttUser").c_str()),
|
|
|
|
strdup(server.arg("mqttPasswd").c_str()), server.arg("mqttPort").toInt(),
|
|
|
|
server.arg("ip_config").toInt(), static_cast<uint32_t>(ip), static_cast<uint32_t>(gw),
|
2020-02-28 17:16:39 +01:00
|
|
|
static_cast<uint32_t>(mask), static_cast<uint32_t>(dns), static_cast<uint32_t>(dns2), static_cast<uint8_t>(server.arg("channel").toInt()), strdup(server.arg("bssid").c_str())
|
2019-06-03 00:07:12 +02:00
|
|
|
};
|
2016-11-20 00:06:31 +01:00
|
|
|
if (EepromSaveConfig(newConf) < 0) {
|
2016-04-07 02:02:51 +02:00
|
|
|
WebSendError("Cannot Save Credentials (Too long ?Contains \";\"?)\r\n");
|
2016-03-11 00:43:24 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-06-03 00:07:12 +02:00
|
|
|
if (WiFi.softAPIP() != IPAddress((uint32_t)0)) {
|
2016-07-08 01:03:32 +02:00
|
|
|
//In STA mode, we can test the AP connection
|
|
|
|
WiFi.begin(server.arg("ssid").c_str(), server.arg("password").c_str());
|
|
|
|
server.send(200, "text/html", "<h1>Configuration Saved</h1><br/>"
|
2019-06-03 00:07:12 +02:00
|
|
|
"<a href=\"/wifiStatus\">Check Wifi Configuration</a><br/>"
|
|
|
|
"<a href=\"/reboot\">Reboot</a><br/>");
|
|
|
|
} else {
|
2016-07-08 01:03:32 +02:00
|
|
|
server.send(200, "text/html", "<h1>Configuration Saved</h1><br/>"
|
2019-06-03 00:07:12 +02:00
|
|
|
"<a href=\"/reboot\">Reboot</a><br/>");
|
2016-07-08 01:03:32 +02:00
|
|
|
}
|
2016-03-11 00:43:24 +01:00
|
|
|
}
|
|
|
|
|
2016-03-24 14:54:55 +01:00
|
|
|
void WebHandleOTA() {
|
2016-12-14 22:57:01 +01:00
|
|
|
SKETCH_DEBUG_PRINTLN("Activating OTA mode");
|
|
|
|
server.send(200, "text/html", "<h1>Setting OTA mode</h1><br/>"
|
|
|
|
"Web ui will be disabled<br/>");
|
|
|
|
mode = BOOTMODE_OTA;
|
|
|
|
OTASetup();
|
2016-03-11 00:43:24 +01:00
|
|
|
}
|
|
|
|
|
2016-03-24 14:54:55 +01:00
|
|
|
void WebHandleNotFound() {
|
2016-03-11 00:43:24 +01:00
|
|
|
String message = "File Not Found\n\n";
|
|
|
|
message += "URI: ";
|
|
|
|
message += server.uri();
|
|
|
|
message += "\nMethod: ";
|
|
|
|
message += (server.method() == HTTP_GET) ? "GET" : "POST";
|
|
|
|
message += "\nArguments: ";
|
|
|
|
message += server.args();
|
|
|
|
message += "\n";
|
|
|
|
for (uint8_t i = 0; i < server.args(); i++) {
|
|
|
|
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
|
|
|
|
}
|
|
|
|
server.send(404, "text/plain", message);
|
|
|
|
}
|
|
|
|
|
2016-03-24 14:54:55 +01:00
|
|
|
void WebHandleReboot() {
|
2016-03-26 15:07:15 +01:00
|
|
|
SKETCH_DEBUG_PRINTLN("HTTP request to reboot");
|
2016-03-16 01:09:25 +01:00
|
|
|
server.send(200, "text/html", "<h1>Device Reboot</h1><br/>");
|
|
|
|
ESP.restart();
|
|
|
|
}
|
|
|
|
|
2016-07-08 01:03:32 +02:00
|
|
|
String statusToString(wl_status_t status) {
|
2019-06-03 00:07:12 +02:00
|
|
|
switch (status) {
|
2016-07-08 01:03:32 +02:00
|
|
|
case WL_IDLE_STATUS: return String("Idle");
|
|
|
|
case WL_NO_SSID_AVAIL: return String("Wifi not found");
|
|
|
|
case WL_CONNECTED: return String("Connected");
|
|
|
|
case WL_CONNECT_FAILED: return String("Connection failed (Wrong password ?)");
|
|
|
|
case WL_CONNECTION_LOST: return String("Connection Lost");
|
|
|
|
case WL_DISCONNECTED: return String("Connecting");
|
|
|
|
default: return String(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebHandleWifiStatus() {
|
|
|
|
|
|
|
|
String message;
|
2019-06-03 00:07:12 +02:00
|
|
|
if (WiFi.status() == WL_DISCONNECTED)
|
2016-07-08 01:03:32 +02:00
|
|
|
message += "<head><meta http-equiv=\"refresh\" content=\"1\" ></head>";
|
|
|
|
message += "<h1>Wifi Connection Status</h1><br/>";
|
|
|
|
message += "Connection to ";
|
|
|
|
message += WiFi.SSID();
|
|
|
|
message += ":<br/>";
|
|
|
|
message += statusToString(WiFi.status());
|
|
|
|
message += "<br/>";
|
2019-06-03 00:07:12 +02:00
|
|
|
if (mode == BOOTMODE_SETUP && WiFi.status() == WL_CONNECTED) {
|
2017-01-01 23:35:19 +01:00
|
|
|
message += "Wifi correctly setup! You can reboot now<br/>";
|
2016-07-08 01:03:32 +02:00
|
|
|
message += "<a href=\"/reboot\">Reboot</a><br/>";
|
|
|
|
}
|
2019-06-03 00:07:12 +02:00
|
|
|
if (WiFi.status() == WL_CONNECT_FAILED || WiFi.status() == WL_NO_SSID_AVAIL) {
|
2016-07-08 01:03:32 +02:00
|
|
|
message += "Try to reconfigure you WiFi details<br/>";
|
|
|
|
message += "<a href=\"/setup\">Enter Setup</a><br/>";
|
|
|
|
}
|
|
|
|
server.send(200, "text/html", message);
|
|
|
|
}
|
|
|
|
|
2019-06-03 00:07:12 +02:00
|
|
|
void WebBuildGpioControl() {
|
|
|
|
if (NB_ELEMENTS(gpioControlled) > 0) {
|
2016-09-28 15:28:02 +02:00
|
|
|
gpioControlHTML += "<fieldset>"
|
2019-06-03 00:07:12 +02:00
|
|
|
"<legend>Relay</legend>";
|
2016-12-13 22:31:14 +01:00
|
|
|
for (uint i = 0 ; i < NB_ELEMENTS(gpioControlled) ; i++) {
|
|
|
|
gpioControlHTML += "Relay " + String(gpioControlled[i]) + " " + "<a href=\"/gpio?gpio=" + String(gpioControlled[i]) + "&value=1\">ON</a>/";
|
|
|
|
gpioControlHTML += "<a href=\"/gpio?gpio=" + String(gpioControlled[i]) + "&value=0\">OFF</a><br/>";
|
2016-09-28 15:28:02 +02:00
|
|
|
}
|
|
|
|
gpioControlHTML += "</fieldset>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-03 00:07:12 +02:00
|
|
|
void WebBuildPwmControl() {
|
|
|
|
if (NB_ELEMENTS(pwmControlled) > 0) {
|
2016-09-28 15:45:45 +02:00
|
|
|
pwmControlHTML += "<fieldset>"
|
2019-06-03 00:07:12 +02:00
|
|
|
"<legend>PWM</legend>";
|
2016-12-13 22:31:14 +01:00
|
|
|
for (uint i = 0 ; i < NB_ELEMENTS(pwmControlled) ; i++) {
|
|
|
|
pwmControlHTML += "PWM " + String(pwmControlled[i]) + "<br/>";
|
2016-09-28 15:45:45 +02:00
|
|
|
pwmControlHTML += "<input type=\"range\" min=\"0\" max=\"1023\""
|
|
|
|
"style=\"background:#eee\""
|
2016-12-13 22:31:14 +01:00
|
|
|
"onChange=\"setPWM(this.value," + String(pwmControlled[i]) + ")\" />";
|
2016-09-28 15:45:45 +02:00
|
|
|
}
|
|
|
|
pwmControlHTML += "<script type=\"text/javascript\">"
|
|
|
|
"function setPWM(newValue, gpio){"
|
|
|
|
" var xmlHttp = new XMLHttpRequest();"
|
|
|
|
" xmlHttp.open( \"GET\", \"/pwm?gpio=\"+ gpio + \"&value=\" + newValue, true );" // false for synchronous request
|
|
|
|
" xmlHttp.send( null );}"
|
|
|
|
"</script>";
|
|
|
|
pwmControlHTML += "</fieldset>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-07 16:14:19 +02:00
|
|
|
void WebSetupServer(int ) {
|
2016-09-28 15:28:02 +02:00
|
|
|
WebBuildGpioControl();
|
2016-09-28 15:45:45 +02:00
|
|
|
WebBuildPwmControl();
|
2016-09-28 15:28:02 +02:00
|
|
|
|
2016-03-24 14:54:55 +01:00
|
|
|
server.on("/", WebHandleRoot);
|
2018-12-19 22:36:19 +01:00
|
|
|
server.on("/setupPreConfig", WebHandleSetupPreConfig);
|
2016-03-24 14:54:55 +01:00
|
|
|
server.on("/setup", WebHandleSetup);
|
|
|
|
server.on("/save", WebHandleSave);
|
|
|
|
server.on("/gpio", WebHandleGpio);
|
2016-09-28 15:45:45 +02:00
|
|
|
server.on("/pwm", WebHandlePWM);
|
2016-03-24 14:54:55 +01:00
|
|
|
server.on("/otamode", WebHandleOTA);
|
|
|
|
server.on("/reboot", WebHandleReboot);
|
2016-07-08 01:03:32 +02:00
|
|
|
server.on("/wifiStatus", WebHandleWifiStatus);
|
2016-03-11 01:41:21 +01:00
|
|
|
|
2016-03-24 14:54:55 +01:00
|
|
|
server.onNotFound(WebHandleNotFound);
|
2017-03-29 21:55:14 +02:00
|
|
|
httpUpdater.setup(&server, "/upload");
|
2016-03-11 00:43:24 +01:00
|
|
|
server.begin();
|
2016-03-26 15:07:15 +01:00
|
|
|
SKETCH_DEBUG_PRINTLN("HTTP server started");
|
2016-03-11 00:43:24 +01:00
|
|
|
}
|
2016-10-28 18:02:39 +02:00
|
|
|
#else
|
|
|
|
|
2019-06-03 00:07:12 +02:00
|
|
|
void WebHandleRoot() {}
|
|
|
|
void WebHandleSetupPreConfig() {}
|
|
|
|
void WebHandleSetup() {}
|
|
|
|
void WebHandleGpio() {}
|
|
|
|
void WebHandleSave() {}
|
|
|
|
void WebHandleOTA() {}
|
|
|
|
void WebHandleNotFound() {}
|
|
|
|
void WebSetupServer(int bootmode) {}
|
2016-10-28 18:02:39 +02:00
|
|
|
#endif
|