Socket Server Not Accepting Clients
Posted: Sat Feb 27, 2021 3:58 pm
The ESP-01 module connects to the router and gets an IP, I can see it on the router page, but it will not accept incoming clients nor pings. I've tried two ESP modules, different ports, various "Tool" settings in Arduino IDE 1.8.13. Such a simple code, with examples on the web, should just work. It must be something stupid, but I have days into this problem. What is the problem?
The serial monitor output after module reset:
Using Putty (Win10) to connect, set to Connection type: Raw. Also tried Telnet and Ubuntu command line, pinging.
After 20 sec or so it times out "Network error: Connection timed out"
Update: I discovered a diagnostics feature of my router where it can send pings. This works, the ESP responds within 2ms four times. It does not work from Win10 command line, "ping 192.168.0.26", nor from Ubuntu. Nothing I've tried can connect except the router's ping. Still stumped.
I can ping other devices on the LAN from command line, including other WiFi devices, just not the ESP-01.
Code: Select all
#include <ESP8266WiFi.h>
const char *ssid = "XXXX";
const char *password = "yyyy";
ESP8266WiFiClass wifi; // For printDiag()
WiFiServer server( 80 );
void setup() {
Serial.begin( 74880 ); // Same as boot loader
while( !Serial );
WiFi.begin( ssid, password );
Serial.print( "Connecting " );
while( WiFi.status() != WL_CONNECTED ) {
delay( 500 );
Serial.print( "." );
}
Serial.println();
Serial.print( "Connected to WiFi. IP: " );
Serial.println( WiFi.localIP() );
server.begin();
wifi.printDiag( Serial );
}
void loop() {
WiFiClient client = server.available();
if( client ) {
Serial.println( "Have pending client connection" ); // Never executes
while( client.connected() ) {
while( client.available() > 0 ) {
char c = client.read();
Serial.write( c );
}
delay( 10 );
}
client.stop();
Serial.println( "Client disconnected" );
}
}
The serial monitor output after module reset:
Code: Select all
ets Jan 8 2013,rst cause:2, boot mode:(3,7)
load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld
Connecting .
Connected to WiFi. IP: 192.168.0.26
Mode: STA+AP
PHY mode: N
Channel: 6
AP id: 0
Status: 5
Auto connect: 1
SSID (17): XXXX
Passphrase (30): yyyy
BSSID set: 0
Using Putty (Win10) to connect, set to Connection type: Raw. Also tried Telnet and Ubuntu command line, pinging.
After 20 sec or so it times out "Network error: Connection timed out"
Update: I discovered a diagnostics feature of my router where it can send pings. This works, the ESP responds within 2ms four times. It does not work from Win10 command line, "ping 192.168.0.26", nor from Ubuntu. Nothing I've tried can connect except the router's ping. Still stumped.
I can ping other devices on the LAN from command line, including other WiFi devices, just not the ESP-01.