WiFiEspAT Library - UDP trafic interferes with AT commands?

Hi I am using to above library with an ESP-7 module which is connected to the MCU on Serial1 (hardware).

The program

  1. Sends measurement data with MQTT every second
  2. Sends and receives UDP packets asynchronously

There is a continuous incoming stream of UDP packets even though the program responds to only those that are addressed to it.

The problem begins when AT commands are also sent to the ESP module for example when I periodically check the WiFI connection using:

if (WiFi.status() == WL_CONNECTED)   {   ... }

These AT commands sent to the ESP seem to interfere with the incoming UDP traffic.
Sometimes, the ESP response to the AT command or even some UDP traffic is lost.
There is also some delay in the ESP response to AT commands which makes things even worse.
Eventually the WiFi connection itself is also lost!

The command above is issued once every 5 secs.
Increasing this time, improves performance but still its not perfect.

I then decided to use a "watchdog" timer which prevents interrogation of the WiFi status as long as UDP traffic keeps coming (which means that the connection is OK).
Only if the timer times out, the ESP is asked for status.

I am wondering if there is a better, more efficient way to do this..
I am not even sure how concurrent MQTT transmission affects all this.

Any ideas?

try higher baudrate and/or flow control

Serial1 is at 115200. You mean higher than this?
By Flow control you mean XON /XOFF?

Btw the udp stream itself is only at 9600

https://github.com/JAndrassy/WiFiEspAT#baud-rate-for-communication-with-at-firmware

https://github.com/JAndrassy/WiFiEspAT#uart-flow-control

I guess i will need handshaking ..
But how do you enable cts with hardware serial1 on a particular pin?

we don't know what Arduino you use

I'm using MyghtyCore 1284p

that doesn't support Serial flow control

That means I dont have any other option to improve packet reception performance....