taburineagle / NeewerLite-Python

NeewerLite-Python is an un-official cross-platform Neewer LED light control app - written in Python, originally based off of the NeewerLite macOS Swift project by @keefo (Xu Lian)
MIT License
61 stars 11 forks source link

Using NeewerLite-Python with Stream Deck #66

Closed CongaTom closed 11 months ago

CongaTom commented 1 year ago

Hi @taburineagle

I'm having a problem connecting NeewerLite-Python with Stream Deck.

Please excuse my basic questions:

  1. I don't know if I need to run the GUI program to get everything going first.
  2. Either way, I can't control the lights via the HTTP Server Daemon

If I start from scratch, I launch the program in the Terminal using python3 /Applications/NeewerLite-Python-main/NeewerLite-Python.py --http

And this window appears:

Untitled

The bluetooth sign on the 2 lights are flashing, so it's not connecting via bluetooth. However, when I run the GUI, they connect fine and operate well.

When I type in a command, nothing at all happens.

I also don't know where to put the commands for the lights, eg turn off. Do I put them into the Terminal (when I do this, nothing happens), or I put them into an internet browser window (the search times out), or do I put them into the Stream Deck window via System/Website/URL(same)? Or any or all of the above? And I am using my correct private Network IP Address.

taburineagle commented 1 year ago

Yep, all of that looks good, so far. I have a more in-depth tutorial on how to use the HTTP daemon here:

https://github.com/taburineagle/NeewerLite-Python/wiki/(3)---The-HTTP-Server-Daemon

...although I do need to flesh out my documentation! The easiest way to get started with the HTTP daemon is start it in that mode (as you have above), and from the PC you're running the daemon from, visit the URL http://127.0.0.1:8080/NeewerLite-Python/doAction?list to see a quick overview of the lights NeewerLite-Python has access to, to discover new lights, etc. Click on "Scan for New Lights" at the top, wait for the program to find your lights, and then you can use commands similar to the tutorial to change settings on your lights like,

http://127.0.0.1:8080/NeewerLite-Python/doAction?light=(mac address of your light, or number of light, like 1)&mode=CCT&temp=5200&bri=50 - set light 11:22:33:44:55:66 to CCT mode, with a color temperature of 5200K, and set the brightness to 50%

http://127.0.0.1:8080/NeewerLite-Python/doAction?light=(mac address of your light, or number of light, like 1)&mode=HSI&hue=240&sat=100&brightness=100 - set light 11:22:33:44:55:66 to HSI mode, with the hue set to 240ΒΊ (blue), with saturation and brightness set to 100%

http://127.0.0.1:8080/NeewerLite-Python/doAction?light=(mac address of your light, or number of light, like 1)&mode=HSI - set light 11:22:33:44:55:66 to HSI mode, with the default HSI parameters

CongaTom commented 1 year ago

Thanks. That's got me a bit further when I add :8080 into the command!

2 questions:

  1. If I run the program and then quit it by quitting the terminal, I need to shut down the computer totally. If I don't, I get this message that a previous instance still exists. Is there a better way of shutting down the program?
An instance exists already
  1. I can now connect to the lights, but I can't send any commands. When I try for the first time by pasting in the browser window, this happens:
Website view

Note that the Last Sent Value hasn't changed.

1st Attempt

And when I try the second time by pasting in the browser window, this happens:

2nd Attempt

Any ideas about what's going on?

CongaTom commented 1 year ago

... are you there? ...

taburineagle commented 1 year ago

Hi @CongaTom - I'm here... the editing project that I thought turned into nothing had an immediate (and very time-crunched) deadline, so I've been working on that for the past few days to get it done, and I had a bunch of other things I had to finish first. I just got done working on it about 30 minutes ago, so I'm going to relax a little bit before getting back in to programming mode... so here, but a little mentally frazzled at the moment 😁 I'll check into the HTTP issue this week!

CongaTom commented 1 year ago

Thanks @taburineagle , All good. Although I don't have a deadline with this, I'm slowly going through other jobs related to this project, and just keeping things moving forward. πŸ‘πŸΌ

taburineagle commented 1 year ago

Got you, yeah, sorry to be incommunicado for the past few weeks, all of my time's been caught up in this gig. I code as a hobby and not professionally (at least not yet :)), so sadly in programming terms gig > hobby, but I've finalized that now and I'm good to check back in! Give me a day or two to check out the order of issues you have above and I'll see if I can suggest some things to help out.

taburineagle commented 1 year ago

OK, ha, sorry for the delay... again - from what I see in your screenshots, the command you copied and pasted was

doAction.php?light=3;4&off

