wifi latency
Posted: Mon Jun 22, 2020 4:06 am
I have been having problems with wifi latency sometimes dropping 10-20 seconds. I am sending packets every 100 milliseconds, and more than 500 is considered "time out" I have tried several images with different compiler settings, including official images. Is it known that wifi is not working at its potential?
First I changed my access point settings in hostapd.conf. I lowered dtim_period=1 and this made a big difference for the esp32 despite not really affecting other devices. I wonder if the esp32 would not need this and could work with slower beacons (lower sleep power) if the driver were modified?
I found with tcp sockets and low through put of 100-200 bytes/s, the driver gets "stuck" and sometimes read (nonblocking) gives no data for 20-30 seconds, then all the data arrives (none is lost). I reduced the number of wifi buffers in menuconfig and this seemed to help this problem but it is still there, and can get stuck up to 10 seconds even with the minimum number of buffers of 2 (0 dynamic)
The data is stuck long enough that after 2 seconds it's faster to reset wifi and reconnect which leads to making new sockets, eventually os error 23 occurs and I have to reset the processor before I can make any more sockets. socket.close() apparently does not fully relinquish them.
When I close the tcp socket from the remote, no exception is thrown so that micropython code is aware of broken connections. I am forced to timeout on data. send and recv don't work properly for detecting broken connections either. I found uselect.poll does not produce socket error and hangup events.
Using udp sockets did not reduce latency but at least the connection never gets "stuck" so I am forced to use udp sockets where normally tcp sockets would also work ok. Despite this, sometimes even udp packets are delayed by over a second.
Any suggestions for micropython settings or in general what can be done to get low latency low bandwidth wifi working?
First I changed my access point settings in hostapd.conf. I lowered dtim_period=1 and this made a big difference for the esp32 despite not really affecting other devices. I wonder if the esp32 would not need this and could work with slower beacons (lower sleep power) if the driver were modified?
I found with tcp sockets and low through put of 100-200 bytes/s, the driver gets "stuck" and sometimes read (nonblocking) gives no data for 20-30 seconds, then all the data arrives (none is lost). I reduced the number of wifi buffers in menuconfig and this seemed to help this problem but it is still there, and can get stuck up to 10 seconds even with the minimum number of buffers of 2 (0 dynamic)
The data is stuck long enough that after 2 seconds it's faster to reset wifi and reconnect which leads to making new sockets, eventually os error 23 occurs and I have to reset the processor before I can make any more sockets. socket.close() apparently does not fully relinquish them.
When I close the tcp socket from the remote, no exception is thrown so that micropython code is aware of broken connections. I am forced to timeout on data. send and recv don't work properly for detecting broken connections either. I found uselect.poll does not produce socket error and hangup events.
Using udp sockets did not reduce latency but at least the connection never gets "stuck" so I am forced to use udp sockets where normally tcp sockets would also work ok. Despite this, sometimes even udp packets are delayed by over a second.
Any suggestions for micropython settings or in general what can be done to get low latency low bandwidth wifi working?