I´m currently trying to connect a smartphone to the AMW006 TCP server. But sometimes the socket connection fails and after that, it´s not even possible to reconnect the phone to the access point of the AMW006. The error code on my phone is ECONNREFUSED (Connection refused). If I disable the wifi on my phone the status leds of the AMW006 indicate, that there is still a connection (all leds blink slowly).
My current setup is:
set tcp.keepalive.enabled 1
set tcp.keepalive.initial_timeout 5
set tcp.keepalive.retry_count 5
set tcp.keepalive.retry_timeout 1
set tcp.server.auto_interface softap
set tcp.server.auto_start 1
set tcp.server.max_clients 1
set tcp.server.idle_timeout 120
set tcp.server.port 3000
I´m using stream mode and the version ZENTRI-AMW006-188.8.131.52, 2018-09-13T04:57:09Z, ZentriOS-W-184.108.40.206, Board:AMW006-A1W.2.
Thanks for your help
With keepalive enabled, if no traffic on the TCP socket, server will force disconnect. Did you try disabling the keepalive or this is a needed feature?
On the other side, when this happens can you please list all the connections and streams open:
To list all open streams with: stream_list
To list all streams with status: stream_poll all -r
To list all connected clients: get softap.info
There is a limit on number of open streams (maximum 8), and another limit on number of connected clients (configured by softap.max_clients, which is 4 by default). So the info above should show if any of these limits is reached.
thanks for the quick response. I disabled keepalive, but the error still occures sometimes.
Here the information you requested:
The serial interface of the wifi module is connected to a microcontroller, therefore to access the wifi modul (to get the information above) I have to use the remote terminal. But only in some cases I´m able to conncet two clients (phone and pc) to the wifi modul.
I am trying to reproduce this locally with no luck. Would you please help with the exact scenario that helps showing the problem? What exact settings (if different than the above), then what flow your mobile and PC are connecting/ disconnecting. Also do you send any data on the link, or just conn/discon? Any info will be helpful here. Next step will be to sniff the traffic using wireshark, but lets first try to reproduce this here before moving ahead with other steps..
My PC is only connected for test purposes. The wifi module is connected to the serial interface of a microcontroller. My phone is used to control this microcontroller.
First the phone connects to the wifi module (port 2000) initializes the socket, sends gpio_set 20 1, reads set ok, closes the socket than repeats the same process with gpio_set 20 0. This causes the microcontroller to wake up. The phone initializes a socket (port 3000) to connect to the microcontroller, which sends a byte (FF) to indicate that it´s ready to recieve commands. After this byte is received the socket is closed.
After that the phone initializes infrequently a tcp connection (port 3000) to pass commands to the microcontroller (5 to 10 bytes) awaits and response (7 to 10 bytes) before closing the socket.
Some commands require no answer, then the socket is closed after sending the command.
The discribed error occurres sometimes after a socket timeout exception (which are necessary to check if the micorocontroller is in standby) or after the app was idle for sometime. After the timout occurred all attempts open a new socket fail, if it happens, only restarting the wifi modul helps. Sometimes the error occures every few minutes and sometimes it works fine for half a day.
The read and write timeout of the tcp socket of the phone is 4 sec.
I did some additional tests by connecting the wifi module with my pc (by connecting to the wifi modul (port 2000) and the microcontroller (port 3000)) . If the client (pc) looses the connection for example if the user turns off the wifi temporarily, then sometimes the wifi modul doesn´t recognize that the connection is lost and refuses to reconnect. Only cutting off the power to the wifi modul resolves this issue. I attached a wireshark protokoll for further information. The error occured at the last connection attemt (No. 206).
I used ncat to conntect to the wifi module.