嗨,
我正在尝试同时使用 AP 和 STA
tiON MODE,但到目前为止还不能。可以在下面的代码中帮助我吗?
#include
#include
#include
#include
char ssid[100] = "STA MODE"; //SSID STATION MODE
char password[100] = "1234567890"; //密码 STATION MODE
const char* myssid = "AP MODE"; //SSID AP 模式
const char* mypassword = "1234567890"; //密码AP MODE
WiFiServer server(80);
ESP8266WebServer serverAP(8000);
长时间超时=0;
char estado = 0;
serverAP.send(200, "text/html", "已连接
");
}
void setup()
{
pinMode(OUT1, OUTPUT);
数字写入(OUT1,0);
WiFi.mode(WIFI_AP_STA);
//AP
IP地址 myIP =WiFi.softAP(myssid, mypassword);
serverAP.on("/", handleRoot);
serverAP.begin();
//建站
WiFi.begin(ssid, password);
}
void loop()
{
serverAP.handleClient();
if(estado==0)
{
if (WiFi.status() == WL_CONNECTED)
{
server.begin();
服务器.setNoDelay(true);
状态=1;
}
}
if(estado==1)
{
WiFiClient client = server.available();
如果(!客户)
{
返回;
}
超时=0;
while(!client.available() && 超时<=1000)
{
延迟(1);
超时++;
}
String req = client.readStringUntil('r');
客户端.flush();
String resposta = "HTTP/1.1 200 OKrnContent-Type: text/htmlrnrnrnrn ";
如果 (req.indexOf("/A") != -1)
{
digitalWrite(OUT1,1);
resposta += "OUT1 ON";
{
digitalWrite(OUT1,0);
resposta += "OUT1 关闭";
}
client.flush();
resposta += "n";
client.print(resposta);
延迟(1);
}