Renstec / LD2410

Arduino Library to read out and parameterize a HiLink-LD2410 radar sensor.
GNU Lesser General Public License v2.1
15 stars 4 forks source link

ERROR: Too many messages queued #3

Open Kabron287 opened 1 year ago

Kabron287 commented 1 year ago

Compilation in Adruino IDE and in VisualMicro in Release mode leads to many error messages: ERROR: Too many messages queued After compilation in VisualMicro in Debug mode they never appeared, but browser periodically hangs up.

Is there any solution?

Thanks in advance.

Renstec commented 1 year ago

Hello Kabron287,

The reason you are seeing the error message "ERROR: Too many messages queued" is because the example code sends a WebSocket message to the client for every message received from the radar. This can generate a large amount of traffic which the AsyncWebserver library or the client cannot handle, resulting in the error.

To prevent the error message, you can modify the code to check if the WebSocket is available for sending messages before sending each message. However, it's important to note that this may not completely prevent the issue, as some messages may still be lost.

Here's the modified code snippet that checks for WebSocket availability before sending:

void loop() {
  // read must be called cyclically
  if (radar.read()) {
    // check if we can send a websocket message to the client
    if (ws.availableForWriteAll()) {
      if (sendRadarSettings) {
        sendRadarSettings = false;
        wsSendRadarSettings();
      } else {
        wsSendCyclicData();
      }
    }
  }

  ws.cleanupClients();
}

If this does not help, you can also update the Web-Socket connect event. When a Web-Socket client connects to the server, the server sends some initial data to the client, such as the firmware version and radar parameters, wich can also result in the same error because the code does not check for websocket availbility here.

I hope this helps.

Thanks Renstec