Which is a valid command, but you don't have a light 3 or 4 in your list of lights to use (the example you posted only had 2 available), so the program has an issue with it, and apparently after it has that issue, it just stops trying everything. Duly noted on my end, as I need to do more error checking to make sure the request connects to a light that's accessible, so I'll look more into that, but a more valid command for your setup you showed me would be

doAction.php?light=1;2&off

As it would affect 1 and 2, the 2 lights in your available lights list. As far as needing to close the computer entirely, that shouldn't be the case. Basically, the way the lock file works is, the program checks for it at launch, and if it finds the file, it'll warn you that you're already running the program. The file stays until NeewerLite-Python itself closes out gracefully, and then it deletes that file on exit, so the next time you'd come into it, the file doesn't exist, and everything goes as it should. To quit out of NeewerLite-Python gracefully, using the HTTP server and Terminal, you have to stop it by typing Ctrl+C into the Terminal window where NL-P is running. To always launch NeewerLite-Python without it looking for that file (it'll start regardless even if the lockfile exists), add --force_instance to the command line, along with your other options.

CongaTom commented 1 year ago

Thanks for getting back to me. Unfortunately, nothing's working. I can adjust the lights on the GUI, and use the Preset Globals, but I can do nothing on the Server Daemon. I've tried 192.'s, 10.'s, 127.'s, with and without *'s I've tried light=3:4, light=1;2 I've tried &off I've tried &temp=3200 It's just ignoring everything....

I use 3 & 4 for the lights because that's the channel number that they have. And I can't change them. And the GUID recognizes them as that. They don't seem to have a MAC address, just a UUID. And I tried using that too.

Also when I put URL's into a browser window nothing happens either. It just times out.

taburineagle commented 1 year ago

Huh - interesting... sorry this is being such a pain in the ass to get working!

OK, so:

Let me do some testing on my end with my Mac OS setup and that VM I made a few weeks back to see if I have issues controlling any of my lights. Also note, NeewerLite-Python doesn't really take channel numbers into account when sending commands - it lists which channel the lights are on, but uses the order the light occupies in the list of master lights to send commands - so the numbers here correspond to the light you're controlling and not the channels:

image

taburineagle commented 1 year ago

OK @CongaTom - I tested everything on my end yesterday and didn't have any program issues with the HTTP server, but, I think I might know one problem that may be coming up. Here is the order of what I did:

taburineagle commented 1 year ago

One thing of annoyance I did notice when I was testing it though was trying to type a URL in the window that's currently showing the list of lights (http://127.0.0.1:8080/NeewerLite-Python/doAction?list) kept kicking me out of typing the new URL due to the refresh timer that I implemented a while back to keep the information in the window more current. To test the URLs, I opened another tab before typing the URL, and sent the command in that new tab. Try that first and see if it helps out at all - I could also look in to writing a routine that stops the refresh timer if you hit a button, allowing easier entries of new URLs.

CongaTom commented 1 year ago

Thanks for that. The following is a long list of what I tried. But in the end it was successful. So you can jump down to near the bottom if you like….

This is what I did:

"Unable to connect Firefox can’t establish a connection to the server at 127.0.0.1:8080."

Safari Can't Open the Page Safari can't open the page "www.127.0.0.1:8080/NeewerLite-Python/doAction?list" because the page's address isn't valid.

I did some research. I found out how to confirm the port, so in the terminal I typed in the following, and got this response:

python3 -m http.server

