lasselukkari / aWOT

Arduino web server library.
MIT License
283 stars 41 forks source link

Using ESPAsyncWebServer for better reliability #64

Closed jvoj closed 4 years ago

jvoj commented 4 years ago

Hi, I really like your lib, good work there! Any ideas how to add ESPAsyncWebServer? It should act like normal normal WiFiServer but you dont need to wait in loop() for new requests. Other libraries were easily ported onto that, but I am struggling with this one. Thanks!

lasselukkari commented 4 years ago

I completely misread your comment at first. Here is an updated reply.

ESPAsyncWebServer and aWOT are both web server libraries that do pretty much the same thing. Converting this to use the ESPAsyncWebServer would no really make sense.

In theory this library could use the same async tcp stack as the ESPAsyncWebServer but the conversion is not really possible without really big changes. Also it would at the same time beat the main purpose of this library: being cross platform.

aWOT is cross platform meaning that applications written with it work on any Arduino platform from Uno to ESP32. This is possible because it uses the standard Stream base class instead of any specific web/tcp server implementation. The Stream class is as synchronous as it gets and converting this library to use the same ESPAsyncTCP tcp stack would not make much sense as it would need to be wrapped inside a synchronous api.

I recently did a simple benchmark to compare the write performance of three different esp32 web server libraries. As you can see from the results in many cases the performance differences are negligible. In some cases the synchronous alternative is actually faster.

There is no reason to believe the ESPAsyncWebServer or the ESPAsyncTCP libraries would be any reliable. To be honest there is many reasons to believe the exact opposite.

jvoj commented 4 years ago

Thanks for reply. I of course meant implementing server via ESPAsyncTCP, not via ESPAsyncWebServer which is just alternative to aWOT. My point was that if some part of arduino code uses delay (or some exensive computation) and blocks rest of the loop, aWOT gets stuck also. I see that as anti-pattern for reliable implementations. Implementing it by ESPAsyncTCP would imho solve the problem.

I thought that this can be archieved quite easily, when you take a look into Server.ino example in ESPAsyncTCP, they are getting new clients via async callback on line 67. Something similar to loop() on your lib. But yea that wouldnt be cross platform, nor even more reliable... And if you say its not worth it, I understand...

lasselukkari commented 4 years ago

I would say that it is an antipattern to do anything time consuming inside the http handler. It will make your server slow anyway. If you need to for example read sensors do it periodically and then just read the stored results in the http handler. If you need to trigger some long lasting operation instead set a flag and do it after http handler has been executed. If you really need long lasting connections use websockets instead.

lasselukkari commented 4 years ago

If you wonder why my initial response was so way off I thought it was for another project. I had two github tabs open at the same time and got mixed up with the repos... Anyway thanks for the positive feedback in your initial message