Skip to content

SoftAP interface is not accessible when STA connection is not established #1661

Closed
@geoffreyhhh

Description

@geoffreyhhh

with example code below, it acts as wifi client to connects to a wifi ap "testAP", and obtain a dhcp ip e.g. 192.168.43.52 from the wifi ap. at the same time, the esp8266 has it own ip, e.g. 192.168.4.1.

we can use web browser to access the 192.168.43.52 and to turn on/off led on esp8266 board.
at the same time, we use another pc to connect to esp8266_AP 192.168.4.1 and obtain a dhcp ip, e.g. 192.168.4.3, and use web browser to access 192.168.4.1 to turn on/off led on esp8266 board.

however, when the 192.168.43.* wifi connection is not established, accessing 192.168.4.1 is very difficult, ping to 192.168.4.1 shows many time-out and only rarely successful ping response. accessing 192.168.4.1 with web browser is failed

could anyone advise when is the cause that when 192.168.43.* wifi connection is not established, 192.168.4.* shows very poor connection performance and the 192.168.4.1 web server is hardly not accessible.

thank you.

include ESP8266WiFi.h #anchor removed as it didn't show up

include WiFiClient.h

include ESP8266WebServer.h

include ESP8266mDNS.h

const char* ssid = "testAP";
const char* password = "12345678";
MDNSResponder mdns;

ESP8266WebServer server(80);

const int led = 13;

void handleRoot() {
server.send(200, "text/plain",
"hello from esp8266!) \n/on: to tuen LED ON \n/off: to tuen LED OFF \n");

}

void handleNotFound(){
digitalWrite(led, 1);
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
digitalWrite(led, 0);
}

void setup(void){
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");

// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

if (mdns.begin("esp8266", WiFi.localIP())) {
Serial.println("MDNS responder started");
}

server.on("/", handleRoot);

server.on("/on", {
digitalWrite(BUILTIN_LED, LOW);
server.send(200, "text/plain", "LED ON");
});

server.on("/off", {
digitalWrite(BUILTIN_LED, HIGH);
server.send(200, "text/plain", "LED OFF");
});

server.onNotFound(handleNotFound);

server.begin();
Serial.println("HTTP server started");

//delay a moment,
//for terminal to receive inf, such as IP address
delay(1000);
Serial.end();
pinMode(BUILTIN_LED, OUTPUT);
}

void loop(void){
server.handleClient();
}

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions