-
Notifications
You must be signed in to change notification settings - Fork 555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uno R4 Wifi freezing... #909
Comments
According to this thread : I decided to remove experimentally some small delays of 10ms that I had in my loop, and notice big improvement. I may still not be able to connect two clients at the same time, but at least the first one seems to be stable. I can even reload the page without freezing my box. And if I close it first, then I am able to re open it. With a few words, the first connected client works fine. (...at the moment) Thanks to @furdog |
And according the latest reply from Markus @Links2004 regarding the reasons to avoid a delay, i would like to ask Markus if a heavy loop (from calculations or serving multiple web pages or even too many serial.prints) could have the same luck with delay command or not Thanks for your time |
yes any think that takes a long time can have the same affect, a delay is a do nothing for x. what may help is to make sure that all open messages a handled before you do the heavy calculations. a other option is to place the heavy calculations in a dedicated thread. |
Parallel execution attached on a core was my fist thought but unfortunately its not available on UNO R4. What I've noticed also is that a weak WiFi signal can also cause the same issue. In other words, if you want to have a flawlessly working websocket server, you need to keep your box as much free as possible. Btw, something else that it maybe important... I tried to reduce WEBSOCKETS_SERVER_CLIENT_MAX from 5 to 1 and prevent my setup from crashes etc, but after compilation my Uno r4 is freezing while entering to main loop. |
have you enabled the debug output of the websocket lib? if the R4 has printf support then its as easy as setting the arduinoWebSockets/src/WebSockets.h Lines 46 to 51 in 7a4c416
if this not the case then a custom function can be called via defining |
Unfortunately there is no printf for serial on UNO R4 :( |
ok that makes it a bit harder to see whats going on, but may try: #define DEBUG_WEBSOCKETS(msg) \
{ \
Serial1.print(msg); \
Serial1.flush(); \
} with that we can at least get a idea where in the code the problem is, no details of what happening but by searching the msg in the code we can at least get a hint. |
You mean the issue regarding the weak signal or regarding WEBSOCKETS_SERVER_CLIENT_MAX ? |
we can look at both, but make sure to clearly label the logs and conversation. |
Its sounds maybe stupid question but since now I am using the Arduino Cloud Editor how can I set there a compiler debug switch ? |
good question, have never used it. |
I will put WebSockets.h and WebSocketsServer.h inside my project so I will be able to edit the defines. Like this: `#include "WebSocketsVersion.h" #ifndef NODEBUG_WEBSOCKETS #ifndef DEBUG_WEBSOCKETS |
my bad, try: #define DEBUG_WEBSOCKETS(msg, ...) \
{ \
Serial1.print(msg); \
Serial1.flush(); \
} |
Unfortunately there's no
|
There so many things that could go wrong here.
If you use heavy computing that blocks other tasks for excessive amount of time, i would recomend you to use some kind of coroutines, duff devices, computed gotos, callbacks, or state machines, or just plain conditionals. It takes some effort to implement, but in single threaded applications it's always good to split monolith tasks into smaller ones, so they work very limited ammount of time. for example: void loop() {
//calculation-heavy routine, takes a lot of time to execute
for (int i = 0; i < 100000; i++) {
some_sum += some_calculation();
}
//do something with some_sum...
...
//other tasks
...
} This "for" loop will take huge amount of time to execute, so its better to rewrite it like this: void loop() {
static int i = 0;
//Just a simple conditional which takes almost no time to evaluate
if (i < 100000) {
some_sum += some_calculation();
i++;
} else {
//do something with some_sum..
...
i = 0;
}
//other tasks
...
} These are only examples how to write efficient code on single-threaded devices. |
I put it in the beginning of my code before loading the websocketsserver.h and here is what I got:
Any idea???? |
try |
Thanks for your time first of all. Here is what i have then:
Do i have to change anything and in websockets.h ??? |
It says that va_printf is not defined. I suggest you to create separate .h file with all the definitions provided and include it in all .cpp .ino or in common header files at the very start. |
When I paste the code before #include <WebSocketsServer.h>
Now cannot recognize WStype_t Here is my code: `#include <stdarg.h> // Required for va_list, va_start, va_end size_t va_printf(const char *format, ...) { #include <WebSocketsServer.h> ` |
You did everything right, it's just Arduino auto-prototyping messes with some definitions. It's very sneaky and odd behaviour. Tho it could be fixed with some manual prototyping, but i suggest you to move all your code from yourprojectname.ino into some separate .cpp file, then add |
I created a debug.h file : ``#include <stdarg.h> // Required for va_list, va_start, va_end size_t va_printf(const char *format, ...) { And then I managed to include it before WebSocketsServer.h : `#include "debug.h" Now the program compiles without any issue but unfortunately nothing coming on serial monitor :( Thanks for your time |
Are you sure that If you just define it inside your main project file it will not have any effect on the library behaviour and thus it will not output anything. Sorry, I was unclear early. My original statement brought confusion:
This is pure bullshit from me. I meant that if you copied ALL files from arduinoWebSockets into your project, you must make sure you don't include the original library, so arduino builds your changed copy. To make it all easy, just fork
|
I did but unfortunately no debug messages comes into my serial console :( |
Hello again @Links2004 Since I was not able to debug your library with Uno R4, Is there any thought on how can I play with TCP / Network stack so I check if I can have any improvement regarding my issues? Once again, thanks for your time |
does the Uno R4 has |
In this post says that could work. Check this out: However, even when I add the following into my code: `#include <stdarg.h> // Required for va_list, va_start, va_end size_t va_printf(const char *format, ...) { And change the line 53 of your WebSockets.h to:
Unfortunately it does not gives me anything on my serial console :( I really would like to participate for solving the issue on Uno R4 because currently your library is the only one that works with is box. |
Hi @leosoftGR Just tried this and seems to work. hope it helps
|
have created a branch platformio.ini example:
|
I moved my project to a local arduino ide 2.3 and a platform.txt file created in the same directory of my project. So I added: Then, on line 49 of WebShockets.h changed printf to print And then compiled.... All ok but still no debug output in my serial console :( Am I that much stupid or I miss something else? |
I managed to put your code on line 53 of WebShockets.h and then compile it. Nothing came to my console. Do I have to declare something else in platform.txt ? |
Screenshot is from Arduino IDE. baud rate 115200 |
Finally I managed to solve my issue. What I did is to completely uninstall IDE and reinstall it with re-downloading of libraries. Then, the solution of @kakopappa worked flawlessly. And therefore, here is my debug output for @Links2004 `... Server: arduino-WebSocketsServer Upgrade: websocket Connection: Upgrade Sec-WebSocket-Version: 13 Sec-WebSocket-Accept: lJEhwR9fhifuI5cyBDHpestib4Q= [write] n: zu t: 190 Server: arduino-WebSocketsServer Upgrade: websocket Connection: Upgrade Sec-WebSocket-Version: 13 Sec-WebSocket-Accept: cJjg18claBZiPxj1wqYbsKpgJbI= [write] n: zu t: 190 In the above test, I connected successfully with my first websocket client, and then tried to connect a second one and my Uno R4 freezed..... |
the logs show 2 web socket clients connecting one after the other, which look mostly normal. the strange part is that there is a TCP client connecting and disconnecting all the time. see all the:
is the TCP server of the R4 always saying that it has a new client? |
This is my test routine: void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length){ Have no idea why there are disconnections... |
Hello all,
I am using an Uno R4 wifi as a websockets server and I am experienced a strange issue. Whenever I reload my webpage (...containing javascript websockets client) or whenever I try to connect a second client to my arduino, this completely freezing. I thought it might be a memory issue and I tried to create an empty project for testing but same results. Of course I am using the latest 0.4.1 firmware.
Another test i did, was to install a websockets client tester plugin to chrome so, I could try to connect directly from my browser without using my buildin webpage but still the same.
Also tried to reduce the WEBSOCKETS_MAX_DATA_SIZE from webshocket.h as an experiment but still no luck.
Any ideas??????
The text was updated successfully, but these errors were encountered: