-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add support for sending realtime UDP frames #71
Conversation
@magicus You will recognize these commits. :-D |
@rec Thanks for trying to revive the code! I don't know what's up with the typo, I must have made some unintentional search/replace before committing. I'ts good to know the code still easily applies and works. However, the problem with getting it into mainline was more the high-level comments from @scrool. I really should address those, but when the holiday season ended, my Twinkly got stowed away, and my spare time got diverted toward other interests. I don't care much about credit; if you can get my code fixed so that @scrool accept it, that's fantastic. Otherwise I guess it will lay dormant until late November, or longer... |
Nothing yet! I started a new pull request.
Worst case, I'll fork the repo and rename it something like
tled: T̶o̶m̶'̶s̶ Twinkly LED.
…On Mon, Apr 26, 2021 at 2:10 PM Magnus Ihse Bursie ***@***.***> wrote:
@rec <https://github.com/rec> Thanks for trying to revive the code! I
don't know what's up with the typo, I must have made some unintentional
search/replace before committing.
I'ts good to know the code still easily applies and works. However, the
problem with getting it into mainline was more the high-level comments from
@scrool <https://github.com/scrool>.
I really should address those, but when the holiday season ended, my
Twinkly got stowed away, and my spare time got diverted toward other
interests.
I don't care much about credit; if you can get my code fixed so that
@scrool <https://github.com/scrool> accept it, that's fantastic.
Otherwise I guess it will lay dormant until late November, or longer...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#71 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB53MQ6YNOKW6AMJCBR5HLTKVJ37ANCNFSM43EBDB4Q>
.
--
/t
PGP Key: ***@***.***
*https://tom.ritchford.com <https://tom.ritchford.com>*
*https://tom.swirly.com <https://tom.swirly.com>*
|
For your information, I have in turn taken your code and debugged and tweaked it some more. I will just polish it before updating my previous pull request, with this fix included. In my version I actually suggest to put it back into control.py - I read scrool's comments carefully (had to read them several times really), and think I now understand what he means: rt-support need not be in its own file. Its only that control.py don't do any low level communication itself, but out-sources this to the Session class which takes care of the restful stuff. Similarly, the UDP-socket stuff should also be out-sourced, and there is already a file udp_client.py included which can do this. So similar to the ControlInterface creating a session member, it now also creates an udpclient member (lazily, when needed) which takes care of the socket communication. I had to tweak it a little to work on both pyton-2 and python-3, and add the version 2 protocol (which by the way appear to be wrong in the docs). I just posted a test-example of my version of your code in #81 (there still using the socket directly, and not through udp_client though). Best Regards (By the way, Magnus, I live in Stockholm too.) |
Whoa, good news!
When you say "Debugged", was there a bug in my code? I'd love to know - it
was working here, and I hate little surprises. :-D
Are people really using Python 2 for new development?? :-o
If you'd like a b̶r̶u̶t̶a̶l̶ thorough code review, let me know.
I am *not* in Stockholm, but I'm in your timezone. Greetz from Amsterdam!
…On Sun, Sep 26, 2021 at 9:25 PM Anders-Holst ***@***.***> wrote:
Hi @rec <https://github.com/rec> and @magicus <https://github.com/magicus>
,
For your information, I have in turn taken your code and debugged and
tweaked it some more. I will just polish it before updating my previous
pull request, with this fix included.
In my version I actually suggest to put it back into control.py - I read
scrool's comments carefully (had to read them several times really), and
think I now understand what he means: rt-support need not be in its own
file. Its only that control.py don't do any low level communication itself,
but out-sources this to the Session class which takes care of the restful
stuff. Similarly, the UDP-socket stuff should also be out-sourced, and
there is already a file udp_client.py included which can do this. So
similar to the ControlInterface creating a session member, it now also
creates an udpclient member (lazily, when needed) which takes care of the
socket communication.
I had to tweak it a little to work on both pyton-2 and python-3, and add
the version 2 protocol (which by the way appear to be wrong in the docs). I
just posted a test-example of my version of your code in #81
<#81> (there still using the socket
directly, and not through udp_client though).
Best Regards
Anders Holst
(By the way, Magnus, I live in Stockholm too.)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#71 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB53MV4VJKHAENMMCR3INTUD5XRZANCNFSM43EBDB4Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
--
/t
PGP Key: ***@***.***
*https://tom.ritchford.com <https://tom.ritchford.com>*
*https://tom.swirly.com <https://tom.swirly.com>*
|
Well, I don't know. But it says in the requirements for contributing to xled that it should be compatible with python-2. I suppose the idea is that some people have some separate hardware for playing with IoT, maybe with limited performance and not connected to the external web and seldom upgraded, and xled should work for them too out of the box, even if they have an old python. I you have made major hacks on your system, upgrading may be a pain.
Well, I don't want to focus on the bugs of course - rather thank you again for providing the code, since I am not a communication guy and would not have figured out myself how to assemble those packages, nor how to use a socket. Two bugs affecting the "version 3" protocol (you probably only use the "version 1" on your side so you didn't notice.):
Then two adjustments to make it work in python-2:
And finally, as Scrool also pointed out:
That's very kind of you, maybe I will. I'm packaging it up for a pull request but need some more time. |
On Mon, Sep 27, 2021 at 8:14 PM Anders-Holst ***@***.***> wrote:
Are people really using Python 2 for new development?
Well, I don't know. But it says in the requirements for contributing to
xled that it should be compatible with python-2. I suppose the idea is that
some people have some separate hardware for playing with IoT, maybe with
limited performance and not connected to the external web and seldom
upgraded, and xled should work for them too out of the box, even if they
have an old python. I you have made major hacks on your system, upgrading
may be a pain.
I spent a little time but I couldn't find even one piece of hardware that
didn't support Python 3, which has been out for 11 years now...
Once Python 2 went officially end of life, ten years after Python 3, I
stopped supporting it in my code. And having to support both makes your
code less reliable, as you can see below.
Lecture over! :-) If the codebase supports 2, then we should too.
was there a bug in my code?
Well, I don't want to focus on the bugs of course - rather thank you again
for providing the code, since I am not a communication guy and would not
have figured out myself how to assemble those packages, nor how to use a
socket.
But if you want to know, to adjust the code on your side:
Two bugs affecting the "version 3" protocol (you probably only use the
"version 1" on your side so you didn't notice.):
- First, packet becomes a list and not a "bytes" string on line 63, so
sock.send chokes on line 66.
- Then, packet_size is the number of bytes, not the number of pixels,
so should not be divided by bytes_per_led on lines 59,61,62.
All that code is new to me, so I'm relieved.
Then two adjustments to make it work in python-2:
- bytes([num_leds]) means the same as str([num_leds]) in python-2,
neatly producing the string '[250]' which was not intended. Lines 54 and 64.
This is because of the awfulness of Python 2 strings. :-D
- for some reason "with socket... as sock" does not work in python-2
but I don't know why so I just replaced it.
Well, that's a little bad. That means that the socket won't get closed at
the end of that statement. On Linux, that shouldn't be a problem, but on
Windows, open file handles can last for a surprisingly large amount of time.
And finally, as Scrool also pointed out:
- The condition for when to use what protocol is wrong. Really, you
should have used version 3 yourself and not version 1 (assuming you have
generation II with a fairly updated firmware)... Version 1 is only for
generation I, version 2 is for older firmware of generation II and version
3 for newer firmware. To your defense though, there seem to be a bug in the
documentation for version 2: I had to add an extra null byte after the
access token to make it work. And Twinkly appear to be mostly backward
compatible, so version 1 and 2 still works for version 3 devices.
Very instructive.
If you'd like a b̶r̶u̶t̶a̶l̶ thorough code review, let me know.
That's very kind of you, maybe I will. I'm packaging it up for a pull
request but need some more time.
It might be that the maintainer isn't going to review this pull request.
We could consider starting a fork, in that case...!
…--
/t
PGP Key: ***@***.***
*https://tom.ritchford.com <https://tom.ritchford.com>*
*https://tom.swirly.com <https://tom.swirly.com>*
|
I have reviewed #67 and I don't see my issues addressed in that nor this PR. |
Hi Pavol, nice to hear from you! As mentioned, I am weaving this into my pull request #80 (making it even more huge), and I think I have managed to meet most of your concerns. Just hang on a little, I'm in the polishing phase. Best Regards |
Cool! Glad this is still a going concern, and thanks for your work!!
…On Tue, Sep 28, 2021 at 12:05 PM Pavol Babinčák ***@***.***> wrote:
It might be that the maintainer isn't going to review this pull request.
We could consider starting a fork, in that case...!
I have reviewed #67 <#67> and I don't
see my issues addressed in that nor this PR.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#71 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB53MWEEZOF7YN6ZPRHA4DUEGHOPANCNFSM43EBDB4Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
--
/t
PGP Key: ***@***.***
*https://tom.ritchford.com <https://tom.ritchford.com>*
*https://tom.swirly.com <https://tom.swirly.com>*
|
I have now polished, documented, tested, and committed my changes including the real-time support in pull request #80 . If you fell like it and have the time, there is one thing I would need some help with though, related to the real-time stuff: The interactive color picker that is included in the pull request. It is an example of how the real time interface can be used. However, it is based on matplotlib, and I sometimes have a problem to make platform independent code with matplotlib, so I would need help to check if it looks right. If so, you need to download my branch, and then try "python -m test_colorsphere". Make sure your leds are connected. You should then on your computer see a window with a picture of a colored sphere. It is a depiction of the color body. Rotate it by dragging on the surface. Select a color by clicking the surface. Quit by pressing q in the window. If it looks ugly, take a screenshot and send me back. But if you don't have time, don't worry, I'll test it myself at some different platforms. |
Intended to replace #67, tweaking to get rid of the typo!