Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By ursinho
#56843 Hi,

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
User avatar
By mrburnette
#56915 Two things:
1) please edit your post and properly use code tags .... on the menu ribbon it is the </> button and your code goes between the tags.

2) This is just wrong:
Code: Select allchar 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


When you install the ESP8266 core in Arduino, you get a lots of examples. They should be studied.
Help on commands is here:
https://github.com/esp8266/Arduino#documentation

But ... there are so many working examples on the Internet ... and even here in the forum. I recommend you do a little homework - examples are not hard to find.


Ray
User avatar
By vkthakar
#68285 Hi,

I have tested AP+STA mode and find out one issue like,

ESP8266 STA mode continuously tried to connected to SSID if it has wrong SSID.
In This condition, sometime mobile wifi can not connect with ESP8266 AP mode. needed multiple retries for connect mobile wifi to ESP8266 AP mode.
sometimes got error like, err already associed! . But after sometime connect successfully.
After successful connection, communication with mobile to ESP8266 execute successfully without any issue.

If any has idea about this behavior then please let me know and tell me solution for that also.

regards,
vkthakar