ESP32 is set as AP. After the client disconnects from WIFI and then reconnects to WIFI, the client socket cannot connect
[Copy link]
When testing the ESP32 micropython network application, I found a problem: ESP32 is set as AP, and ESP32 is used as the server. The mobile phone is connected to ESP32 normally, and the mobile phone is used as the client. The mobile phone sends and receives data normally. After the mobile phone disconnects the socket connection, it reconnects the socket again, and the sending and receiving of data are still normal! But! ! ! : If the mobile phone socket is connected normally, the WIFI connection on the mobile phone is changed to another AP, and then changed back again, in this case, the mobile phone socket will not be able to connect to the server! But if the mobile phone socket is actively disconnected, then the WIFI is changed, and then changed back, it is normal for the mobile phone socket to reconnect! The server-side recv() uses the default blocking mode for reception. When the WIFI is disconnected, this recv() does not return any information, and the user program cannot determine the current connection status. Should it be received in a non-blocking mode (MICROPYTHON defaults to blocking mode). I don’t know how to deal with it. Please ask an expert!
while 1:
print("accepting.....")
conn,addr = listenSocket.accept() #Accept a connection,conn is a new socket object
print(addr,"connected")
while True:
data = conn.recv(1024)
if(len(data) == 0):
print("close socket")
conn.close()
break
print(data)
ret = conn.send(data)
|