Closed asteinh closed 4 years ago
it is in WiFiUDP::readRxData.
size_t l = serial->readBytes(rxBuffer, len);
if (l != len) // timeout
return TIMEOUT;
readRXData is called EspATDrv to read the data after +IPD.
this problem is usually a serial buffer overflow. bytes get lost and readBytes then can't retrieve the advised count of bytes and times out.
it is possible, that with a delay some packets are dropped so the buffer is cleaned up quickly for the next packet.. check WiFi.getLastDriverError()
for EspAtDrvError ::UDP_BUSY after
Thanks for the fast response! 👏
I'm not sure how to resolve this though. I checked for EspAtDrvError::UDP_BUSY
, which in all cases appears false. When the error occurs it's a EspAtDrvError::UDP_TIMEOUT
.
Is there a remedy for this timeout? I read about changing the Arduino's serial buffer size, but if possible, I'd prefer a solution that doesn't require such changes.
the solution would be UART flow control or fimware's passive mode for UDP. possible workarounds are:
- send less messages
I don't see how this would change anything - it fails to receive a single message already?
- low baud rate. 9600 baud
I successfully tried 9600 baud - but it's too slow for the application, i.e. the time required is too long.
- smaller UDP message
That's unfortunately not an option.
- larger serial buffer
I'll look into this, but it seems (as long as using the Arduino IDE) injecting a custom #define
for HardwareSerial.h
is not as easy as it should be...
somehow I understood the the version with delay is the working one. the serial buffer is 64 bytes. "+IPD,4,64:" and 64 bytes of data is 74 bytes. while the code waits in delay the message is revived to serial buffer and the last 10 bytes are lost.
For an application that runs at a predefined sampling rate, I encountered the following problem: In most cases, when I try to parse a UDP packet, I run into timeout errors, even though the debug output shows all the right sizes. The expected package length is 64 bytes (which is confirmed by wireshark) and the library tries to read 64 bytes, but something seems to go wrong. Even more confusing is the fact that in rare cases everything seems to work, see the debug output below. This seems to depend on the rate at which the packages are coming in...
To reproduce, an Arduino sketch as a minimal working example:
Without the
delay(100);
line everything seems to work as expected. However, with this line, the debug output readsI hope someone has a little hint as to what I am missing or doing wrong here 😅