-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage_config_net.h
131 lines (119 loc) · 6.04 KB
/
page_config_net.h
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef PAGE_CONFIG_NET_H_
#define PAGE_CONFIG_NET_H_
void send_config_net_html(AsyncWebServerRequest *request) {
if (request->params()) {
config.dhcp = false;
for ( uint8_t i = 0; i < request->params(); i++ ) {
AsyncWebParameter *p = request->getParam(i);
if (p->name() == "ssid") config.ssid = p->value();
if (p->name() == "password") config.passphrase = p->value();
if (p->name() == "ip_0") if (checkRange(p->value())) config.ip[0] = p->value().toInt();
if (p->name() == "ip_1") if (checkRange(p->value())) config.ip[1] = p->value().toInt();
if (p->name() == "ip_2") if (checkRange(p->value())) config.ip[2] = p->value().toInt();
if (p->name() == "ip_3") if (checkRange(p->value())) config.ip[3] = p->value().toInt();
if (p->name() == "nm_0") if (checkRange(p->value())) config.netmask[0] = p->value().toInt();
if (p->name() == "nm_1") if (checkRange(p->value())) config.netmask[1] = p->value().toInt();
if (p->name() == "nm_2") if (checkRange(p->value())) config.netmask[2] = p->value().toInt();
if (p->name() == "nm_3") if (checkRange(p->value())) config.netmask[3] = p->value().toInt();
if (p->name() == "gw_0") if (checkRange(p->value())) config.gateway[0] = p->value().toInt();
if (p->name() == "gw_1") if (checkRange(p->value())) config.gateway[1] = p->value().toInt();
if (p->name() == "gw_2") if (checkRange(p->value())) config.gateway[2] = p->value().toInt();
if (p->name() == "gw_3") if (checkRange(p->value())) config.gateway[3] = p->value().toInt();
if (p->name() == "dhcp") config.dhcp = true;
}
saveConfig();
request->send(200, "text/html",
R"=====(<meta http-equiv="refresh" content="2; url=/"><strong>Rebooting...</strong>)=====");
reboot = true;
} else {
request->send(400);
}
}
void send_config_net_vals(AsyncWebServerRequest *request) {
String values ="";
values += "ssid|input|" + config.ssid + "\n";
values += "password|input|" + config.passphrase + "\n";
values += "ip_0|input|" + (String)config.ip[0] + "\n";
values += "ip_1|input|" + (String)config.ip[1] + "\n";
values += "ip_2|input|" + (String)config.ip[2] + "\n";
values += "ip_3|input|" + (String)config.ip[3] + "\n";
values += "nm_0|input|" + (String)config.netmask[0] + "\n";
values += "nm_1|input|" + (String)config.netmask[1] + "\n";
values += "nm_2|input|" + (String)config.netmask[2] + "\n";
values += "nm_3|input|" + (String)config.netmask[3] + "\n";
values += "gw_0|input|" + (String)config.gateway[0] + "\n";
values += "gw_1|input|" + (String)config.gateway[1] + "\n";
values += "gw_2|input|" + (String)config.gateway[2] + "\n";
values += "gw_3|input|" + (String)config.gateway[3] + "\n";
values += "dhcp|chk|" + (String)(config.dhcp ? "checked" : "") + "\n";
values += "title|div|" + config.id + " - Net Config\n";
request->send(200, "text/plain", values);
}
void send_survey_vals(AsyncWebServerRequest *request) {
String networks = "";
int scanStatus = WiFi.scanComplete();
if (scanStatus == WIFI_SCAN_FAILED) {
WiFi.scanNetworks(true);
networks = "<font color='#FF0000'>Scan in progress...</font>";
} else if (scanStatus == 0) {
networks = "<font color='#FF0000'>No networks found!</font>";
} else if (scanStatus) {
networks = "Found " + String(scanStatus) + " Networks<br>";
networks += "<table border='0' cellspacing='0' cellpadding='3'>";
networks += "<tr bgcolor='#DDDDDD' ><td><strong>Name</strong></td><td><strong>Quality</strong></td><td><strong>Enc</strong></td><tr>";
for (int i = 0; i < scanStatus; ++i) {
int quality = 0;
if (WiFi.RSSI(i) <= -100) {
quality = 0;
} else if (WiFi.RSSI(i) >= -50) {
quality = 100;
} else {
quality = 2 * (WiFi.RSSI(i) + 100);
}
networks += "<tr><td><a href='javascript:selssid(\"" + String(WiFi.SSID(i)) + "\")'>" + String(WiFi.SSID(i)) + "</a></td><td>" + String(quality) + "%</td><td>" + String((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*") + "</td></tr>";
}
networks += "</table>";
WiFi.scanDelete();
}
String values = "";
values += "networks|div|" + networks + "\n";
request->send(200, "text/plain", values);
}
/*
// https://github.com/dancol90/ESP8266Ping/tree/master/src
void send_survey2_vals(AsyncWebServerRequest *request) {
String networks = "";
networks = "Found active network members<br>";
//networks += "<table border='0' cellspacing='0' cellpadding='3'>";
//networks += "<tr bgcolor='#DDDDDD' ><td><strong>Name</strong></td><td><strong>Quality</strong></td><td><strong>Enc</strong></td><tr>";
//for (int i = 0; i < scanStatus; ++i) {
// int quality = 0;
// if (WiFi.RSSI(i) <= -100) {
// quality = 0;
// } else if (WiFi.RSSI(i) >= -50) {
// quality = 100;
// } else {
// quality = 2 * (WiFi.RSSI(i) + 100);
// }
// networks += "<tr><td><a href='javascript:selssid(\"" + String(WiFi.SSID(i)) + "\")'>" + String(WiFi.SSID(i)) + "</a></td><td>" + String(quality) + "%</td><td>" + String((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*") + "</td></tr>";
//}
//networks += "</table>";
//WiFi.scanDelete();
for(int i=100; i <= 120; i++){
IPAddress ip_address(192,168,1,i);
if(Ping.ping(ip_address,1)) {
Serial.println("");
Serial.println("192.168.1." + String(i) + ": Success!");
networks += "192.168.1." + String(i) + "<br>";
} else {
Serial.print(".");
}
//yield();
}
//}
String values = "";
values += "networks|div|" + networks + "\n";
request->send(200, "text/plain", values);
}
*/
#endif /* PAGE_CONFIG_NET_H_ */