Node mcu (1.0) ESP8266 12E doesn't respond after IDLE time i
Posted: Wed Jan 01, 2020 8:43 am
I am trying to set up node mcu as Access Point with static IP. I am able to connect to the AP using tcp sockets and receive response from it.
However, if the client is not connected to it for a certain amount of time, node MCU doesn't respond at all.
Say if 1 hr passed as idle time then node mcu allows clients to connect to the AP but it doesn't respond to the queries.
Here is my code.
I am using Arduino ide to flash the code.
Arduino version: 1.8.10 Board: Node Mcu 1.0 12E Upload speed: 115200 CPU freq: 80Mhz (Board Manager) Esp8266 : 2.6.2
Just to summarize after idle period node mcu let me connect using tcp sockets but it won't turn off/on the led and it doesn't send any response back. If I reset node mcu then it works again.
I am not able to figure out why this is happening. Any help is appreciated.
However, if the client is not connected to it for a certain amount of time, node MCU doesn't respond at all.
Say if 1 hr passed as idle time then node mcu allows clients to connect to the AP but it doesn't respond to the queries.
Here is my code.
Code: Select all
#include <ESP8266WiFi.h>
WiFiServer server(8080);
IPAddress IP(192,168,4,15);
IPAddress mask = (255, 255, 255, 0);
//byte ledPin = 16;
byte ledPin = 2;
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_AP);
WiFi.softAP("PRAKASH", "1234567890");
WiFi.softAPConfig(IP, IP, mask);
server.begin();
pinMode(ledPin, OUTPUT);
Serial.println();
Serial.println("Server started.");
Serial.print("IP: "); Serial.println(WiFi.softAPIP());
Serial.print("MAC:"); Serial.println(WiFi.softAPmacAddress());
}
void loop(void) {
WiFiClient client = server.available();
if (client) {
Serial.println("Client connected.");
while (client.connected()) {
if (client.available()) {
String request = client.readStringUntil('\r');
Serial.println("____NEW_COMMAND_____");
if (request == "LED_ON") {
digitalWrite(ledPin, LOW);
Serial.println("LED is now on.");
} else if (request == "LED_OFF") {
digitalWrite(ledPin, HIGH);
Serial.println("LED is now off.");
} else {
Serial.println("Invalid command:");
Serial.println(request);
}
Serial.println("From the station: " + request);
client.flush();
Serial.print("Byte sent to the station: ");
Serial.println(client.println(request + "ca" + "\r"));
Serial.println("*____COMMAND_COMPLETED____*");
}
}
Serial.println("Client disconnected.");
client.stop();
}
}
I am using Arduino ide to flash the code.
Arduino version: 1.8.10 Board: Node Mcu 1.0 12E Upload speed: 115200 CPU freq: 80Mhz (Board Manager) Esp8266 : 2.6.2
Just to summarize after idle period node mcu let me connect using tcp sockets but it won't turn off/on the led and it doesn't send any response back. If I reset node mcu then it works again.
I am not able to figure out why this is happening. Any help is appreciated.