|
楼主 |
发表于 2021-3-1 10:53:00
|
显示全部楼层
SkyGz 发表于 2021-2-28 18:02
wifiManager.setAPStaticIPConfig(IPAddress(192,168,1,99), IPAddress(192,168,1,1), IPAddress(255, ...
这个静态IP是STA的静态IP,不是AP模式的IP。有个函数:
setSTAStaticIPConfig
看代码,里面有相关内容
/**
* HTTPD CALLBACK save form and redirect to WLAN config page again
*/
void WiFiManager::handleWifiSave() {
#ifdef WM_DEBUG_LEVEL
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP WiFi save "));
DEBUG_WM(DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST));
#endif
handleRequest();
// @todo use new callback for before paramsaves
if ( _presavecallback != NULL) {
_presavecallback();
}
//SAVE/connect here
_ssid = server->arg(F("s")).c_str();
_pass = server->arg(F("p")).c_str();
if(_paramsInWifi) doParamSave();
if (server->arg(FPSTR(S_ip)) != "") {
//_sta_static_ip.fromString(server->arg(FPSTR(S_ip));
String ip = server->arg(FPSTR(S_ip));
optionalIPFromString(&_sta_static_ip, ip.c_str());
#ifdef WM_DEBUG_LEVEL
DEBUG_WM(DEBUG_DEV,F("static ip:"),ip);
#endif
}
if (server->arg(FPSTR(S_gw)) != "") {
String gw = server->arg(FPSTR(S_gw));
optionalIPFromString(&_sta_static_gw, gw.c_str());
#ifdef WM_DEBUG_LEVEL
DEBUG_WM(DEBUG_DEV,F("static gateway:"),gw);
#endif
}
if (server->arg(FPSTR(S_sn)) != "") {
String sn = server->arg(FPSTR(S_sn));
optionalIPFromString(&_sta_static_sn, sn.c_str());
#ifdef WM_DEBUG_LEVEL
DEBUG_WM(DEBUG_DEV,F("static netmask:"),sn);
#endif
}
if (server->arg(FPSTR(S_dns)) != "") {
String dns = server->arg(FPSTR(S_dns));
optionalIPFromString(&_sta_static_dns, dns.c_str());
#ifdef WM_DEBUG_LEVEL
DEBUG_WM(DEBUG_DEV,F("static DNS:"),dns);
#endif
}
String page;
if(_ssid == ""){
page = getHTTPHead(FPSTR(S_titlewifisettings)); // @token titleparamsaved
page += FPSTR(HTTP_PARAMSAVED);
}
else {
page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved
page += FPSTR(HTTP_SAVED);
}
page += FPSTR(HTTP_END);
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
server->sendHeader(FPSTR(HTTP_HEAD_CORS), FPSTR(HTTP_HEAD_CORS_ALLOW_ALL));
server->send(200, FPSTR(HTTP_HEAD_CT), page);
#ifdef WM_DEBUG_LEVEL
DEBUG_WM(DEBUG_DEV,F("Sent wifi save page"));
#endif
connect = true; //signal ready to connect/reset process in processConfigPortal
}
这个handleWifiSave函数里会检查server->arg(FPSTR(S_ip)) 这个即使STA的静态IP,如果有值会传给_sta_static_ip变量用作sta模式的静态IP,还有网关、子网掩码、dns参数。
server在类中定义
std::unique_ptr<WM_WebServer> server;
ssid和密码也是存在这里的,是在AP模式下,通过192.168.4.1登录设置后保存,然后在STA模式读出使用。
//SAVE/connect here
_ssid = server->arg(F("s")).c_str();
_pass = server->arg(F("p")).c_str();
还没弄明白 server->arg(FPSTR(S_ip) 这些怎么在AP模式下设置,怎么在STA模式读出使用。
|
|