esphome / ESPAsyncWebServer

Async Web Server for ESP8266 and ESP32
81 stars 62 forks source link

Add queueLength() #38

Open MoonModules opened 2 months ago

MoonModules commented 2 months ago

To know how full the client queue is - and do only 'lossless' things if the queue is not too full

ewowi commented 2 days ago

just a few comments ;-)

Hi Mathieu, thx for your response, sounds like I should try this repo! - Which I am doing now ;-)

queueLen() works !!

However, I get a few use of deleted function errors like this:

src/Sys/SysModWeb.h:44:45: error: use of deleted function 'AsyncWebSocket::AsyncWebSocket(const AsyncWebSocket&)'
     AsyncWebSocket ws = AsyncWebSocket("/ws");

Any idea what can cause this? I define ws and server in a class like this:

image

That isn't the problem hopefully, or is defining this globally required?

mathieucarbou commented 2 days ago

However, I get a few use of deleted function errors like this:

That's not normal... Did you import AsyncWebSocket.h ? (That was incorrect sorry)

I would need to see more of your code... This is something related to the recent split to move implementation code in cpp files, but I don't understand why I don't saw it in the many projects I have.

ewowi commented 2 days ago

I created a branch in my repo which moves from the esp home to your repo. You can see the complete log here:

https://github.com/MoonModules/StarLight/actions/runs/11113157238/job/30876843828

this is the branch: https://github.com/MoonModules/StarLight/tree/mc-eaws-test ws is defined here: https://github.com/MoonModules/StarLight/blob/mc-eaws-test/src/Sys/SysModWeb.h

Let me know if you need more info, thx for looking into this, Ewoud

Oh and including AsyncWebSocket.h indeed made no difference, and moving the vars out of the class also resulted in the same errors

mathieucarbou commented 2 days ago

I created a branch in my repo which moves from the esp home to your repo. You can see the complete log here:

https://github.com/MoonModules/StarLight/actions/runs/11113157238/job/30876843828

this is the branch: https://github.com/MoonModules/StarLight/tree/mc-eaws-test ws is defined here: https://github.com/MoonModules/StarLight/blob/mc-eaws-test/src/Sys/SysModWeb.h

Let me know if you need more info, thx for looking into this, Ewoud

Oh and including AsyncWebSocket.h indeed made no difference, and moving the vars out of the class also resulted in the same errors

This is not right:

    WebSocket ws = WebSocket("/ws");
    WebServer server = WebServer(80);

=>

    WebSocket ws("/ws");
    WebServer server(80);

You are relying on an inexisting copy constructor.

Sae error above for Psychic (side note; I am one of PsychicHttp dev also)

ewowi commented 2 days ago

Hey thanks for your help!

That makes sense if ws and server is defined outside a class, but within a class I thought this was the way to do it. But maybe just not possible to define it inside a class? (although esp home version 'accepted' it - but making copies ...)

I now did it like this:

image

Diff is here: https://github.com/MoonModules/StarLight/commit/06423f84fe84d5b52a45d47a3bb85986745d0f2f

I then had new errors, mainly related to for (auto client:ws.getClients()) I use the auto : syntax and added an &. But maybe this is not your recommendated way. See the latest code, specially here:

https://github.com/MoonModules/StarLight/blob/06423f84fe84d5b52a45d47a3bb85986745d0f2f/src/Sys/SysModWeb.cpp#L424-L459

Error log here: https://github.com/MoonModules/StarLight/actions/runs/11120233580/job/30896848815

And yeah I am investigating for a while which ws server is the best to use, see also some remarks / comments I have in my platformio.ini. Tried also PsychicHttp but never finished that POC. So if you work on both, which one to choose ? ;-)

mathieucarbou commented 2 days ago

Choose the one you prefer!

I am a heavy contributor / collaborator of Psychic: at the moment, we are preparing v2 which will be an API rework and won't be compatible with v1. A lot of perf issues and bugs are fixed. Psychic is not yet on par with ESPAsyncWebServer in terms of features m, and this is partly due to the limitations of the esp-idf API used behind. Also, it does not have years of history behind it...

In terms of flag usage and memory footprint, ESPAsyncWebServer is better than Psychic and also better than Arduino Webserver. But it does not support https.

For your issue, it is possible that you need to change a little your code if you are doing more advanced things like using the client API because we had to change the internal structure used to store clients for better perfs. So yes use references, always avoid copies.

Most of perf issues often lies in the user code or how a library is used ;-)

mathieucarbou commented 2 days ago

Also I am more concerned about this const issue which might be related to that:

https://github.com/mathieucarbou/ESPAsyncWebServer/blob/main/src/AsyncWebSocket.h#L354

Can you please open a discussion in the right projet so that we stop hijacking ESPhome 's PR ?

Also maybe try to fix the warnings: there are so many 😅

Thanks!

mathieucarbou commented 2 days ago

@ewowi : you can upgrade to 3.3.7 : it includes the fix to be able to iterate over clients in a non-const way to call send methods. This limitation was there since previous forks.