...
|
...
|
@@ -15,106 +15,127 @@ WebServer server(PORT);
|
15
|
15
|
|
16
|
16
|
String message="";
|
17
|
17
|
|
18
|
|
-void handleRoot() {
|
19
|
|
- server.sendHeader("Connection", "close");
|
|
18
|
+String page_header="<!DOCTYPE HTML><html>\n<head>\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <link rel=\"stylesheet\" href=\"https://use.fontawesome.com/releases/v5.7.2/css/all.css\" integrity=\"sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr\" crossorigin=\"anonymous\">\n <title>"+String(APPNAME)+"</title>\n<style>\nhtml{font-family:Arial;display:inline-block;margin:0px auto;text-align:center;}h2{font-size:2.0rem;}p{font-size:3.0rem;}ul,li {list-style-type: none; margin: 0; padding: 0;text-align: left;}li { display: inline-block; color:#00add6;padding-left: 10px; }.results {width: 80%;word-wrap: break-word;font-family: monospace;text-align: left;}.app {font-size:0.8rem;font-style: italic; padding-top: 20px; padding-bottom: 20px;}.dht-labels{font-size:1.0rem;vertical-align:middle;padding-bottom:15px;}\n</style>\n</head>\n<body>\n";
|
|
19
|
+String page_links="<ul class=\"links\">\n<li><a href=\"/\"><i class=\"fas fa-home\"></i></a></li>\n<li><a href=\"/json\"><i class=\"fas fa-clipboard-list\"></i></a></li>\n<li><a href=\"/status\"><i class=\"fas fa-question-circle\"></i></a></li>\n<li><a href=\"/ota\"><i class=\"fas fa-toolbox\"></i></a></li>\n<li><a href=\"/config\"><i class=\"fas fa-cog\"></i></a></li>\n</ul>";
|
|
20
|
+String page_footer="</body></html>";
|
|
21
|
+
|
|
22
|
+String getMACstr() {
|
20
|
23
|
byte mac[6];
|
21
|
24
|
char macStr[6];
|
22
|
25
|
WiFi.macAddress(mac);
|
23
|
26
|
sprintf(macStr,"%02x%02x%02x", mac[3], mac[4], mac[5]);
|
24
|
27
|
String macStrString=macStr;
|
25
|
|
- message = "";
|
26
|
|
- message += "<!DOCTYPE HTML><html>";
|
27
|
|
- message += "<head>";
|
28
|
|
- message += " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">";
|
29
|
|
- message += " <link rel=\"stylesheet\" href=\"https://use.fontawesome.com/releases/v5.7.2/css/all.css\" integrity=\"sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr\" crossorigin=\"anonymous\">";
|
30
|
|
- message += " <title>esp8266-"+macStrString+"</title>";
|
31
|
|
- message += "<style>";
|
32
|
|
- message += "html{font-family:Arial;display:inline-block;margin:0px auto;text-align:center;}";
|
33
|
|
- message += "h2{font-size:2.0rem;}";
|
34
|
|
- message += "p{font-size:3.0rem;}";
|
35
|
|
- message += "ul,li {list-style-type: none; margin: 0; padding: 0;text-align: left;}";
|
36
|
|
- message += ".results {width: 80%;word-wrap: break-word;font-family: monospace;text-align: left;}";
|
37
|
|
- message += ".app {font-size:0.8rem;font-style: italic; padding-top: 20px; padding-bottom: 20px;}";
|
38
|
|
- message += ".dht-labels{font-size:1.5rem;vertical-align:middle;padding-bottom:15px;}";
|
39
|
|
- message += "</style>";
|
40
|
|
- message += "</head>";
|
41
|
|
- message += "<body>";
|
42
|
|
- message += "<h2>esp8266-"+macStrString+"</h2>";
|
|
28
|
+ return macStrString;
|
|
29
|
+}
|
|
30
|
+void handleRoot() {
|
|
31
|
+ server.sendHeader("Connection", "close");
|
|
32
|
+ message = page_header;
|
|
33
|
+ message += "<h2>esp32-"+getMACstr()+"</h2>";
|
43
|
34
|
message += "<p><i class=\"fas fa-clock\" style=\"color:#00add6;\"></i><span class=\"dht-labels\">Date</span> <span id=\"temperature\">"+String(acTimeStringTZ)+"</span></p>";
|
44
|
35
|
message += "<div class=\"results\">\n";
|
45
|
36
|
message += ss.str().c_str();
|
46
|
37
|
message += "</div>\n";
|
47
|
38
|
message += "<div class=\"app\">"+String(compile_date)+"</div>";
|
48
|
|
- message += "<ul class=\"links\">";
|
49
|
|
- message += "<li><a href=\"/status\">/status</li>";
|
50
|
|
- message += "<li><a href=\"/ota\">/ota</li>";
|
51
|
|
- message += "<li><a href=\"/json\">/json</li>";
|
52
|
|
- message += "</ul>";
|
53
|
|
- message += "</body></html>";
|
|
39
|
+ message += page_links;
|
|
40
|
+ message += page_footer;
|
54
|
41
|
server.send(200, "text/html", message );
|
55
|
42
|
}
|
56
|
43
|
void handleJSON() {
|
57
|
44
|
server.sendHeader("Connection", "close");
|
58
|
|
- byte mac[6];
|
59
|
|
- char macStr[6];
|
60
|
|
- WiFi.macAddress(mac);
|
61
|
|
- sprintf(macStr,"%02x%02x%02x\0", mac[3], mac[4], mac[5]);
|
62
|
|
- String macStrString=macStr;
|
63
|
|
- String statusMsg = "{";
|
64
|
|
- statusMsg += "\"ota_name\": \"esp8266-"+macStrString+"\",";
|
65
|
|
- statusMsg += "\"uptime\": "+String(millis())+",";
|
66
|
|
- statusMsg += "\"countMeasures\": "+String(countMeasures)+",";
|
67
|
|
- statusMsg += "\"last_update\": \""+String(acTimeStringTZ)+"\",";
|
68
|
|
- statusMsg += "\"epoch\":" +String(acTimeEpoch)+",";
|
69
|
|
- statusMsg += "\"ble\": "+String(listBLEElts.str().c_str());
|
70
|
|
- statusMsg += "}";
|
71
|
|
- server.send(200, "text/html", String(statusMsg) );
|
|
45
|
+ message = "{";
|
|
46
|
+ message += "\"ota_name\": \"esp32-"+getMACstr()+"\",";
|
|
47
|
+ message += "\"uptime\": "+String(millis())+",";
|
|
48
|
+ message += "\"countMeasures\": "+String(countMeasures)+",";
|
|
49
|
+ message += "\"last_update\": \""+String(acTimeStringTZ)+"\",";
|
|
50
|
+ message += "\"epoch\":" +String(acTimeEpoch)+",";
|
|
51
|
+ message += "\"ble\": "+String(listBLEElts.str().c_str());
|
|
52
|
+ message += "}";
|
|
53
|
+ server.send(200, "text/html", String(message) );
|
72
|
54
|
}
|
73
|
55
|
void handleSTATUS() {
|
74
|
56
|
server.sendHeader("Connection", "close");
|
75
|
|
- byte mac[6];
|
76
|
|
- char macStr[6];
|
77
|
|
- bzero(macStr,6);
|
78
|
|
- WiFi.macAddress(mac);
|
79
|
|
- sprintf(macStr,"%02x%02x%02x", mac[3], mac[4], mac[5]);
|
80
|
|
- String macStrString=macStr;
|
81
|
|
- String statusMsg = "{";
|
82
|
|
- statusMsg += "\"app_name\": \""+String(APPNAME)+"\",";
|
83
|
|
- statusMsg += "\"app_version\": \""+String(APPVER)+"\",";
|
84
|
|
- statusMsg += "\"build_date\": \""+String(compile_time)+"\",";
|
85
|
|
- statusMsg += "\"mac\": \""+WiFi.macAddress()+"\",";
|
86
|
|
- statusMsg += "\"ip\": \""+WiFiIP+"\",";
|
87
|
|
- statusMsg += "\"ota_name\": \"esp8266-"+macStrString+"\",";
|
88
|
|
- statusMsg += "\"uptime\": "+String(millis())+",";
|
89
|
|
- statusMsg += "\"countMeasures\": "+String(countMeasures)+",";
|
90
|
|
- statusMsg += "\"period\": "+String(UPDATE_PERIOD)+",";
|
91
|
|
- statusMsg += "\"loop_delay\": "+String(LOOP_DELAY)+",";
|
92
|
|
- statusMsg += "\"last_update\": \""+String(acTimeStringTZ)+"\",";
|
93
|
|
- statusMsg += "\"epoch\":" +String(acTimeEpoch);
|
94
|
|
- statusMsg += "}";
|
95
|
|
- server.send(200, "text/html", String(statusMsg) );
|
|
57
|
+ message = page_header;
|
|
58
|
+ message += "<h2>esp32-"+getMACstr()+" Status</h2>";
|
|
59
|
+ message += "{";
|
|
60
|
+ message += "\"app_name\": \""+String(APPNAME)+"\",";
|
|
61
|
+ message += "\"app_version\": \""+String(APPVER)+"\",";
|
|
62
|
+ message += "\"build_date\": \""+String(compile_time)+"\",";
|
|
63
|
+ message += "\"mac\": \""+WiFi.macAddress()+"\",";
|
|
64
|
+ message += "\"ip\": \""+WiFiIP+"\",";
|
|
65
|
+ message += "\"ota_name\": \"esp32-"+getMACstr()+"\",";
|
|
66
|
+ message += "\"uptime\": "+String(millis())+",";
|
|
67
|
+ message += "\"countMeasures\": "+String(countMeasures)+",";
|
|
68
|
+ message += "\"period\": "+String(UPDATE_PERIOD)+",";
|
|
69
|
+ message += "\"loop_delay\": "+String(LOOP_DELAY)+",";
|
|
70
|
+ message += "\"last_update\": \""+String(acTimeStringTZ)+"\",";
|
|
71
|
+ message += "\"epoch\":" +String(acTimeEpoch);
|
|
72
|
+ message += "}";
|
|
73
|
+ message += page_links;
|
|
74
|
+ message += page_footer;
|
|
75
|
+ server.send(200, "text/html", String(message) );
|
96
|
76
|
}
|
97
|
77
|
void handleOTA() {
|
98
|
78
|
server.sendHeader("Connection", "close");
|
99
|
|
- message = "";
|
|
79
|
+ //message = "";
|
|
80
|
+ message = page_header;
|
100
|
81
|
//message += "<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>";
|
101
|
82
|
if( 0 == strcmp(aplist[currentAPIndex].ssid,"kawifi") ) {
|
102
|
83
|
message += "<script src='http://"+String(mqtt_server_int)+"/jquery.min.js'></script>\n";
|
103
|
84
|
} else {
|
104
|
85
|
message += "<script src='http://"+String(mqtt_server_ext)+"/jquery.min.js'></script>\n";
|
105
|
86
|
}
|
|
87
|
+ message += "<h2>esp32-"+getMACstr()+" OTA</h2>";
|
106
|
88
|
message += "<form method='POST' action='#' enctype='multipart/form-data' id='upload_form'>\n";
|
107
|
89
|
message += "Firmware:<br>\n";
|
108
|
90
|
message += "<input type='file' name='update'><input type='submit' value='Update Firmware'>\n";
|
109
|
91
|
message += "</form>\n";
|
110
|
92
|
message += "<div id='prg'>progress: 0%</div>\n";
|
111
|
93
|
message += otaScript;
|
|
94
|
+ message += page_links;
|
|
95
|
+ message += page_footer;
|
|
96
|
+ server.send(200, "text/html", String(message) );
|
|
97
|
+}
|
|
98
|
+void handleCONFIG() {
|
|
99
|
+ server.sendHeader("Connection", "close");
|
|
100
|
+ message = page_header;
|
|
101
|
+ message += "<h2>esp32-"+getMACstr()+" Configuration</h2>";
|
|
102
|
+ message += "<form action=\"\">\n";
|
|
103
|
+ message += "<label for=\"gInterval\">Interval:</label><br>\n";
|
|
104
|
+ message += "<input type=\"text\" id=\"gInterval\" name=\"gInterval\" value=\""+String(gInterval)+"\"><br>\n";
|
|
105
|
+ message += "<label for=\"gWindow\">Window:</label><br>\n";
|
|
106
|
+ message += "<input type=\"text\" id=\"gWindow\" name=\"gWindow\" value=\""+String(gWindow)+"\"><br>\n";
|
|
107
|
+ message += "<label for=\"gScanTime\">ScanTime:</label><br>\n";
|
|
108
|
+ message += "<input type=\"text\" id=\"gSc\" name=\"gScanTime\" value=\""+String(gScanTime)+"\"><br>\n";
|
|
109
|
+ message += "<input type=\"submit\" value=\"Submit\">\n";
|
|
110
|
+ message += "</form>\n";
|
|
111
|
+ for (uint8_t i = 0; i < server.args(); i++) {
|
|
112
|
+ if( String(server.argName(i)) == String("gInterval") ) {
|
|
113
|
+ if( gInterval != String(server.arg(i)).toInt() ) {
|
|
114
|
+ gInterval = String(server.arg(i)).toInt();
|
|
115
|
+ message += "Changing gInterval<br>";
|
|
116
|
+ }
|
|
117
|
+ } else if( String(server.argName(i)) == String("gWindow") ) {
|
|
118
|
+ if( gWindow != String(server.arg(i)).toInt() ) {
|
|
119
|
+ gWindow = String(server.arg(i)).toInt();
|
|
120
|
+ message += "Changing gWindow<br>";
|
|
121
|
+ }
|
|
122
|
+ } else if( String(server.argName(i)) == String("gScanTime") ) {
|
|
123
|
+ if( gScanTime != String(server.arg(i)).toInt() ) {
|
|
124
|
+ gScanTime = String(server.arg(i)).toInt();
|
|
125
|
+ message += "Changing gScanTime<br>";
|
|
126
|
+ }
|
|
127
|
+ }
|
|
128
|
+ }
|
|
129
|
+ message += page_links;
|
|
130
|
+ message += page_footer;
|
112
|
131
|
server.send(200, "text/html", String(message) );
|
113
|
132
|
}
|
114
|
133
|
|
115
|
134
|
void handleNotFound() {
|
116
|
135
|
server.sendHeader("Connection", "close");
|
117
|
|
- String message = "File Not Found\n\n";
|
|
136
|
+ //String message = "File Not Found\n\n";
|
|
137
|
+ String message = page_header;
|
|
138
|
+ message += "File Not Found\n\n";
|
118
|
139
|
message += "URI: ";
|
119
|
140
|
message += server.uri();
|
120
|
141
|
message += "\nMethod: ";
|
...
|
...
|
@@ -122,18 +143,20 @@ void handleNotFound() {
|
122
|
143
|
message += "\nArguments: ";
|
123
|
144
|
message += server.args();
|
124
|
145
|
message += "\n";
|
125
|
|
-
|
126
|
146
|
for (uint8_t i = 0; i < server.args(); i++) {
|
127
|
147
|
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
|
128
|
148
|
}
|
129
|
|
- server.send(404, "text/plain", message);
|
|
149
|
+ message += page_links;
|
|
150
|
+ message += page_footer;
|
|
151
|
+ server.send(404, "text/html", message);
|
130
|
152
|
}
|
131
|
153
|
|
132
|
154
|
|
133
|
155
|
void http_set() {
|
134
|
156
|
server.on("/", handleRoot);
|
135
|
|
- server.on("/status", handleSTATUS);
|
136
|
|
- server.on("/json", handleJSON);
|
|
157
|
+ server.on("/status", handleSTATUS);
|
|
158
|
+ server.on("/json", handleJSON);
|
|
159
|
+ server.on("/config", handleCONFIG);
|
137
|
160
|
server.onNotFound(handleNotFound);
|
138
|
161
|
server.begin();
|
139
|
162
|
|