You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
I had a blast with your wsServer library the last few days. #24
I spend my entire career trying to avoid C so despite decades in IT I only spend a week so far on learning C.
For a project I need to send messages from a browser to a raspberry pi zero w. In turn it drives TMC2209 stepper controllers etc etc.
Your library is indeed a breeze to start with and I have it working nicely receiving binary data.
Now I wonder, is it possible to have an animation loop running while wsServer is doing it's thing?
ws_socket(&evs, 8080);
Hogs the main loop and I can't figure out how I can keep my own code going while we wait for the next message.
Maybe a hook for a callback or a function call so I can push the wsServer loop along manually.
Maybe there is a solution already but after seeing the thread stuff I decided to grease up and see if you have any ideas.
Hi @dinther,
(I'm glad you liked it, it's feedback like this that pushes me forward for keeping this library, thanks =).)
About your issue, yes, you're right. So far, there wasn't any kind of feature that would make the ws_socket non-blocking. With that in mind, the latest commit slightly modifies the ws_socket function signature to:
When the thread_loop parameter is zero, the routine behaves as before; when non-zero, a thread is created to accept new connections, and the function returns right away.
So from now on, a code like the one below would work without problems:
Maybe a hook for a callback or a function call so I can push the wsServer loop along manually.
That would be very interesting. I've seen some libraries using a similar approach, letting the user have full control over connections, receiving messages, and so on. Maybe it's a good feature to support in the future.
Anyway, please let me know what you think of my changes and if they meet what you expect.
Oh man, you're a saint. It's late here in New Zealand but I definitely try the update this weekend and see if I can animate my variables.
I am sending command speeds for multiple stepper motors via your websocket and then onto a TMC2209 which generates it's own step pulses at a commanded rate. But stepper motors need a managed acceleration ramp otherwise they stall. With the loop suggested I can make sure the stepper motor is guided towards the target speed.
Actually, I could not make it work initially and wrote you an elaborate message with code details but every time I thought...hang on let's check this or that as I didn't want to look like an idiot.
Well, all issues were my own fault of course but I got it working thanks to your change. Thank you very much.
I let you know if I find any issues during testing.
Activity
Enhancement: Non-blocking ws_socket option
Theldus commentedon Jul 2, 2021
Hi @dinther,
(I'm glad you liked it, it's feedback like this that pushes me forward for keeping this library, thanks =).)
About your issue, yes, you're right. So far, there wasn't any kind of feature that would make the ws_socket non-blocking. With that in mind, the latest commit slightly modifies the ws_socket function signature to:
When the
thread_loopparameter is zero, the routine behaves as before; when non-zero, a thread is created to accept new connections, and the function returns right away.So from now on, a code like the one below would work without problems:
That would be very interesting. I've seen some libraries using a similar approach, letting the user have full control over connections, receiving messages, and so on. Maybe it's a good feature to support in the future.
Anyway, please let me know what you think of my changes and if they meet what you expect.
dinther commentedon Jul 2, 2021
Oh man, you're a saint. It's late here in New Zealand but I definitely try the update this weekend and see if I can animate my variables.
I am sending command speeds for multiple stepper motors via your websocket and then onto a TMC2209 which generates it's own step pulses at a commanded rate. But stepper motors need a managed acceleration ramp otherwise they stall. With the loop suggested I can make sure the stepper motor is guided towards the target speed.
Thank you so much.
dinther commentedon Jul 2, 2021
I couldn't wait of course :-)
Actually, I could not make it work initially and wrote you an elaborate message with code details but every time I thought...hang on let's check this or that as I didn't want to look like an idiot.
Well, all issues were my own fault of course but I got it working thanks to your change. Thank you very much.
I let you know if I find any issues during testing.
Theldus commentedon Jul 3, 2021
I'm glad you made progress with the library and your use case (which looks very interesting).
Any questions, don't hesitate to ask =).
Theldus commentedon Apr 19, 2022
I am going to close this issue.
Feel free to create other issues whenever you need =).
PS: I created an issue (#47) covering what we talked about a lower-level API, as it's a feature I really want and I couldn't forget to implement.