all to async webserver
This commit is contained in:
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"functional": "cpp"
|
||||
}
|
||||
}
|
||||
@@ -10,15 +10,6 @@
|
||||
window.onload = function() {
|
||||
getPageContent("/accesspoint");
|
||||
};
|
||||
|
||||
function setApMode(){
|
||||
var obj = {};
|
||||
obj["apMode"] = document.getElementById("apMode").checked;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "/accesspoint", true);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.send(JSON.stringify(obj));
|
||||
}
|
||||
</script>
|
||||
<body>
|
||||
<ul class="navbar">
|
||||
@@ -35,13 +26,17 @@
|
||||
</ul>
|
||||
<h1>WSEN Access point mode</h1>
|
||||
<div id="main">
|
||||
<form method='post' action='accesspoint'>
|
||||
<div class='datafield'>
|
||||
<h2>Access Point Mode</h2>
|
||||
<div class='checkboxThree'>
|
||||
<input type='checkbox' id='apMode' name='apmode' onclick="setApMode();">
|
||||
<label for="apMode"></label>
|
||||
<input type='checkbox' id='apMode' name='apMode'><label for='apMode'></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class='datafield'>
|
||||
<div class='submitWrapper'><input type='submit' value='Save Settings'></div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -21,7 +21,7 @@
|
||||
<h1>WSEN Reset Default Settings</h1>
|
||||
<div id="main">
|
||||
<div class="datafield">
|
||||
<h2>Reset</h2>
|
||||
<h2>Reset eeprom to default settings</h2>
|
||||
<div class="submitWrapper">
|
||||
<form method="POST" action="clear">
|
||||
<input value="Default Settings" type="submit">
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<label>PRTG Server :</label>
|
||||
<input id="prtgserver" name='prtgserver' maxlength='63' size='64' type='text'>
|
||||
<input id="prtgserver" name='prtgserver' maxlength='31' size='32' type='text'>
|
||||
</div>
|
||||
<div>
|
||||
<label>PRTG Server Port :</label>
|
||||
|
||||
BIN
data/favicon.ico
Normal file
BIN
data/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
@@ -28,6 +28,7 @@
|
||||
row.insertCell(1).innerHTML = network.chan;
|
||||
row.insertCell(2).innerHTML = network.rssi;
|
||||
row.insertCell(3).innerHTML = network.encrypt;
|
||||
row.insertCell(4).innerHTML = network.hidden;
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -80,6 +81,7 @@
|
||||
<th>Channel</th>
|
||||
<th>RSSI</th>
|
||||
<th>Encryption</th>
|
||||
<th>Hidden</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
//#include <FS.h>
|
||||
#include <LittleFS.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266SSDP.h>
|
||||
#include <ESPAsyncTCP.h> //https://github.com/me-no-dev/ESPAsyncTCP
|
||||
#include <ESPAsyncWebServer.h> //https://github.com/me-no-dev/ESPAsyncWebServer
|
||||
#include "AsyncJson.h"
|
||||
#include <ArduinoJson.h> //https://arduinojson.org/
|
||||
#include <StreamString.h>
|
||||
#include "global.h"
|
||||
#include "pins.h"
|
||||
#include "h1602_eeprom.h"
|
||||
@@ -15,8 +17,6 @@ AsyncWebServer asyncServer(80);
|
||||
|
||||
boolean isAuthenticated(AsyncWebServerRequest *request)
|
||||
{
|
||||
//return request->authenticate(getEeprom()->www_username, getEeprom()->www_password);
|
||||
|
||||
if (!request->authenticate(getEeprom()->www_username, getEeprom()->www_password))
|
||||
{
|
||||
request->requestAuthentication();
|
||||
@@ -48,7 +48,7 @@ void notFound(AsyncWebServerRequest *request)
|
||||
|
||||
void sendPlainError(AsyncWebServerRequest *request)
|
||||
{
|
||||
request->send(200, "text/plain", "I'm sorry Dave, I'm afraid I can't do that");
|
||||
request->send(200, F("text/plain"), F("I'm sorry Dave, I'm afraid I can't do that"));
|
||||
}
|
||||
|
||||
//--------------- Index.html -------------------------------
|
||||
@@ -60,7 +60,6 @@ void LiveInfoGet(AsyncWebServerRequest *request)
|
||||
if (request->args() == 0)
|
||||
{
|
||||
AsyncJsonResponse *response = new AsyncJsonResponse();
|
||||
//response->addHeader("Server", "ESP Async Web Server");
|
||||
JsonVariant &jsonObj = response->getRoot();
|
||||
jsonObj["rssi"] = WiFi.RSSI();
|
||||
jsonObj["uptimeDay"] = uptime.Day;
|
||||
@@ -72,21 +71,6 @@ void LiveInfoGet(AsyncWebServerRequest *request)
|
||||
jsonObj["heap"] = ESP.getHeapFragmentation();
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
|
||||
// AsyncResponseStream *response = request->beginResponseStream("application/json");
|
||||
// const int JSON_MAX_SIZE = 1024;
|
||||
// DynamicJsonDocument doc(JSON_MAX_SIZE);
|
||||
// JsonObject root = doc.to<JsonObject>();
|
||||
// root["rssi"] = WiFi.RSSI();
|
||||
// root["uptimeDay"] = uptime.Day;
|
||||
// root["uptimeHour"] = uptime.Hour;
|
||||
// root["uptimeMinute"] = uptime.Minute;
|
||||
// root["uptimeSecond"] = uptime.Second;
|
||||
// root["free"] = ESP.getFreeHeap();
|
||||
// root["max"] = ESP.getMaxFreeBlockSize();
|
||||
// root["heap"] = ESP.getHeapFragmentation();
|
||||
// serializeJson(root, *response);
|
||||
// request->send(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -104,7 +88,6 @@ void InfoGet(AsyncWebServerRequest *request)
|
||||
if (request->args() == 0)
|
||||
{
|
||||
AsyncJsonResponse *response = new AsyncJsonResponse();
|
||||
//response->addHeader("Server", "ESP Async Web Server");
|
||||
JsonVariant &jsonObj = response->getRoot();
|
||||
jsonObj["mac"] = MAC_char;
|
||||
jsonObj["chipid"] = String(ESP.getChipId(), DEC);
|
||||
@@ -123,28 +106,6 @@ void InfoGet(AsyncWebServerRequest *request)
|
||||
jsonObj["isSerialSet"] = getEeprom()->isSerialSet;
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
|
||||
// AsyncResponseStream *response = request->beginResponseStream("application/json");
|
||||
// const int JSON_MAX_SIZE = 1024;
|
||||
// DynamicJsonDocument doc(JSON_MAX_SIZE);
|
||||
// JsonObject root = doc.to<JsonObject>();
|
||||
// root["mac"] = MAC_char;
|
||||
// root["chipid"] = String(ESP.getChipId(), DEC);
|
||||
// root["version"] = softwareVersion;
|
||||
// root["sdkversion"] = String(ESP.getFullVersion());
|
||||
// String cmp = compileDate;
|
||||
// cmp += " , ";
|
||||
// cmp += compileTime;
|
||||
// root["compiledate"] = cmp;
|
||||
// root["vcc"] = (ESP.getVcc() / 1024.0f);
|
||||
// root["ipaddress"] = WiFi.localIP().toString();
|
||||
// root["subnet"] = WiFi.subnetMask().toString();
|
||||
// root["gateway"] = WiFi.gatewayIP().toString();
|
||||
// root["dns"] = WiFi.dnsIP().toString();
|
||||
// root["serialnumber"] = getEeprom()->serialnumber;
|
||||
// root["isSerialSet"] = getEeprom()->isSerialSet;
|
||||
// serializeJson(root, *response);
|
||||
// request->send(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -219,10 +180,6 @@ void ConfigPost(AsyncWebServerRequest *request)
|
||||
getEeprom()->updateTime = request->arg("update").toInt();
|
||||
|
||||
startSendTimer();
|
||||
// if (getEeprom()->updateTime == 0)
|
||||
// detachSendTimer();
|
||||
// else
|
||||
// attachSendTimer(getEeprom()->updateTime);
|
||||
saveEeprom();
|
||||
}
|
||||
request->redirect("/config.html");
|
||||
@@ -238,12 +195,11 @@ void AccesspointGet(AsyncWebServerRequest *request)
|
||||
digitalWrite(LED_RED, LOW);
|
||||
if (request->args() == 0)
|
||||
{
|
||||
DynamicJsonDocument jsonBuffer(24);
|
||||
jsonBuffer["apMode"] = eepromStruct.apMode;
|
||||
String JSONmessageBuffer;
|
||||
Serial.println(jsonBuffer.memoryUsage());
|
||||
serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
request->send(200, "application/json", JSONmessageBuffer);
|
||||
AsyncJsonResponse *response = new AsyncJsonResponse();
|
||||
JsonVariant &jsonObj = response->getRoot();
|
||||
jsonObj["apMode"] = getEeprom()->apMode;
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -257,25 +213,9 @@ void AccesspointPost(AsyncWebServerRequest *request)
|
||||
if (isAuthenticated(request))
|
||||
{
|
||||
digitalWrite(LED_RED, LOW);
|
||||
if (request->args() == 1)
|
||||
{
|
||||
StaticJsonDocument<32> doc;
|
||||
DeserializationError error = deserializeJson(doc, request->arg("plain"));
|
||||
if (error)
|
||||
{
|
||||
Serial.print(F("deserializeJson() failed: "));
|
||||
Serial.println(error.c_str());
|
||||
return;
|
||||
}
|
||||
getEeprom()->apMode = doc["apMode"];
|
||||
saveEeprom();
|
||||
//request->send(200, "application/json");
|
||||
request->redirect("/accesspoint.html");
|
||||
}
|
||||
else
|
||||
{
|
||||
sendPlainError(request);
|
||||
}
|
||||
getEeprom()->apMode = request->hasArg("apMode") ? true : false;
|
||||
saveEeprom();
|
||||
request->redirect("/accesspoint.html");
|
||||
digitalWrite(LED_RED, HIGH);
|
||||
}
|
||||
}
|
||||
@@ -290,31 +230,29 @@ void InputsGet(AsyncWebServerRequest *request)
|
||||
{
|
||||
if (request->hasArg("settings"))
|
||||
{
|
||||
DynamicJsonDocument jsonBuffer(256);
|
||||
jsonBuffer["ch1Enabled"] = getEepromChannel(1)->enable;
|
||||
jsonBuffer["ch1Name"] = getEepromChannel(1)->channel;
|
||||
jsonBuffer["ch2Enabled"] = getEepromChannel(2)->enable;
|
||||
jsonBuffer["ch2Name"] = getEepromChannel(2)->channel;
|
||||
jsonBuffer["ch3Enabled"] = getEepromChannel(3)->enable;
|
||||
jsonBuffer["ch3Name"] = getEepromChannel(3)->channel;
|
||||
jsonBuffer["ch4Enabled"] = getEepromChannel(4)->enable;
|
||||
jsonBuffer["ch4Name"] = getEepromChannel(4)->channel;
|
||||
String JSONmessageBuffer;
|
||||
//Serial.println(jsonBuffer.memoryUsage());
|
||||
serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
request->send(200, "application/json", JSONmessageBuffer);
|
||||
AsyncJsonResponse *response = new AsyncJsonResponse();
|
||||
JsonVariant &jsonObj = response->getRoot();
|
||||
jsonObj["ch1Enabled"] = getEepromChannel(1)->enable;
|
||||
jsonObj["ch1Name"] = getEepromChannel(1)->channel;
|
||||
jsonObj["ch2Enabled"] = getEepromChannel(2)->enable;
|
||||
jsonObj["ch2Name"] = getEepromChannel(2)->channel;
|
||||
jsonObj["ch3Enabled"] = getEepromChannel(3)->enable;
|
||||
jsonObj["ch3Name"] = getEepromChannel(3)->channel;
|
||||
jsonObj["ch4Enabled"] = getEepromChannel(4)->enable;
|
||||
jsonObj["ch4Name"] = getEepromChannel(4)->channel;
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
}
|
||||
else if (request->hasArg("state"))
|
||||
{
|
||||
DynamicJsonDocument jsonBuffer(128);
|
||||
jsonBuffer["in1_state"] = !digitalRead(inputTable[1]);
|
||||
jsonBuffer["in2_state"] = !digitalRead(inputTable[2]);
|
||||
jsonBuffer["in3_state"] = !digitalRead(inputTable[3]);
|
||||
jsonBuffer["in4_state"] = !digitalRead(inputTable[4]);
|
||||
String JSONmessageBuffer;
|
||||
//Serial.println(jsonBuffer.memoryUsage());
|
||||
serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
request->send(200, "application/json", JSONmessageBuffer);
|
||||
AsyncJsonResponse *response = new AsyncJsonResponse();
|
||||
JsonVariant &jsonObj = response->getRoot();
|
||||
jsonObj["in1_state"] = !digitalRead(inputTable[1]);
|
||||
jsonObj["in2_state"] = !digitalRead(inputTable[2]);
|
||||
jsonObj["in3_state"] = !digitalRead(inputTable[3]);
|
||||
jsonObj["in4_state"] = !digitalRead(inputTable[4]);
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -338,9 +276,6 @@ void InputsPost(AsyncWebServerRequest *request)
|
||||
digitalWrite(LED_RED, LOW);
|
||||
if (request->args() != 0)
|
||||
{
|
||||
//const char *enableTable[5] = {"", "en1", "en2", "en3", "en4"};
|
||||
//const char *channelTable[5] = {"", "ch1Name", "ch2Name", "ch3Name", "ch4Name"};
|
||||
|
||||
for (int i = 1; i < 5; i++)
|
||||
{
|
||||
if (request->hasArg(enableTable[i]))
|
||||
@@ -353,20 +288,7 @@ void InputsPost(AsyncWebServerRequest *request)
|
||||
getEepromChannel(i)->enable = false;
|
||||
detachInputInterrupt(i);
|
||||
}
|
||||
|
||||
startSendTimer();
|
||||
// if (!anyChannelEnabled())
|
||||
// {
|
||||
// detachSendTimer();
|
||||
// }
|
||||
// if (getEepromChannel(1)->enable == false && getEepromChannel(2)->enable == false && getEepromChannel(3)->enable == false && getEepromChannel(4)->enable == false)
|
||||
// {
|
||||
// detachSendTimer();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// attachSendTimer(getEeprom()->updateTime);
|
||||
// }
|
||||
request->arg(channelTable[i]).toCharArray(getEepromChannel(i)->channel, sizeof(getEepromChannel(i)->channel) - 1);
|
||||
}
|
||||
saveEeprom();
|
||||
@@ -384,13 +306,12 @@ void CredentialsGet(AsyncWebServerRequest *request)
|
||||
digitalWrite(LED_RED, LOW);
|
||||
if (request->args() == 0)
|
||||
{
|
||||
DynamicJsonDocument jsonBuffer(64);
|
||||
jsonBuffer["username"] = eepromStruct.www_username;
|
||||
jsonBuffer["password"] = eepromStruct.www_password;
|
||||
String JSONmessageBuffer;
|
||||
//Serial.println(jsonBuffer.memoryUsage());
|
||||
serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
request->send(200, "application/json", JSONmessageBuffer);
|
||||
AsyncJsonResponse *response = new AsyncJsonResponse();
|
||||
JsonVariant &jsonObj = response->getRoot();
|
||||
jsonObj["username"] = getEeprom()->www_username;
|
||||
jsonObj["password"] = getEeprom()->www_password;
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -423,16 +344,15 @@ void WifiGet(AsyncWebServerRequest *request)
|
||||
digitalWrite(LED_RED, LOW);
|
||||
if (request->args() == 0)
|
||||
{
|
||||
DynamicJsonDocument jsonBuffer(128);
|
||||
jsonBuffer["ssid"] = getEeprom()->ssid;
|
||||
jsonBuffer["pass"] = getEeprom()->password;
|
||||
jsonBuffer["ssdp"] = getEeprom()->ssdp;
|
||||
jsonBuffer["mdns"] = getEeprom()->use_mdns;
|
||||
jsonBuffer["llmnr"] = getEeprom()->use_llmnr;
|
||||
String JSONmessageBuffer;
|
||||
//Serial.println(jsonBuffer.memoryUsage());
|
||||
serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
request->send(200, "application/json", JSONmessageBuffer);
|
||||
AsyncJsonResponse *response = new AsyncJsonResponse();
|
||||
JsonVariant &jsonObj = response->getRoot();
|
||||
jsonObj["ssid"] = getEeprom()->ssid;
|
||||
jsonObj["pass"] = getEeprom()->password;
|
||||
jsonObj["ssdp"] = getEeprom()->ssdp;
|
||||
jsonObj["mdns"] = getEeprom()->use_mdns;
|
||||
jsonObj["llmnr"] = getEeprom()->use_llmnr;
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -495,10 +415,15 @@ void WifiScanGet(AsyncWebServerRequest *request)
|
||||
{
|
||||
showHidden = true;
|
||||
}
|
||||
DynamicJsonDocument jsonBuffer(4096);
|
||||
JsonArray networks = jsonBuffer.createNestedArray("networks");
|
||||
int n = WiFi.scanNetworks(false, showHidden);
|
||||
if (n != 0)
|
||||
AsyncJsonResponse *response = new AsyncJsonResponse();
|
||||
JsonArray networks = response->getRoot().createNestedArray("networks");
|
||||
int n = WiFi.scanComplete();
|
||||
if (n == -2)
|
||||
{
|
||||
//Scan not triggered
|
||||
WiFi.scanNetworks(true, showHidden);
|
||||
}
|
||||
else if (n)
|
||||
{
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
@@ -507,12 +432,16 @@ void WifiScanGet(AsyncWebServerRequest *request)
|
||||
network["rssi"] = WiFi.RSSI(i);
|
||||
network["chan"] = WiFi.channel(i);
|
||||
network["encrypt"] = translateEncryptionType(WiFi.encryptionType(i));
|
||||
network["hidden"] = String(WiFi.isHidden(i) ? "true" : "false");
|
||||
}
|
||||
WiFi.scanDelete();
|
||||
if (WiFi.scanComplete() == -2)
|
||||
{
|
||||
WiFi.scanNetworks(true, showHidden);
|
||||
}
|
||||
}
|
||||
String JSONmessageBuffer;
|
||||
//Serial.println(jsonBuffer.memoryUsage());
|
||||
serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
request->send(200, "application/json", JSONmessageBuffer);
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -522,12 +451,55 @@ void WifiScanGet(AsyncWebServerRequest *request)
|
||||
}
|
||||
}
|
||||
|
||||
//--------------- Clear -------------------------------
|
||||
volatile bool clearEepromFlag = false;
|
||||
void ClearPost(AsyncWebServerRequest *request)
|
||||
{
|
||||
if (isAuthenticated(request))
|
||||
{
|
||||
digitalWrite(LED_RED, LOW);
|
||||
//defaultEeprom();
|
||||
//Serial.println("Clear post");
|
||||
//TODO clear eeprom
|
||||
//request->redirect("/index.html");
|
||||
request->send(200, F("text/html"), F("<META http-equiv='refresh' content='10;URL=/'>Clearing eeprom.................."));
|
||||
clearEepromFlag = true;
|
||||
digitalWrite(LED_RED, HIGH);
|
||||
}
|
||||
}
|
||||
bool needsClearEeprom()
|
||||
{
|
||||
return clearEepromFlag;
|
||||
}
|
||||
|
||||
//--------------- reboot -------------------------------
|
||||
volatile bool rebootFlag = false;
|
||||
void RebootPost(AsyncWebServerRequest *request)
|
||||
{
|
||||
if (isAuthenticated(request))
|
||||
{
|
||||
request->send(200, F("text/html"), F("<META http-equiv='refresh' content='10;URL=/'>Rebooting.................."));
|
||||
rebootFlag = true;
|
||||
//delay(500); //time to send data to browser
|
||||
//WiFi.disconnect();
|
||||
//ESP.restart();
|
||||
}
|
||||
}
|
||||
bool needsRebooting()
|
||||
{
|
||||
return rebootFlag;
|
||||
}
|
||||
|
||||
//--------------- Server setup -------------------------------
|
||||
void setupAsyncWebserver()
|
||||
{
|
||||
//serve all filesystem files
|
||||
asyncServer.serveStatic("/", LittleFS, "/").setDefaultFile("index.html").setAuthentication(getEeprom()->www_username, getEeprom()->www_password);
|
||||
|
||||
asyncServer.on("/favicon.ico", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
request->send(LittleFS, "/favicon.ico", F("image/x-icon"));
|
||||
});
|
||||
|
||||
asyncServer.on("/liveinfo", HTTP_GET, [](AsyncWebServerRequest *request) { LiveInfoGet(request); });
|
||||
asyncServer.on("/info", HTTP_GET, [](AsyncWebServerRequest *request) { InfoGet(request); });
|
||||
asyncServer.on("/serialnumber", HTTP_POST, [](AsyncWebServerRequest *request) { ConfigPost(request); });
|
||||
@@ -545,14 +517,24 @@ void setupAsyncWebserver()
|
||||
asyncServer.on("/credentials", HTTP_POST, [](AsyncWebServerRequest *request) { CredentialsPost(request); });
|
||||
|
||||
asyncServer.on("/wifi", HTTP_GET, [](AsyncWebServerRequest *request) { WifiGet(request); });
|
||||
asyncServer.on("/wifi", HTTP_GET, [](AsyncWebServerRequest *request) { WifiPost(request); });
|
||||
asyncServer.on("/wifiscan", HTTP_POST, [](AsyncWebServerRequest *request) { WifiScanGet(request); });
|
||||
|
||||
// server.on("/clear", HTTP_POST, handleClearPost);
|
||||
asyncServer.on("/wifi", HTTP_POST, [](AsyncWebServerRequest *request) { WifiPost(request); });
|
||||
asyncServer.on("/wifiscan", HTTP_GET, [](AsyncWebServerRequest *request) { WifiScanGet(request); });
|
||||
|
||||
// server.on("/reboot", HTTP_POST, handleRebootPost);
|
||||
asyncServer.on("/clear", HTTP_POST, [](AsyncWebServerRequest *request) { ClearPost(request); });
|
||||
asyncServer.on("/reboot", HTTP_POST, [](AsyncWebServerRequest *request) { RebootPost(request); });
|
||||
|
||||
asyncServer.onNotFound(notFound);
|
||||
|
||||
asyncServer.begin();
|
||||
}
|
||||
|
||||
void setupSSDPWebServer()
|
||||
{
|
||||
asyncServer.on("/description.xml", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
StreamString output;
|
||||
SSDP.schema(output);
|
||||
output.remove(0, 94); //remove headers ... Hack
|
||||
request->send(200, "text/xml", (String)output);
|
||||
//Serial.print((String)output);
|
||||
});
|
||||
}
|
||||
@@ -2,5 +2,9 @@
|
||||
#define ASYNCWEBSERVER_H
|
||||
|
||||
void setupAsyncWebserver(void);
|
||||
void setupSSDPWebServer(void);
|
||||
|
||||
bool needsClearEeprom(void);
|
||||
bool needsRebooting(void);
|
||||
|
||||
#endif
|
||||
@@ -4,12 +4,6 @@
|
||||
|
||||
eepromStruct_t eepromStruct;
|
||||
|
||||
void startEeprom()
|
||||
{
|
||||
EEPROM.begin(512);
|
||||
checkEeprom();
|
||||
}
|
||||
|
||||
//Read eeprom check for empty eeprom
|
||||
void checkEeprom()
|
||||
{
|
||||
@@ -154,6 +148,12 @@ void checkEeprom()
|
||||
}
|
||||
}
|
||||
|
||||
void startEeprom()
|
||||
{
|
||||
EEPROM.begin(512);
|
||||
checkEeprom();
|
||||
}
|
||||
|
||||
void storeApMode(bool state)
|
||||
{
|
||||
//AP mode activation
|
||||
@@ -185,4 +185,15 @@ bool saveEeprom()
|
||||
{
|
||||
EEPROM.put(EEPROMSTRUCT_OFFSET, eepromStruct);
|
||||
return EEPROM.commit();
|
||||
}
|
||||
|
||||
void clearEeprom()
|
||||
{
|
||||
// write a 0 to all 512 bytes of the EEPROM
|
||||
for (int i = 0; i < 512; i++)
|
||||
{
|
||||
EEPROM.write(i, 0xFF);
|
||||
yield();
|
||||
}
|
||||
EEPROM.commit();
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
#define EEPROMSTRUCT_OFFSET 0
|
||||
|
||||
void startEeprom(void);
|
||||
void checkEeprom(void);
|
||||
void storeApMode(bool state);
|
||||
|
||||
typedef struct {
|
||||
@@ -34,11 +33,10 @@ typedef struct {
|
||||
bool use_llmnr;
|
||||
} eepromStruct_t;
|
||||
|
||||
extern eepromStruct_t eepromStruct;
|
||||
|
||||
eepromStruct_t *getEeprom(void);
|
||||
channel_t *getEepromChannel(int channel);
|
||||
bool anyChannelEnabled(void);
|
||||
bool saveEeprom(void);
|
||||
void clearEeprom(void);
|
||||
|
||||
#endif
|
||||
@@ -52,3 +52,18 @@ void detachInputInterrupt(int pin)
|
||||
{
|
||||
detachInterrupt(inputTable[pin]);
|
||||
}
|
||||
|
||||
/**
|
||||
* if gpio input has changed
|
||||
* @return true input has changed,
|
||||
* false nothing has changed
|
||||
*/
|
||||
boolean isInputChanged()
|
||||
{
|
||||
return inputChangedFlag;
|
||||
}
|
||||
|
||||
void lowerInputFlag()
|
||||
{
|
||||
inputChangedFlag = false;
|
||||
}
|
||||
@@ -1,17 +1,10 @@
|
||||
#ifndef INTERRUPTS_H
|
||||
#define INTERRUPTS_H
|
||||
|
||||
//#include <ESP8266WiFi.h>
|
||||
|
||||
//void ICACHE_RAM_ATTR pinChangedInput1();
|
||||
//void ICACHE_RAM_ATTR pinChangedInput2();
|
||||
//void ICACHE_RAM_ATTR pinChangedInput3();
|
||||
//void ICACHE_RAM_ATTR pinChangedInput4();
|
||||
|
||||
void attachInputInterrupt(int pin);
|
||||
void detachInputInterrupt(int pin);
|
||||
|
||||
//volatile boolean inputChangedFlag = false;
|
||||
extern volatile boolean inputChangedFlag;
|
||||
boolean isInputChanged(void);
|
||||
void lowerInputFlag(void);
|
||||
|
||||
#endif
|
||||
97
src/main.cpp
97
src/main.cpp
@@ -8,14 +8,8 @@
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <ESP8266HTTPUpdateServer.h>
|
||||
//#include <ESP8266SSDP.h>
|
||||
//#include <ESP8266LLMNR.h>
|
||||
//#include <ESP8266mDNS.h>
|
||||
#include <ESP8266httpUpdate.h>
|
||||
//#include <ESPAsyncTCP.h> //https://github.com/me-no-dev/ESPAsyncTCP
|
||||
//#include <ESPAsyncWebServer.h> //https://github.com/me-no-dev/ESPAsyncWebServer
|
||||
#include "h1602_eeprom.h"
|
||||
//#include "webserver.h"
|
||||
#include "nodered.h"
|
||||
#include "prtg.h"
|
||||
#include "pins.h"
|
||||
@@ -127,9 +121,7 @@ void setup()
|
||||
}
|
||||
|
||||
startEeprom();
|
||||
//setupServerPaths();
|
||||
setupAsyncWebserver();
|
||||
//setupAsyncWebserver();
|
||||
setupSSDP();
|
||||
|
||||
uint8_t MAC_array[6];
|
||||
@@ -150,22 +142,6 @@ void setup()
|
||||
if (getEeprom()->channel[i].enable == true)
|
||||
{
|
||||
attachInputInterrupt(i);
|
||||
|
||||
// switch (i)
|
||||
// {
|
||||
// case 1:
|
||||
// attachInterrupt(inputTable[i], pinChangedInput1, CHANGE);
|
||||
// break;
|
||||
// case 2:
|
||||
// attachInterrupt(inputTable[i], pinChangedInput2, CHANGE);
|
||||
// break;
|
||||
// case 3:
|
||||
// attachInterrupt(inputTable[i], pinChangedInput3, CHANGE);
|
||||
// break;
|
||||
// case 4:
|
||||
// attachInterrupt(inputTable[i], pinChangedInput4, CHANGE);
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,16 +158,10 @@ void setup()
|
||||
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
|
||||
WiFi.softAP("H1602R10");
|
||||
|
||||
dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
|
||||
// if DNSServer is started with "*" for domain name, it will reply with provided IP to all DNS request
|
||||
dnsServer.start(DNS_PORT, "*", apIP);
|
||||
|
||||
// replay to all requests with same HTML
|
||||
// server.onNotFound([]() {
|
||||
// server.send(200, "text/html", responseHTML);
|
||||
// //handleServerRequest("/index.html");
|
||||
// });
|
||||
// server.begin();
|
||||
|
||||
|
||||
//Deactivate AP mode bool
|
||||
storeApMode(false);
|
||||
|
||||
@@ -203,7 +173,6 @@ void setup()
|
||||
while (1)
|
||||
{
|
||||
//only config webserver, fast flashing green led
|
||||
//server.handleClient();
|
||||
dnsServer.processNextRequest();
|
||||
if (ledCounter == 20000)
|
||||
{
|
||||
@@ -214,42 +183,15 @@ void setup()
|
||||
uptime_update();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Normal mode
|
||||
connectWifi();
|
||||
}
|
||||
|
||||
//server.onNotFound(handleNotFound);
|
||||
|
||||
//httpUpdater.setup(&server, update_path, getEeprom()->www_username, getEeprom()->www_password);
|
||||
//server.begin();
|
||||
|
||||
connectWifi();
|
||||
startLLMNR();
|
||||
startMDNS();
|
||||
startSSDP();
|
||||
|
||||
startSendTimer();
|
||||
//Timer interrupt
|
||||
//if (eepromStruct.updateTime != 0)
|
||||
// if (getEeprom()->updateTime != 0)
|
||||
// {
|
||||
// //sendTimer.attach(eepromStruct.updateTime, tickerChanged);
|
||||
// attachSendTimer(getEeprom()->updateTime);
|
||||
// }
|
||||
|
||||
//if (eepromStruct.channel[1].enable == false && eepromStruct.channel[2].enable == false && eepromStruct.channel[3].enable == false && eepromStruct.channel[4].enable == false)
|
||||
// if (getEepromChannel(1)->enable == false && getEepromChannel(2)->enable == false && getEepromChannel(3)->enable == false && getEepromChannel(4)->enable == false)
|
||||
// {
|
||||
// detachSendTimer();
|
||||
// }
|
||||
// if (!anyChannelEnabled())
|
||||
// {
|
||||
// detachSendTimer();
|
||||
// }
|
||||
|
||||
//Vertsuur meteen de eerste status
|
||||
timerRaisedFlag = true;
|
||||
raiseTimerFlag();
|
||||
|
||||
digitalWrite(LED_RED, HIGH);
|
||||
|
||||
@@ -262,18 +204,30 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
//server.handleClient();
|
||||
uptime_update();
|
||||
updateMDNS();
|
||||
checkApButton(65534);
|
||||
|
||||
if (needsRebooting())
|
||||
{
|
||||
delay(500); //time to send data to browser
|
||||
WiFi.disconnect();
|
||||
ESP.restart();
|
||||
}
|
||||
if (needsClearEeprom())
|
||||
{
|
||||
clearEeprom();
|
||||
WiFi.disconnect();
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED)
|
||||
{
|
||||
// er is wifi verbinding
|
||||
|
||||
// input event
|
||||
if (inputChangedFlag == true)
|
||||
if (isInputChanged())
|
||||
{
|
||||
inputChangedFlag = false;
|
||||
lowerInputFlag();
|
||||
digitalWrite(LED_RED, LOW);
|
||||
|
||||
if (getEeprom()->use_nodered == true)
|
||||
@@ -285,13 +239,12 @@ void loop()
|
||||
prtgServerUpdate();
|
||||
}
|
||||
digitalWrite(LED_RED, HIGH);
|
||||
//inputChangedFlag = false;
|
||||
}
|
||||
|
||||
//timer event
|
||||
if (timerRaisedFlag == true)
|
||||
if (isTimerFlagRaised())
|
||||
{
|
||||
timerRaisedFlag = false;
|
||||
lowerTimerFlag();
|
||||
digitalWrite(LED_RED, LOW);
|
||||
|
||||
if (getEeprom()->use_nodered == true)
|
||||
@@ -303,11 +256,7 @@ void loop()
|
||||
prtgServerUpdate();
|
||||
}
|
||||
digitalWrite(LED_RED, HIGH);
|
||||
//timerRaisedFlag = false;
|
||||
}
|
||||
|
||||
//check AP button
|
||||
checkApButton(65534);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -315,6 +264,6 @@ void loop()
|
||||
digitalWrite(LED_RED, LOW);
|
||||
connectWifi();
|
||||
digitalWrite(LED_RED, HIGH);
|
||||
timerRaisedFlag = true;
|
||||
raiseTimerFlag();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,11 @@
|
||||
#include <ESP8266httpUpdate.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <ESP8266SSDP.h>
|
||||
#include <ESP8266SSDP.h>
|
||||
#include <ESP8266LLMNR.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include "global.h"
|
||||
#include "h1602_eeprom.h"
|
||||
//#include "webserver.h"
|
||||
#include "asyncWebserver.h"
|
||||
|
||||
void setupSSDP()
|
||||
{
|
||||
@@ -17,10 +16,7 @@ void setupSSDP()
|
||||
#ifdef DEBUG_MSG
|
||||
Serial.printf("Setting up SSDP...\n");
|
||||
#endif
|
||||
// server.on("/description.xml", HTTP_GET, []() {
|
||||
// SSDP.schema(server.client());
|
||||
// });
|
||||
|
||||
setupSSDPWebServer();
|
||||
|
||||
//SSDP.setTTL(5);
|
||||
//SSDP.setInterval(60);
|
||||
@@ -28,7 +24,7 @@ void setupSSDP()
|
||||
SSDP.setSchemaURL("description.xml");
|
||||
SSDP.setHTTPPort(80);
|
||||
SSDP.setName(getEeprom()->device);
|
||||
SSDP.setSerialNumber(String(ESP.getChipId(), DEC));
|
||||
SSDP.setSerialNumber(getEeprom()->serialnumber);
|
||||
SSDP.setURL("/");
|
||||
SSDP.setModelName("H1602R10");
|
||||
String modelNumber = "H1602R10 Release ";
|
||||
@@ -80,4 +76,4 @@ void updateMDNS()
|
||||
{
|
||||
MDNS.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,16 +11,41 @@ Ticker ledFlashTimer;
|
||||
|
||||
volatile boolean timerRaisedFlag = false;
|
||||
|
||||
// Ticker overflow
|
||||
void ICACHE_RAM_ATTR tickerChanged()
|
||||
//------ Send timer --------
|
||||
void ICACHE_RAM_ATTR sendTimerChanged()
|
||||
{
|
||||
timerRaisedFlag = true;
|
||||
}
|
||||
|
||||
//Led flash timer
|
||||
void startSendTimer()
|
||||
{
|
||||
if (getEeprom()->updateTime != 0)
|
||||
{
|
||||
sendTimer.attach(getEeprom()->updateTime, sendTimerChanged);
|
||||
}
|
||||
if (!anyChannelEnabled())
|
||||
{
|
||||
sendTimer.detach();
|
||||
}
|
||||
}
|
||||
|
||||
boolean isTimerFlagRaised()
|
||||
{
|
||||
return timerRaisedFlag;
|
||||
}
|
||||
|
||||
void raiseTimerFlag()
|
||||
{
|
||||
timerRaisedFlag = true;
|
||||
}
|
||||
void lowerTimerFlag()
|
||||
{
|
||||
timerRaisedFlag = false;
|
||||
}
|
||||
|
||||
//------ LED timer --------
|
||||
void ICACHE_RAM_ATTR ledFlashChanged()
|
||||
{
|
||||
//if (eepromStruct.apMode == true)
|
||||
if (getEeprom()->apMode == true)
|
||||
{
|
||||
digitalWrite(LED_GREEN, LOW);
|
||||
@@ -36,30 +61,6 @@ void ICACHE_RAM_ATTR ledFlashChanged()
|
||||
}
|
||||
}
|
||||
|
||||
void startSendTimer()
|
||||
{
|
||||
if (getEeprom()->updateTime != 0)
|
||||
{
|
||||
//attachSendTimer(getEeprom()->updateTime);
|
||||
sendTimer.attach(getEeprom()->updateTime, tickerChanged);
|
||||
}
|
||||
if (!anyChannelEnabled())
|
||||
{
|
||||
//detachSendTimer();
|
||||
sendTimer.detach();
|
||||
}
|
||||
}
|
||||
|
||||
// void detachSendTimer()
|
||||
// {
|
||||
// sendTimer.detach();
|
||||
// }
|
||||
|
||||
// void attachSendTimer(uint32_t time)
|
||||
// {
|
||||
// sendTimer.attach(time, tickerChanged);
|
||||
// }
|
||||
|
||||
void detachLedFlashTimer()
|
||||
{
|
||||
ledFlashTimer.detach();
|
||||
@@ -69,9 +70,4 @@ void attachLedFlashTimer_ms(uint32_t time)
|
||||
{
|
||||
//ledFlashTimer.attach(time, ledFlashChanged);
|
||||
ledFlashTimer.attach_ms(750, ledFlashChanged);
|
||||
}
|
||||
|
||||
boolean isTimerFlagRaised()
|
||||
{
|
||||
return timerRaisedFlag;
|
||||
}
|
||||
@@ -2,14 +2,11 @@
|
||||
#define TIMERS_H
|
||||
|
||||
void startSendTimer(void);
|
||||
//void detachSendTimer();
|
||||
//void attachSendTimer(uint32_t time);
|
||||
boolean isTimerFlagRaised();
|
||||
void raiseTimerFlag(void);
|
||||
void lowerTimerFlag(void);
|
||||
|
||||
void detachLedFlashTimer();
|
||||
void attachLedFlashTimer_ms(uint32_t time);
|
||||
|
||||
boolean isTimerFlagRaised();
|
||||
|
||||
extern volatile boolean timerRaisedFlag;
|
||||
|
||||
#endif
|
||||
@@ -1,806 +0,0 @@
|
||||
#include <FS.h>
|
||||
#include <LittleFS.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
//#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <ESP8266HTTPUpdateServer.h>
|
||||
//#include <ESP8266SSDP.h>
|
||||
//#include <ESP8266LLMNR.h>
|
||||
//#include <ESP8266mDNS.h>
|
||||
#include <ArduinoJson.h> //https://arduinojson.org/
|
||||
//#include <ESP8266httpUpdate.h>
|
||||
//#include <Ticker.h>
|
||||
#include <EEPROM.h>
|
||||
#include "pins.h"
|
||||
#include "h1602_eeprom.h"
|
||||
#include "global.h"
|
||||
#include "interrupts.h"
|
||||
#include "timers.h"
|
||||
#include "webserver.h"
|
||||
|
||||
ESP8266WebServer server(80);
|
||||
ESP8266HTTPUpdateServer httpUpdater;
|
||||
|
||||
boolean isAuthenticated()
|
||||
{
|
||||
return !server.authenticate(getEeprom()->www_username, getEeprom()->www_password);
|
||||
|
||||
// if (!server.authenticate(getEeprom()->www_username, getEeprom()->www_password))
|
||||
// {
|
||||
// server.requestAuthentication();
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
}
|
||||
|
||||
void handleNotFound()
|
||||
{
|
||||
//if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
if (isAuthenticated())
|
||||
{
|
||||
return server.requestAuthentication();
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(LED_RED, LOW);
|
||||
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);
|
||||
digitalWrite(LED_RED, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
void sendPlainError()
|
||||
{
|
||||
server.send(200, "text/plain", "I'm sorry Dave, I'm afraid I can't do that");
|
||||
}
|
||||
|
||||
//////////////////////// LittleFS File webserver ////////////////////////////////////////////////
|
||||
|
||||
String getContentType(String filename)
|
||||
{
|
||||
if (server.hasArg("download"))
|
||||
return "application/octet-stream";
|
||||
else if (filename.endsWith(".htm"))
|
||||
return "text/html";
|
||||
else if (filename.endsWith(".html"))
|
||||
return "text/html";
|
||||
else if (filename.endsWith(".css"))
|
||||
return "text/css";
|
||||
else if (filename.endsWith(".js"))
|
||||
return "application/javascript";
|
||||
else if (filename.endsWith(".png"))
|
||||
return "image/png";
|
||||
else if (filename.endsWith(".gif"))
|
||||
return "image/gif";
|
||||
else if (filename.endsWith(".jpg"))
|
||||
return "image/jpeg";
|
||||
else if (filename.endsWith(".ico"))
|
||||
return "image/x-icon";
|
||||
else if (filename.endsWith(".xml"))
|
||||
return "text/xml";
|
||||
else if (filename.endsWith(".pdf"))
|
||||
return "application/x-pdf";
|
||||
else if (filename.endsWith(".zip"))
|
||||
return "application/x-zip";
|
||||
else if (filename.endsWith(".gz"))
|
||||
return "application/x-gzip";
|
||||
return "text/plain";
|
||||
}
|
||||
|
||||
bool handleFileRead(String path)
|
||||
{
|
||||
if (path.endsWith("/"))
|
||||
path += "index.htm";
|
||||
String contentType = getContentType(path);
|
||||
String pathWithGz = path + ".gz";
|
||||
if (LittleFS.exists(pathWithGz) || LittleFS.exists(path))
|
||||
{
|
||||
if (LittleFS.exists(pathWithGz))
|
||||
path += ".gz";
|
||||
File file = LittleFS.open(path, "r");
|
||||
//size_t sent = server.streamFile(file, contentType);
|
||||
server.streamFile(file, contentType);
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void handleServerRequest(String path)
|
||||
{
|
||||
digitalWrite(LED_RED, LOW);
|
||||
if (isAuthenticated())
|
||||
{
|
||||
return server.requestAuthentication();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!handleFileRead(path))
|
||||
handleNotFound();
|
||||
}
|
||||
digitalWrite(LED_RED, HIGH);
|
||||
}
|
||||
|
||||
//////////////////////// Webserver ////////////////////////////////////////////////
|
||||
|
||||
// *************** Webserver Functions *****************************
|
||||
|
||||
//--------------- LiveInfo -------------------------------
|
||||
// void handleLiveInfoGet()
|
||||
// {
|
||||
// //if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
// if (isAuthenticated())
|
||||
// {
|
||||
// return server.requestAuthentication();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitalWrite(LED_RED, LOW);
|
||||
// if (server.args() == 0)
|
||||
// {
|
||||
// DynamicJsonDocument jsonBuffer(192);
|
||||
// jsonBuffer["rssi"] = WiFi.RSSI();
|
||||
// jsonBuffer["uptimeDay"] = uptime.Day;
|
||||
// jsonBuffer["uptimeHour"] = uptime.Hour;
|
||||
// jsonBuffer["uptimeMinute"] = uptime.Minute;
|
||||
// jsonBuffer["uptimeSecond"] = uptime.Second;
|
||||
// jsonBuffer["free"] = ESP.getFreeHeap();
|
||||
// jsonBuffer["max"] = ESP.getMaxFreeBlockSize();
|
||||
// jsonBuffer["heap"] = ESP.getHeapFragmentation();
|
||||
// String JSONmessageBuffer;
|
||||
// //Serial.println(jsonBuffer.memoryUsage());
|
||||
// serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
// server.send(200, "application/json", JSONmessageBuffer);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sendPlainError();
|
||||
// }
|
||||
// digitalWrite(LED_RED, HIGH);
|
||||
// }
|
||||
// }
|
||||
|
||||
//--------------- Info -------------------------------
|
||||
// void handleInfoGet()
|
||||
// {
|
||||
// //if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
// if (isAuthenticated())
|
||||
// {
|
||||
// return server.requestAuthentication();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitalWrite(LED_RED, LOW);
|
||||
// if (server.args() == 0)
|
||||
// {
|
||||
// DynamicJsonDocument jsonBuffer(512);
|
||||
// jsonBuffer["mac"] = MAC_char;
|
||||
// jsonBuffer["chipid"] = String(ESP.getChipId(), DEC);
|
||||
// jsonBuffer["version"] = softwareVersion;
|
||||
// jsonBuffer["sdkversion"] = String(ESP.getFullVersion());
|
||||
// String cmp = compileDate;
|
||||
// cmp += " , ";
|
||||
// cmp += compileTime;
|
||||
// jsonBuffer["compiledate"] = cmp;
|
||||
// jsonBuffer["vcc"] = (ESP.getVcc() / 1024.0f);
|
||||
// jsonBuffer["ipaddress"] = WiFi.localIP().toString();
|
||||
// jsonBuffer["subnet"] = WiFi.subnetMask().toString();
|
||||
// jsonBuffer["gateway"] = WiFi.gatewayIP().toString();
|
||||
// jsonBuffer["dns"] = WiFi.dnsIP().toString();
|
||||
// jsonBuffer["serialnumber"] = eepromStruct.serialnumber;
|
||||
// jsonBuffer["isSerialSet"] = eepromStruct.isSerialSet;
|
||||
|
||||
// String JSONmessageBuffer;
|
||||
// //Serial.println(jsonBuffer.memoryUsage());
|
||||
// serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
// server.send(200, "application/json", JSONmessageBuffer);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sendPlainError();
|
||||
// }
|
||||
// digitalWrite(LED_RED, HIGH);
|
||||
// }
|
||||
// }
|
||||
|
||||
//--------------- Serial Number -------------------------------
|
||||
// void handleSerialNumberPost()
|
||||
// {
|
||||
// //if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
// if (isAuthenticated())
|
||||
// {
|
||||
// return server.requestAuthentication();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitalWrite(LED_RED, LOW);
|
||||
// if (server.args() != 0)
|
||||
// {
|
||||
// server.arg("serialnumber").toCharArray(eepromStruct.serialnumber, sizeof(eepromStruct.serialnumber) - 1);
|
||||
// if (strlen(eepromStruct.serialnumber) > 0)
|
||||
// {
|
||||
// eepromStruct.isSerialSet = true;
|
||||
// }
|
||||
// EEPROM.put(EEPROMSTRUCT_OFFSET, eepromStruct);
|
||||
// EEPROM.commit();
|
||||
// }
|
||||
// handleServerRequest("/index.html");
|
||||
// digitalWrite(LED_RED, HIGH);
|
||||
// }
|
||||
// }
|
||||
|
||||
// //--------------- Access point -------------------------------
|
||||
// void handleAccesspointGet()
|
||||
// {
|
||||
// //if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
// if (isAuthenticated())
|
||||
// {
|
||||
// return server.requestAuthentication();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitalWrite(LED_RED, LOW);
|
||||
// if (server.args() == 0)
|
||||
// {
|
||||
// DynamicJsonDocument jsonBuffer(24);
|
||||
// jsonBuffer["apMode"] = eepromStruct.apMode;
|
||||
// String JSONmessageBuffer;
|
||||
// Serial.println(jsonBuffer.memoryUsage());
|
||||
// serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
// server.send(200, "application/json", JSONmessageBuffer);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sendPlainError();
|
||||
// }
|
||||
// digitalWrite(LED_RED, HIGH);
|
||||
// }
|
||||
// }
|
||||
// void handleAccesspointPost()
|
||||
// {
|
||||
// //if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
// if (isAuthenticated())
|
||||
// {
|
||||
// return server.requestAuthentication();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitalWrite(LED_RED, LOW);
|
||||
// if (server.args() == 1)
|
||||
// {
|
||||
// StaticJsonDocument<32> doc;
|
||||
// DeserializationError error = deserializeJson(doc, server.arg("plain"));
|
||||
// if (error)
|
||||
// {
|
||||
// Serial.print(F("deserializeJson() failed: "));
|
||||
// Serial.println(error.c_str());
|
||||
// return;
|
||||
// }
|
||||
// eepromStruct.apMode = doc["apMode"];
|
||||
// EEPROM.put(EEPROMSTRUCT_OFFSET, eepromStruct);
|
||||
// EEPROM.commit();
|
||||
|
||||
// server.send(200, "application/json");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sendPlainError();
|
||||
// }
|
||||
// digitalWrite(LED_RED, HIGH);
|
||||
// }
|
||||
// }
|
||||
|
||||
//--------------- Config -------------------------------
|
||||
// void handleConfigGet()
|
||||
// {
|
||||
// //if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
// if (isAuthenticated())
|
||||
// {
|
||||
// return server.requestAuthentication();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitalWrite(LED_RED, LOW);
|
||||
// if (server.args() == 0)
|
||||
// {
|
||||
// DynamicJsonDocument jsonBuffer(256);
|
||||
// jsonBuffer["device"] = eepromStruct.device;
|
||||
// jsonBuffer["useprtg"] = eepromStruct.use_prtg;
|
||||
// jsonBuffer["usenodered"] = eepromStruct.use_nodered;
|
||||
// jsonBuffer["noderedserver"] = eepromStruct.noderedHost;
|
||||
// jsonBuffer["noderedurl"] = eepromStruct.noderedUrl;
|
||||
// jsonBuffer["prtgserver"] = eepromStruct.prtgHost;
|
||||
// jsonBuffer["prtgport"] = eepromStruct.prtgHttpPort;
|
||||
// jsonBuffer["update"] = eepromStruct.updateTime;
|
||||
// String JSONmessageBuffer;
|
||||
// //Serial.println(jsonBuffer.memoryUsage());
|
||||
// serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
// server.send(200, "application/json", JSONmessageBuffer);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sendPlainError();
|
||||
// }
|
||||
// digitalWrite(LED_RED, HIGH);
|
||||
// }
|
||||
// }
|
||||
// void handleConfigPost()
|
||||
// {
|
||||
// //if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
// if (isAuthenticated())
|
||||
// {
|
||||
// return server.requestAuthentication();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitalWrite(LED_RED, LOW);
|
||||
// if (server.args() != 0)
|
||||
// {
|
||||
// server.arg("device").toCharArray(eepromStruct.device, sizeof(eepromStruct.device) - 1);
|
||||
// eepromStruct.use_nodered = server.hasArg("usenodered") ? true : false;
|
||||
// server.arg("noderedserver").toCharArray(eepromStruct.noderedHost, sizeof(eepromStruct.noderedHost) - 1);
|
||||
// server.arg("noderedurl").toCharArray(eepromStruct.noderedUrl, sizeof(eepromStruct.noderedUrl) - 1);
|
||||
// eepromStruct.use_prtg = server.hasArg("useprtg") ? true : false;
|
||||
// server.arg("prtgserver").toCharArray(eepromStruct.prtgHost, sizeof(eepromStruct.prtgHost) - 1);
|
||||
// eepromStruct.prtgHttpPort = server.arg("prtgport").toInt();
|
||||
// eepromStruct.updateTime = server.arg("update").toInt();
|
||||
// if (eepromStruct.updateTime == 0)
|
||||
// {
|
||||
// //sendTimer.detach();
|
||||
// detachSendTimer();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //sendTimer.attach(eepromStruct.updateTime, tickerChanged);
|
||||
// attachSendTimer(eepromStruct.updateTime);
|
||||
// }
|
||||
|
||||
// EEPROM.put(EEPROMSTRUCT_OFFSET, eepromStruct);
|
||||
// EEPROM.commit();
|
||||
// }
|
||||
// handleServerRequest("/config.html");
|
||||
// digitalWrite(LED_RED, HIGH);
|
||||
// }
|
||||
// }
|
||||
|
||||
// //--------------- Inputs -------------------------------
|
||||
// void handleInputsGet()
|
||||
// {
|
||||
// //if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
// if (isAuthenticated())
|
||||
// {
|
||||
// return server.requestAuthentication();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitalWrite(LED_RED, LOW);
|
||||
// if (server.args() != 0)
|
||||
// {
|
||||
// if (server.hasArg("settings"))
|
||||
// {
|
||||
|
||||
// DynamicJsonDocument jsonBuffer(256);
|
||||
// jsonBuffer["ch1Enabled"] = eepromStruct.channel[1].enable;
|
||||
// jsonBuffer["ch1Name"] = eepromStruct.channel[1].channel;
|
||||
// jsonBuffer["ch2Enabled"] = eepromStruct.channel[2].enable;
|
||||
// jsonBuffer["ch2Name"] = eepromStruct.channel[2].channel;
|
||||
// jsonBuffer["ch3Enabled"] = eepromStruct.channel[3].enable;
|
||||
// jsonBuffer["ch3Name"] = eepromStruct.channel[3].channel;
|
||||
// jsonBuffer["ch4Enabled"] = eepromStruct.channel[4].enable;
|
||||
// jsonBuffer["ch4Name"] = eepromStruct.channel[4].channel;
|
||||
|
||||
// String JSONmessageBuffer;
|
||||
// //Serial.println(jsonBuffer.memoryUsage());
|
||||
// serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
// server.send(200, "application/json", JSONmessageBuffer);
|
||||
// }
|
||||
// else if (server.hasArg("state"))
|
||||
// {
|
||||
// DynamicJsonDocument jsonBuffer(128);
|
||||
|
||||
// jsonBuffer["in1_state"] = !digitalRead(inputTable[1]);
|
||||
// jsonBuffer["in2_state"] = !digitalRead(inputTable[2]);
|
||||
// jsonBuffer["in3_state"] = !digitalRead(inputTable[3]);
|
||||
// jsonBuffer["in4_state"] = !digitalRead(inputTable[4]);
|
||||
// String JSONmessageBuffer;
|
||||
// //Serial.println(jsonBuffer.memoryUsage());
|
||||
// serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
// server.send(200, "application/json", JSONmessageBuffer);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sendPlainError();
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sendPlainError();
|
||||
// }
|
||||
// digitalWrite(LED_RED, HIGH);
|
||||
// }
|
||||
// }
|
||||
// void handleInputsPost()
|
||||
// {
|
||||
// //if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
// if (isAuthenticated())
|
||||
// {
|
||||
// return server.requestAuthentication();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitalWrite(LED_RED, LOW);
|
||||
// //Serial.println(server.args());
|
||||
|
||||
// if (server.args() != 0)
|
||||
// {
|
||||
// const char *enableTable[5] = {"", "en1", "en2", "en3", "en4"};
|
||||
// const char *channelTable[5] = {"", "ch1Name", "ch2Name", "ch3Name", "ch4Name"};
|
||||
|
||||
// for (int i = 1; i < 5; i++)
|
||||
// {
|
||||
// if (server.hasArg(enableTable[i]))
|
||||
// {
|
||||
// eepromStruct.channel[i].enable = true;
|
||||
// switch (i)
|
||||
// {
|
||||
// case 1:
|
||||
// attachInterrupt(inputTable[i], pinChangedInput1, CHANGE);
|
||||
// break;
|
||||
// case 2:
|
||||
// attachInterrupt(inputTable[i], pinChangedInput2, CHANGE);
|
||||
// break;
|
||||
// case 3:
|
||||
// attachInterrupt(inputTable[i], pinChangedInput3, CHANGE);
|
||||
// break;
|
||||
// case 4:
|
||||
// attachInterrupt(inputTable[i], pinChangedInput4, CHANGE);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// eepromStruct.channel[i].enable = false;
|
||||
// detachInterrupt(inputTable[i]);
|
||||
// }
|
||||
|
||||
// if (eepromStruct.channel[1].enable == false && eepromStruct.channel[2].enable == false && eepromStruct.channel[3].enable == false && eepromStruct.channel[4].enable == false)
|
||||
// {
|
||||
// //sendTimer.detach();
|
||||
// detachSendTimer();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //sendTimer.attach(eepromStruct.updateTime, tickerChanged);
|
||||
// attachSendTimer(eepromStruct.updateTime);
|
||||
// }
|
||||
// server.arg(channelTable[i]).toCharArray(eepromStruct.channel[i].channel, sizeof(eepromStruct.channel[i].channel) - 1);
|
||||
// }
|
||||
// EEPROM.put(EEPROMSTRUCT_OFFSET, eepromStruct);
|
||||
// EEPROM.commit();
|
||||
// }
|
||||
// handleServerRequest("/inputs.html");
|
||||
// digitalWrite(LED_RED, HIGH);
|
||||
// }
|
||||
// }
|
||||
|
||||
//--------------- Credentials -------------------------------
|
||||
// void handleCredentialsGet()
|
||||
// {
|
||||
// //if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
// if (isAuthenticated())
|
||||
// {
|
||||
// return server.requestAuthentication();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitalWrite(LED_RED, LOW);
|
||||
// if (server.args() == 0)
|
||||
// {
|
||||
// DynamicJsonDocument jsonBuffer(64);
|
||||
// jsonBuffer["username"] = eepromStruct.www_username;
|
||||
// jsonBuffer["password"] = eepromStruct.www_password;
|
||||
// String JSONmessageBuffer;
|
||||
// //Serial.println(jsonBuffer.memoryUsage());
|
||||
// serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
// server.send(200, "application/json", JSONmessageBuffer);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sendPlainError();
|
||||
// }
|
||||
// digitalWrite(LED_RED, HIGH);
|
||||
// }
|
||||
// }
|
||||
// void handleCredentialsPost()
|
||||
// {
|
||||
// if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
// {
|
||||
// return server.requestAuthentication();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitalWrite(LED_RED, LOW);
|
||||
// if (server.args() != 0)
|
||||
// {
|
||||
// server.arg("www_user").toCharArray(eepromStruct.www_username, sizeof(eepromStruct.www_username) - 1);
|
||||
// server.arg("www_pass").toCharArray(eepromStruct.www_password, sizeof(eepromStruct.www_password) - 1);
|
||||
|
||||
// EEPROM.put(EEPROMSTRUCT_OFFSET, eepromStruct);
|
||||
// EEPROM.commit();
|
||||
// }
|
||||
// handleServerRequest("/credentials.html");
|
||||
// digitalWrite(LED_RED, HIGH);
|
||||
// }
|
||||
// }
|
||||
|
||||
// //--------------- Wifi -------------------------------
|
||||
// void handleWifiGet()
|
||||
// {
|
||||
// //if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
// if (isAuthenticated())
|
||||
// {
|
||||
// return server.requestAuthentication();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitalWrite(LED_RED, LOW);
|
||||
// if (server.args() == 0)
|
||||
// {
|
||||
// DynamicJsonDocument jsonBuffer(128);
|
||||
// jsonBuffer["ssid"] = eepromStruct.ssid;
|
||||
// jsonBuffer["pass"] = eepromStruct.password;
|
||||
// jsonBuffer["ssdp"] = eepromStruct.ssdp;
|
||||
// jsonBuffer["mdns"] = eepromStruct.use_mdns;
|
||||
// jsonBuffer["llmnr"] = eepromStruct.use_llmnr;
|
||||
|
||||
// String JSONmessageBuffer;
|
||||
// //Serial.println(jsonBuffer.memoryUsage());
|
||||
// serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
// server.send(200, "application/json", JSONmessageBuffer);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sendPlainError();
|
||||
// }
|
||||
// digitalWrite(LED_RED, HIGH);
|
||||
// }
|
||||
// }
|
||||
// void handleWifiPost()
|
||||
// {
|
||||
// //if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
// if (isAuthenticated())
|
||||
// {
|
||||
// return server.requestAuthentication();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitalWrite(LED_RED, LOW);
|
||||
// if (server.args() != 0)
|
||||
// {
|
||||
// server.arg("ssid").toCharArray(eepromStruct.ssid, sizeof(eepromStruct.ssid) - 1);
|
||||
// server.arg("pass").toCharArray(eepromStruct.password, sizeof(eepromStruct.password) - 1);
|
||||
// eepromStruct.ssdp = server.hasArg("ssdp") ? true : false;
|
||||
|
||||
// eepromStruct.use_mdns = server.hasArg("mdns") ? true : false;
|
||||
// eepromStruct.use_llmnr = server.hasArg("llmnr") ? true : false;
|
||||
|
||||
// EEPROM.put(EEPROMSTRUCT_OFFSET, eepromStruct);
|
||||
// EEPROM.commit();
|
||||
// }
|
||||
// handleServerRequest("/wifi.html");
|
||||
// digitalWrite(LED_RED, HIGH);
|
||||
// }
|
||||
// }
|
||||
|
||||
// String translateEncryptionType(uint8_t type)
|
||||
// {
|
||||
// switch (type)
|
||||
// {
|
||||
// case (0):
|
||||
// return "Open";
|
||||
// case (1):
|
||||
// return "WEP";
|
||||
// case (2):
|
||||
// return "WPA_PSK";
|
||||
// case (3):
|
||||
// return "WPA2_PSK";
|
||||
// case (4):
|
||||
// return "WPA_WPA2_PSK";
|
||||
// case (5):
|
||||
// return "WPA2_ENTERPRISE";
|
||||
// default:
|
||||
// return "UNKOWN";
|
||||
// }
|
||||
// }
|
||||
// void handleWifiScanGet()
|
||||
// {
|
||||
// //if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
// if (isAuthenticated())
|
||||
// {
|
||||
// return server.requestAuthentication();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// digitalWrite(LED_RED, LOW);
|
||||
// if (server.args() == 1)
|
||||
// {
|
||||
// bool showHidden = false;
|
||||
// if (server.arg("hidden") == "true")
|
||||
// {
|
||||
// showHidden = true;
|
||||
// }
|
||||
// DynamicJsonDocument jsonBuffer(4096);
|
||||
// JsonArray networks = jsonBuffer.createNestedArray("networks");
|
||||
// int n = WiFi.scanNetworks(false, showHidden);
|
||||
// if (n != 0)
|
||||
// {
|
||||
// for (int i = 0; i < n; ++i)
|
||||
// {
|
||||
// JsonObject network = networks.createNestedObject();
|
||||
// network["ssid"] = WiFi.SSID(i);
|
||||
// network["rssi"] = WiFi.RSSI(i);
|
||||
// network["chan"] = WiFi.channel(i);
|
||||
// network["encrypt"] = translateEncryptionType(WiFi.encryptionType(i));
|
||||
// }
|
||||
// }
|
||||
// String JSONmessageBuffer;
|
||||
// //Serial.println(jsonBuffer.memoryUsage());
|
||||
// serializeJson(jsonBuffer, JSONmessageBuffer);
|
||||
// server.send(200, "application/json", JSONmessageBuffer);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sendPlainError();
|
||||
// }
|
||||
// digitalWrite(LED_RED, HIGH);
|
||||
// }
|
||||
// }
|
||||
|
||||
//--------------- Clear -------------------------------
|
||||
//handle clear request
|
||||
void handleClearPost()
|
||||
{
|
||||
//if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
if (isAuthenticated())
|
||||
{
|
||||
return server.requestAuthentication();
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(LED_RED, LOW);
|
||||
|
||||
// write a 0 to all 512 bytes of the EEPROM
|
||||
for (int i = 0; i < 512; i++)
|
||||
{
|
||||
EEPROM.write(i, 0xFF);
|
||||
yield();
|
||||
}
|
||||
EEPROM.commit();
|
||||
checkEeprom();
|
||||
|
||||
handleServerRequest("/index.html");
|
||||
digitalWrite(LED_RED, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------- reboot -------------------------------
|
||||
//handle reboot request
|
||||
void handleRebootPost()
|
||||
{
|
||||
//if (!server.authenticate(eepromStruct.www_username, eepromStruct.www_password))
|
||||
if (isAuthenticated())
|
||||
{
|
||||
return server.requestAuthentication();
|
||||
}
|
||||
else
|
||||
{
|
||||
server.send(200, "text/html", "<META http-equiv='refresh' content='10;URL=/'>Rebooting..................");
|
||||
delay(500); //time to send data to browser
|
||||
WiFi.disconnect();
|
||||
ESP.restart();
|
||||
}
|
||||
}
|
||||
|
||||
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Setup webserver paths %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
void setupServerPaths()
|
||||
{
|
||||
// server.on("/", HTTP_GET, []() {
|
||||
// handleServerRequest("/index.html");
|
||||
// });
|
||||
//server.on("/liveinfo", HTTP_GET, handleLiveInfoGet);
|
||||
//server.on("/info", HTTP_GET, handleInfoGet);
|
||||
//server.on("/serialnumber", HTTP_POST, handleSerialNumberPost);
|
||||
|
||||
// server.on("/accesspoint.html", HTTP_GET, []() {
|
||||
// handleServerRequest("/accesspoint.html");
|
||||
// });
|
||||
//server.on("/accesspoint", HTTP_GET, handleAccesspointGet);
|
||||
//server.on("/accesspoint", HTTP_POST, handleAccesspointPost);
|
||||
|
||||
// server.on("/config.html", HTTP_GET, []() {
|
||||
// handleServerRequest("/config.html");
|
||||
// });
|
||||
//server.on("/config", HTTP_GET, handleConfigGet);
|
||||
//server.on("/config", HTTP_POST, handleConfigPost);
|
||||
|
||||
// server.on("/clear.html", HTTP_GET, []() {
|
||||
// handleServerRequest("/clear.html");
|
||||
// });
|
||||
server.on("/clear", HTTP_POST, handleClearPost);
|
||||
|
||||
// server.on("/reboot.html", HTTP_GET, []() {
|
||||
// handleServerRequest("/reboot.html");
|
||||
// });
|
||||
server.on("/reboot", HTTP_POST, handleRebootPost);
|
||||
|
||||
// server.on("/help.html", HTTP_GET, []() {
|
||||
// handleServerRequest("/help.html");
|
||||
// });
|
||||
// server.on("/update.html", HTTP_GET, []() {
|
||||
// handleServerRequest("/update.html");
|
||||
// });
|
||||
|
||||
// server.on("/inputs.html", HTTP_GET, []() {
|
||||
// handleServerRequest("/inputs.html");
|
||||
// });
|
||||
//server.on("/inputs", HTTP_GET, handleInputsGet);
|
||||
//server.on("/inputs", HTTP_POST, handleInputsPost);
|
||||
|
||||
// server.on("/credentials.html", HTTP_GET, []() {
|
||||
// handleServerRequest("/credentials.html");
|
||||
// });
|
||||
//server.on("/credentials", HTTP_GET, handleCredentialsGet);
|
||||
//server.on("/credentials", HTTP_POST, handleCredentialsPost);
|
||||
|
||||
// server.on("/wifi.html", HTTP_GET, []() {
|
||||
// handleServerRequest("/wifi.html");
|
||||
// });
|
||||
//server.on("/wifi", HTTP_GET, handleWifiGet);
|
||||
//server.on("/wifi", HTTP_POST, handleWifiPost);
|
||||
//server.on("/wifiscan", HTTP_GET, handleWifiScanGet);
|
||||
|
||||
// CSS
|
||||
// server.on("/style.css", HTTP_GET, []() {
|
||||
// handleServerRequest("/style.css");
|
||||
// });
|
||||
// server.on("/Chart.min.css", HTTP_GET, []() {
|
||||
// handleServerRequest("/Chart.min.css");
|
||||
// });
|
||||
|
||||
// Javascript
|
||||
// server.on("/Chart.min.js", HTTP_GET, []() {
|
||||
// handleServerRequest("/Chart.min.js");
|
||||
// });
|
||||
// server.on("/wsen.js", HTTP_GET, []() {
|
||||
// handleServerRequest("/wsen.js");
|
||||
// });
|
||||
|
||||
// Images
|
||||
// server.on("/switch-closed.png", HTTP_GET, []() {
|
||||
// handleServerRequest("/switch-closed.png");
|
||||
// });
|
||||
// server.on("/switch-open.png", HTTP_GET, []() {
|
||||
// handleServerRequest("/switch-open.png");
|
||||
// });
|
||||
// server.on("/diode.png", HTTP_GET, []() {
|
||||
// handleServerRequest("/diode.png");
|
||||
// });
|
||||
// server.on("/diode-led.png", HTTP_GET, []() {
|
||||
// handleServerRequest("/diode-led.png");
|
||||
// });
|
||||
|
||||
//Not found
|
||||
server.onNotFound(handleNotFound);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef WEBSERVER_H
|
||||
#define WEBSERVER_H
|
||||
|
||||
//#include <ESP8266HTTPUpdateServer.h>
|
||||
|
||||
//void setupServerPaths();
|
||||
|
||||
//extern ESP8266WebServer server;
|
||||
//extern ESP8266HTTPUpdateServer httpUpdater;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user