-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathWebConfig.cpp
71 lines (56 loc) · 2.03 KB
/
WebConfig.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
//
//
#include "WebConfig.h"
Web_Get_Function WebConfig::gConfigPageFunction = 0;
Web_Response_Function WebConfig::gSavePageFunction = 0;
ESP8266WebServer WebConfig::gWebServer = ESP8266WebServer(80);
WebConfig::WebConfig(Web_Get_Function pConfigPageFunction, Web_Response_Function pSavePageFunction)
{
WebConfig::gConfigPageFunction = pConfigPageFunction;
WebConfig::gSavePageFunction = pSavePageFunction;
}
void WebConfig::Setup()
{
WiFi.disconnect(true);
WiFi.softAPdisconnect(true);
WiFi.mode(WIFI_OFF);
delay(2000);
WiFi.softAP(AP_SSID);
WiFi.mode(WIFI_AP);
Serial1.println("Configuring access point as ");
Serial1.println(AP_SSID);
IPAddress vIP = WiFi.softAPIP();
Serial1.println("AP IP Address: ");
Serial1.println(vIP.toString().c_str());
SetupWebServer();
while (true)
gWebServer.handleClient();
}
void WebConfig::SetupWebServer()
{
Serial1.println("Setting up web server on port 80");
gWebServer.on("/", WebConfig::WebServer_GetConfig);
gWebServer.on("/save", HTTP_POST, WebConfig::WebServer_SaveConfig);
gWebServer.begin();
}
void WebConfig::WebServer_GetConfig()
{
Serial1.println("Responding to HTTP request at '/'");
String vHtmlText = gConfigPageFunction();
gWebServer.send(200, "text/html", vHtmlText);
}
void WebConfig::WebServer_SaveConfig()
{
String vHtmlText = gSavePageFunction(gWebServer);
gWebServer.send(200, "text/html", vHtmlText);
}
const char* WebConfig::AP_SSID = "ESP_Pulse_Meter";
/*
const char* WebConfig::AP_CONFIG_PAGE = "<html><body><form method='POST' action='/save'>SSID: <input name='ssid'/><br/>Password: <input name='pwd' type='password'/><br/><h3>MQTT</h3>Server: <input name='msrv'/><br/>Topic: <input name='mtop'/><br/>Sensor Name: <input name='mname'/><br/><input type='submit' value='submit'/></body></form>";
const char* WebConfig::AP_SUCCESS_PAGE = "<html><body><h1>Successflly Saved!</h1><h3>Please restart the device now</h3></body></form>";
*/
void WebConfig::Handle()
{
WebConfig::gWebServer.handleClient();
}