I´m trying use together AP and STATION MODE together, but so far could not. Could help me in the code below?
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
#include <string.h>
char ssid[100] = "STA MODE"; //SSID STATION MODE
char password[100] = "1234567890"; //Password STATION MODE
const char* myssid = "AP MODE"; //SSID AP MODE
const char* mypassword = "1234567890"; //Password AP MODE
WiFiServer server(80);
ESP8266WebServer serverAP(8000);
long timeout=0;
char estado=0;
#define OUT1 5
void handleRoot()
{
serverAP.send(200, "text/html", "<h1>You are connected</h1>");
}
void setup()
{
pinMode(OUT1, OUTPUT);
digitalWrite(OUT1, 0);
WiFi.mode(WIFI_AP_STA);
//AP
IPAddress myIP =WiFi.softAP(myssid, mypassword);
serverAP.on("/", handleRoot);
serverAP.begin();
//Station
WiFi.begin(ssid, password);
}
void loop()
{
serverAP.handleClient();
if(estado==0)
{
if (WiFi.status() == WL_CONNECTED)
{
server.begin();
server.setNoDelay(true);
estado=1;
}
}
if(estado==1)
{
WiFiClient client = server.available();
if (!client)
{
return;
}
timeout=0;
while(!client.available() && timeout<=1000)
{
delay(1);
timeout++;
}
String req = client.readStringUntil('\r');
client.flush();
String resposta = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n ";
if (req.indexOf("/A") != -1)
{
digitalWrite(OUT1,1);
resposta += "OUT1 ON";
}
else if (req.indexOf("/a") != -1)
{
digitalWrite(OUT1,0);
resposta += "OUT1 OFF";
}
client.flush();
resposta += "</html>\n";
client.print(resposta);
delay(1);
}
}
Best Regards,
Ursinho