25 #include <ESP8266WiFi.h>
26 #include <ESP8266WebServer.h>
27 #include <DNSServer.h>
38 : ESP8266WebServer(port) { }
40 WiFiClient &wifiClient() {
return _currentClient; }
60 static void AddTableTr (String &info, String name, String value);
62 static bool GetOption (String
id, String &option);
63 static bool GetOption (String
id,
long &option);
64 static bool GetOption (String
id,
double &option);
65 static bool GetOption (String
id,
bool &option);
66 static void AddBr (String &info);
67 static void AddOption (String &info, String
id, String name,
bool value,
bool addBr =
true);
68 static void AddOption (String &info, String
id, String name, String value,
bool addBr =
true,
bool isPassword =
false);
109 : isWebServerActive(false)
114 MyWebServer::~MyWebServer()
130 MyDbg(F(
"MyWebServer::begin"));
131 WiFi.persistent(
false);
132 WiFi.mode(WIFI_AP_STA);
134 WiFi.softAPConfig(
ip,
ip, IPAddress(255, 255, 255, 0));
135 dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
144 for (
int i = 0; i < 30 && WiFi.status() != WL_CONNECTED; i++) {
145 MyDbg(F(
"."),
true,
false);
149 if (WiFi.status() == WL_CONNECTED) {
177 MyDbg(F(
"Server listening"),
true);
195 info += F(
"<table style='width:100%'>");
201 info += F(
"<tr><th></th><td> </td></tr>");
209 info += (String) F(
"<th>") +
TextToXml(name) + F(
"</th>");
210 info += (String) F(
"<td>") +
TextToXml(value) + F(
"</td>");
218 info += F(
"</table>");
235 String opt =
server.arg(
id);
238 if (opt.indexOf(F(
":")) != -1) {
241 option = atoi(opt.c_str());
251 String opt =
server.arg(
id);
254 option = atof(opt.c_str());
263 String opt =
server.arg(
id);
267 if (opt == F(
"on")) {
284 info += (String) F(
"<b>") +
TextToXml(name) + F(
"</b>");
285 info += (String) F(
"<input id='") +
id + F(
"' name='") +
id + F(
"' ");
293 info += (String) F(
"value='") +
TextToXml(value) + F(
"'>");
302 info += F(
"<input style='width:auto;' id='");
304 info += F(
"' name='");
306 info += F(
"' type='checkbox' ");
307 info += value ? F(
" checked") : F(
"");
319 info += (String) F(
"<p>") +
TextToXml(F(
"Interval in '[days] hours:minutes:seconds' or just 'seconds'")) + F(
"</p>");
328 String dataType = F(
"text/plain");
329 if(path.endsWith(
"/")) path += F(
"index.htm");
331 if(path.endsWith(F(
".src"))) path = path.substring(0, path.lastIndexOf(
"."));
332 else if(path.endsWith(F(
".html"))) dataType = F(
"text/html");
333 else if(path.endsWith(F(
".htm"))) dataType = F(
"text/html");
334 else if(path.endsWith(F(
".css"))) dataType = F(
"text/css");
335 else if(path.endsWith(F(
".js"))) dataType = F(
"application/javascript");
336 else if(path.endsWith(F(
".png"))) dataType = F(
"image/png");
337 else if(path.endsWith(F(
".gif"))) dataType = F(
"image/gif");
338 else if(path.endsWith(F(
".jpg"))) dataType = F(
"image/jpeg");
339 else if(path.endsWith(F(
".ico"))) dataType = F(
"image/x-icon");
340 else if(path.endsWith(F(
".xml"))) dataType = F(
"text/xml");
341 else if(path.endsWith(F(
".pdf"))) dataType = F(
"application/pdf");
342 else if(path.endsWith(F(
".zip"))) dataType = F(
"application/zip");
344 File dataFile = SPIFFS.open(path.c_str(),
"r");
346 if (
server.hasArg(F(
"download"))) {
347 dataType = F(
"application/octet-stream");
349 if (
server.streamFile(dataFile, dataType) == dataFile.size()) {
360 server.sendHeader(F(
"Location"), F(
"Main.html"),
true);
361 server.send(302, F(
"text/plain"),
"");
381 String onOff =
server.arg(F(
"o"));
383 if (onOff == F(
"1")) {
392 #ifdef SIM808_CONNECTED
395 if (WiFi.status() != WL_CONNECTED) {
407 #ifndef SIM808_CONNECTED
426 #ifdef SIM808_CONNECTED
437 F(
"<table style='width:100%'>"
439 "<td style='width:100%'>"
440 "<div style='text-align:center;font-weight:bold;font-size:62px'>") +
447 server.send(200, F(
"text/html"), info);
486 MyDbg(F(
"LoadSettings"),
true);
492 #ifdef SIM808_CONNECTED
500 HtmlTag fieldset(info, F(
"fieldset"));
502 HtmlTag legend(info, F(
"legend"));
511 #ifdef SIM808_CONNECTED
514 HtmlTag fieldset(info, F(
"fieldset"));
516 HtmlTag legend(info, F(
"legend"));
526 HtmlTag fieldset(info, F(
"fieldset"));
528 HtmlTag legend(info, F(
"legend"));
540 HtmlTag fieldset(info, F(
"fieldset"));
542 HtmlTag legend(info, F(
"legend"));
554 #ifdef SIM808_CONNECTED
564 HtmlTag fieldset(info, F(
"fieldset"));
566 HtmlTag legend(info, F(
"legend"));
579 server.send(200, F(
"text/html"), info);
589 MyDbg(F(
"SaveSettings"),
true);
626 F(
"<b>Settings saved</b>");
652 AddTableTr(info, F(
"AP1 SSID (RSSI)"), ssidRssi);
658 #ifdef SIM808_CONNECTED
693 AddTableTr(info, F(
"ESP Chip ID"), String(ESP.getChipId()));
694 AddTableTr(info, F(
"Flash Chip ID"), String(ESP.getFlashChipId()));
695 AddTableTr(info, F(
"Real Flash Memory"), String(ESP.getFlashChipRealSize()) + F(
" Byte"));
696 AddTableTr(info, F(
"Total Flash Memory"), String(ESP.getFlashChipSize()) + F(
" Byte"));
697 AddTableTr(info, F(
"Used Flash Memory"), String(ESP.getSketchSize()) + F(
" Byte"));
698 AddTableTr(info, F(
"Free Sketch Memory"), String(ESP.getFreeSketchSpace()) + F(
" Byte"));
699 AddTableTr(info, F(
"Free Heap Memory"), String(ESP.getFreeHeap()) + F(
" Byte"));
703 server.send(200, F(
"text/html"), info);
710 if (
server.hasArg(F(
"clear"))) {
726 String cmd =
server.arg(F(
"c1"));
727 String startIdx =
server.arg(F(
"c2"));
729 if (
server.hasArg(F(
"c1"))) {
742 if (i >= 0 && i < myData->logInfos.count()) {
751 server.send(200, F(
"text/xml"), sendData.c_str());
758 MyDbg(F(
"Load File /Restart.html"),
true);
760 MyDbg(F(
"Restart"),
true);
785 String message = F(
"File Not Found\n");
787 message += F(
"URI: ");
789 message += F(
"\nMethod: ");
790 message += (
server.method() == HTTP_GET) ? F(
"GET") : F(
"POST");
791 message += F(
"\nArguments: ");
798 server.send(404, F(
"text/plain"), message);
799 MyDbg(message,
true);
String formatInterval(long secs)
long deepSleepTimeSec
Time to stay in deep sleep (without check interrupts)
static void AddTableBegin(String &info)
String phoneNumber
Pone number for sms answers.
static DNSServer dnsServer
Dns server.
static void handleLoadRestartInfo()
bool isGpsEnabled
Is the gps part of the sim808 active?
double powerSaveModeVoltage
Minimum voltage to stay always alive.
bool scanInterval(String interval, long &secs)
long smsCheckIntervalSec
SMS check intervall.
static void handleNotFound()
static void handleLoadConsoleInfo()
bool connectWifiAP
Should we connect to wifi.
static void loadSettings()
long awakeTimeOffsetSec
Awake time offset for SaveSettings.
String TextToXml(String data)
static bool loadFromSpiffs(String path)
String mqttUser
MQTT user.
static MyData * myData
Reference to the data.
String status
Status information.
class MyData::RtcData rtcData
Data to store in the RTC memory.
StringList consoleCmds
open commands to send to the sim808 module
double getLowPowerPowerConsumption()
static void handleLoadInfoInfo()
String wifiAP
WiFi AP name.
long gpsCheckIntervalSec
Time interval to check the gps position.
static void handleLoadMainInfo()
StringList logInfos
received sim808 answers or other logs
String TextToUrl(String data)
void MyDbg(String info, bool fromWebServer=false, bool newline=true)
String softAPIP
registered ip of the access point
#define SOFT_AP_NAME
Soft access point name.
String imei
IMEI of the sim card.
long mqttLastSentTime
Last mqtt sent timestamp.
bool powerOn
Is the GSM power from the DC-DC modul switched on?
double temperature
Current BME280 temperature.
long gpsTimeoutSec
Timeout for waiting for gps position.
MyGps lastGps
Last known gps location without timeout.
String mqttPassword
MQTT password.
double getPowerConsumption()
String WifiGetRssiAsQuality(int rssi)
String satellitesString()
void MyDelay(long millisDelay)
static void loadRestart()
static void AddTableTr(String &info)
double pressure
Current BME280 pressure.
static MyOptions * myOptions
Reference to the options.
String signalQuality
Quality of the signal.
long powerCheckIntervalSec
Time interval to check the power supply.
static void AddBr(String &info)
String wifiPassword
WiFi AP password.
bool isWebServerActive
Is the webserver currently active.
String gprsUser
GRPS access point User.
String batteryVolt
Battery volt of the sim808 module.
static void handleLoadSettingsInfo()
String mqttServer
MQTT server url.
static void AddIntervalInfo(String &info)
long mqttSendCount
How many time the mqtt data successfully sent.
bool isDebugActive
Is detailed debugging enabled?
long mqttPort
MQTT server port.
static MyESPWebServer server
Webserver helper class.
static bool GetOption(String id, String &option)
String restartInfo
Information on restart.
static IPAddress ip
Soft AP ip Address.
long activeTimeSec
Maximum alive time after deepsleep.
static void handleWebRequests()
String cop
Operator selection.
long bme280CheckIntervalSec
Time interval to read the temp, hum and pressure.
String stationIP
registered station ip
bool isMoving
Is moving recognized.
double voltage
Current supply voltage.
String gprsPassword
GRPS access point Password.
String batteryLevel
Battery level of the sim808 module.
MyDate date
The received gps utc date.
static void AddTableEnd(String &info)
bool isSmsEnabled
Is the sms check functionality active?
String modemInfo
Information from SIM808.
#define SOFT_AP_PW
Soft access point password.
String softAPmacAddress
module mac address
String modemIP
registered modem ip
long secondsToDeepSleep
Time until next deepsleep. -1 = disabled.
void addTail(String newInfo)
String gprsAP
GRPS access point of the sim card supplier.
String mqttName
MQTT server name.
static void handleSaveSettings()
bool isMqttEnabled
Should the system connect to a MQTT server?
static void AddOption(String &info, String id, String name, bool value, bool addBr=true)
long deepSleepTimeSec
Time in deep sleep mode.
MyTime time
The received gps utc time.
bool fixStatus
Are the gps is valid received?
MyWebServer(MyOptions &options, MyData &data)
double humidity
Current BME280 humidity.
bool isOtaActive
Is OverTheAir update active?
long mqttSendOnNonMoveEverySec
Send data interval to MQTT server on non moving.
bool isDeepSleepEnabled
Should the system go into deepsleep if needed.
static void loadConsole()
long mqttSendOnMoveEverySec
Send data interval to MQTT server on moving.
double movingDistance
Minimum distance for moving flag.
long minMovingDistance
Minimum distance to accept as moving or not.