Closed
Description
Hardware
Hardware: ESP-12E
Core Version: 2.3.0
Description
I found esp826612e network may have some problem, so I write a simple code to test it.
In short, ESP826612e act as station join my router wifi, and act as a tcp server, accept only one connection, my computer act as a TCP client. Client send a byte then server recived it and send back a same byte. In loop, sometime ESP8266 think TCP connection is break, computer found tcp connection is break after a short time
Sketch
#include <ESP8266WiFi.h>
WiFiServer server(23333);
WiFiClient client;
bool connected = false;
const char *ssid = "xxx";
const char *password = "yyy";
void setup() {
Serial.begin(115200);
Serial.println();
server.begin();
WiFi.mode( WIFI_STA );
WiFi.begin ( ssid, password );
// Wait for connection
while ( WiFi.status() != WL_CONNECTED ) {
delay(500);
Serial.print('.');
}
Serial.print("\nIPAddress: ");
Serial.println ( WiFi.localIP() );
}
void loop() {
if (client.connected()) {
if (!connected) {
connected = true;
Serial.println("\ntcp connected");
}
int ch;
if ((ch=client.read()) != -1) {
Serial.printf("%c", ch);
client.write((char)ch);
}
}
else {
if (connected) {
connected = false;
Serial.println("\ntcp disconnected");
}
client = server.available();
client.setNoDelay(true);
}
}
test script
import socket
import time
host = '192.168.31.215'
port = 23333
addr = (host, port)
client=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(addr)
client.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
last = time.time()
while True:
client.send('x')
data=client.recv(1)
if data == 'x':
cur = time.time()
print '%4d ms' % ((cur - last) * 1000)
time.sleep(0.05)
last = time.time()
Metadata
Metadata
Assignees
Labels
No labels