Watchdog unhappy with long requests #139
-
Hi Mathieu, |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 3 replies
-
Hello,, Fyi I am also developing solar routers:
YaSolR is the most optimized open-source solar router as you will be able to read. I've developed many libraries specialized around ZCD pulse analysys. (https://github.com/mathieucarbou/MycilaPulseAnalyzer), jsy, pzem, etc It uses a PID controller at a rate of more than 3 adjustments per second. You'll find them on my GitHub profile. For you questions, just know that there is no issue in the ESPAsyncWebServer Library or Arduino Json, but only in user code. FreeRTOS is not a preemptive OS so your tasks, even if they have some priority, have to be co-operative. Also, as a general rule, never do big operations in a handler or callback, whether it is a mqtt, async webserver or other one. You must find a way to redesign your code to adhere more to the Arduino spirit of doing things with the loop, and if necessary introducing tasks. MycilaTaskManager is a library I've made which can help you for that. Good luck! |
Beta Was this translation helpful? Give feedback.
-
Do not use stream responses to send back json data and do not yield. Also, do not yield: building a Jason document is a fast operations so if you yield it potentially stop a handler which has to be executed fast to let another task with higher priority execute. |
Beta Was this translation helpful? Give feedback.
-
https://github.com/erwan-privat/rbr-magnac/blob/master/ServeurWeb.cpp#L97 Same problem: I think that what you wanted to do is improve memory usage |
Beta Was this translation helpful? Give feedback.
-
https://github.com/erwan-privat/rbr-magnac/blob/master/ServeurWeb.cpp#L168 What happens if your screen is updated on the background while you are reading the pointer ? |
Beta Was this translation helpful? Give feedback.
-
https://github.com/erwan-privat/rbr-magnac/blob/master/ServeurWeb.cpp#L317 With this Library there is a more optimal way to send big json documents That's what we use in ESP-DASH which is able to send quite big websocket buffer (more than 6-8k) from a json documents. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for your review, that was very helpful. |
Beta Was this translation helpful? Give feedback.
-
Here is an example on how to generate on-the-fly and send huge json response in chunks using only a small portion of WebServer's buffer without any intermediate date copies. |
Beta Was this translation helpful? Give feedback.
-
You are right, Matheiu, async nature of chunked response should be kept in mind at first place. However this comment of mine is of something different. I do not remember the details, it is related to dereferencing floats in |
Beta Was this translation helpful? Give feedback.
-
I was thinking about something similar that time ago but came with nothing solid. The problem is that |
Beta Was this translation helpful? Give feedback.
-
I ended up doing that: https://github.com/erwan-privat/rbr-magnac/blob/6407b36dd2e272d73b8db5dd5e79874999defef5/ServeurWeb.cpp#L120 I do think there is a need for a simpler API, I am not satisfied with the process of coding with callbacks as it is needed now. I used some weird switches blocks before using default buffer size for chunks. I know I had to code a chunked delivery of html and script in this case for example, but a proper API relying on your response automagically would be nice. Especially one compatible with e.g. ArduinoJson static buffer, because I apparently don't understand it right now. edit: messed up a copy-paste. |
Beta Was this translation helpful? Give feedback.
https://github.com/erwan-privat/rbr-magnac/blob/13cef33ea92807c50af5a0d225d38c5b9f0eba83/ServeurWeb.cpp#L63
Do not use stream responses to send back json data and do not yield.
Here, you are just accumulating data in memory which is not streamed but sent at once over the Network when the handler finishes.
Also, do not yield: building a Jason document is a fast operations so if you yield it potentially stop a handler which has to be executed fast to let another task with higher priority execute.