Serving HTTP on :: port 8000 (http://[::]:8000/) ...

I then typed in Firefox browser window:

http://127.0.0.1:8000/NeewerLite-Python/doAction?

and got an Error response

I then tried:

http://127.0.0.1:8080/Applications/NeewerLite-Python-main/NeewerLite-Python/doAction?

and got the response:

"Unable to connect Firefox can’t establish a connection to the server at 127.0.0.1:8080."

β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

I then tried in my Firefox browser:

http://127.0.0.1:8080/NeewerLite-Python/doAction?discover

and got the response:

Unable to connect Firefox can’t establish a connection to the server at 127.0.0.1:8080.

I then tried:

192.168.1.5:8080/NeewerLite-Python/doAction?discover

The connection has timed out The server at 192.168.1.5 is taking too long to respond.

I then tried:

192.168.1.5:8080/NeewerLite-Python/doAction?discover

β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

I will not give up

β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

I then Quit out of both python icons and the Terminal.

β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

I opened up the terminal, and typed in:

python3 /Applications/NeewerLite-Python-main/NeewerLite-Python.py --http --force_instance

Ok. So that seemed fine. your stuff came up.

in my Firefox browser I typed:

http://127.0.0.1:8080/NeewerLite-Python/doAction?

and a whole lot of stuff came up, but basically It said I need a command after the ? And it gave me a list of actions.

I then typed in:

http://127.0.0.1:8080/NeewerLite-Python/doAction?discover

And it went to "…doAction?List" And it found the lights!!

in the browser I pressed on Global preset 1, then preset 3, then preset 2.

And it was successful!

I then tested an individual light using its GUID:

http://127.0.0.1:8080/NeewerLite-Python/doAction?light=1A0888FE-45A2-869F-8CA6-5896273EDBA9&temp=5200

It worked. It also took the brightness up to 100%, but it worked!

I then used your test:

http://127.0.0.1:8080/NeewerLite-Python/doAction?light=1;2&off

That turned them off!

http://127.0.0.1:8080/NeewerLite-Python/doAction?light=1;2&on

That turned them on!

I then put those two commands into my Stream Deck and they worked!!!!

I then turned everything off. And then back on. I rediscovered the lights, and I found that light 1 and light 2 had swapped around. So, in different sessions, if I want to give set individual directions to the different lights, I need to use the GUID, rather than the ID#.

Yaayyy!!!!

β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

I think I know what might have been going on: Maybe I can't run the Graphical User Interface at the same time as the HTTP Server Daemon. Maybe I can't have them both running. It just took directions from the GUI as it was the first one that was running. OR I didn't have a good enough understanding of how the HTTP Server Daemon worked.

I also noted that when it was running well on the HTTP Server Daemon, there is no Python icon/s in my dock. Just the Terminal icon.

Also just some helpful words of advice: When you're explaining things, please be ULTRA-logical in what you're doing, as people like me who use these programs aren't programmers. We just have to use them. So like, when you say "Ran the HTTP server with this command:" I didn't know what that meant. I didn't know what window to put it into. It could have been either the Firefox Internet Browser window, or the Terminal. Same thing with "Launched the web interface with the URL"

So maybe the manual can be dumbed down even further for people like me.

But thank you so much for hanging in there with me. That was so so helpful. It will help me a lot now.

I also have another question - so brace yourself!! - is there a way to make the lights fade from one state to another state over a period of time eg changing from brightness=100 to brightness=10 over 5 seconds, or purple to green over 60 seconds?

Thanks so much!

taburineagle commented 1 year ago

Ah, excellent - you're welcome! I'm glad you were able to get it sorted out! Ha, duly noted on the tech speak - I was in a bit of a hurry when I typed that up a few days ago, so I'm sorry for being a little less descriptive than I probably should be :) That's good to know though, it's hard sometimes to articulate things in less technical ways, so I'll try to do better with that moving on.

Yes, you can only run one (GUI or HTTP) copy of NeewerLite-Python at a time and have it work with the lights (at least for the moment) - I could look into coding a version in the future where you can launch the HTTP server in the GUI, but that is the case right now. The reason for that is once a Bluetooth connection is made from the program to the lights, you can't re-sync to another connection - once it's linked to one connection, it's linked, until you either unlink (by closing the program or turning the light off). So if you use the GUI, and connect to the lights there, and then run the HTTP server on top of that, none of the HTTP commands are going to run, as the lights are set to use the GUI connection. That's also another reason why I programmed that "you're already running" check when you launch it a 2nd time.

Hehe, another question?! just kidding - πŸ˜† At the moment, that's not possible to do a smooth transition over a period of time, but that is something I want to look in to! To do that properly, the program would have to send a constant set of commands over that time to transition from A to B. So that is something on the agenda, but not quite there yet...

CongaTom commented 1 year ago

Thank you so much for your patience and understanding. And thanks for your explaining. I've learnt a lot. To do a fade/crossfade I'm thinking I might send individual commands to (basically) go up 1, then down 1, then down 1, then up 1, then down 1 ... etc. Copying and pasting into a Streamdeck command. I don't know how long it would make the crossfade go for, but I can try it... There might also be some sort of program in Streamdeck-land that can insert lengths of time in between commands. Anyway, let me know if/when you do it. Thanks again. :-)

taburineagle commented 1 year ago

You're welcome @CongaTom! Yeah, programatically, it wouldn't be hard to send a series of commands to a light over a period of time, like "go from 100% to 50% over the next 5 seconds" or "switch from red to blue in 10 seconds", it'd just be figuring out the logistics of doing so in the code, and how robust the connection from the program to the lights is (if it's a less-than-reliable Bluetooth connection, it wouldn't be able to receive all of the commands the program is sending to it.) Sending one URL command that would do the processing over a time frame would be a lot more reliable than sending 50 individual HTTP commands over the same time frame, not that you couldn't do it that way, it would just be a lot more streamlined that way... ha, more tinkering needs to be done on my end for that though 😊

CongaTom commented 1 year ago

Good ideas there. Thanks for the suggestions. πŸ‘πŸΌ