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
60 stars 11 forks source link

HTTP interface shows one light twice? #4

Closed fribse closed 2 years ago

fribse commented 2 years ago

Hey there

I just tested the http daemon, it seems to show the same light twice: image If I try to connect to the one that says 'no' it shows:

[09:08:03] - Successfully linked to light 1 [NEEWER-SNL660] MAC Address: DF:88:56:D0:72:A8
[09:08:03] - Attempting to link to light 2 [NEEWER-SNL660] MAC Address: DF:88:56:D0:72:A8
127.0.0.1 - - [06/Dec/2021 09:08:10] "GET /NeewerLite-Python/link=2 HTTP/1.1" 200 -
[09:08:10] - Processing HTTP arguments
['link', '2']
Exception in thread htmlProcessThread:
Traceback (most recent call last):
  File "D:\Python\lib\threading.py", line 973, in _bootstrap_inner
    self.run()
  File "D:\Python\lib\threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "D:\neewer\NeewerLite-Python.py", line 1013, in processHTMLCommands
    loop.run_until_complete(connectToLight(selectedLights[a], False))
  File "D:\Python\lib\asyncio\base_events.py", line 618, in run_until_complete
    self._check_running()
  File "D:\Python\lib\asyncio\base_events.py", line 578, in _check_running
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
D:\Python\lib\threading.py:975: RuntimeWarning: coroutine 'connectToLight' was never awaited
  self._invoke_excepthook(self)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
[09:08:13] - Error linking to light 2 [NEEWER-SNL660] MAC Address: DF:88:56:D0:72:A8
taburineagle commented 2 years ago

That's odd - I'd say the discover function ran twice that time, because it shouldn't have found the same light twice in one discovery... I'll check that out when I get a chance though. If you run this codebase again, does it always detect the same light twice?

fribse commented 2 years ago

I've just gotten my 480RGB, and now that is detected twice. That might be because of 'channel' settings on the light. It was set to channel 5, and then it didn't want to connect. I then changed it to 0, and then it connected. I've now changed it to 1, and it still connects. If I shut down the program, and starts it again it finds the lights, and now only shows 1 of each. I can see that when I turn it off in the windows app, it shows a flashing clock on the back, which (if I recall right) is different from when doing it from the android app

taburineagle commented 2 years ago

Huh... - interesting - yeah, that's how the iOS app works too, when you just close it, the light stays connected. I think that's because the Neewer app keeps a persistent link to the light, so closing it (not quitting out) is just like minimizing NeewerLite-Python in Windows - it's not on screen, but they're still linked together. If you force quit out of the Neewer app (at least in iOS), then the light's icon starts blinking again as if it's been unlinked in Nl-P. Quitting out of the program (not the app) tries to sever that link before completely closing, that's why it shows the "Successfully unlinked from light..." lines in the console.

I'm curious about the double-detection, because I have my code structured so that shouldn't happen (it looks for the MAC address of any new lights found, and if it finds that it matches an already existing light, it doesn't add a new instance of that light)

image

...but maybe there's something going on with the channel as you've said, or I may need to structure that section differently. I'll have to look more into this one!

taburineagle commented 2 years ago

OK, I've reorganized that section of code to look more closely at the MAC address (it was scanning the entire list as a whole before, I limited the comparison to only check one element of that list now) - what I believe has been happening on your end is the light has been disconnecting (possibly due to the Bluetooth dongle's range, but I'm not 100% certain on that), and re-finding itself somehow. I tested the new code by scanning for lights, finding 2 of them, walking away with the lights to another room (until the BT icon started flashing), and then rescanning them again. The program finds the lights again, says "these are already in here", but now I've also added the requirement that if a light is found twice, the link is attempted a 2nd time, as Bleak may have lost connection to the original instance of that light.

fribse commented 2 years ago

I'll have to test it this weekend, btw. the 480RGB works perfectly, so you can add that to the list as well :-D Now I need to get a better ring light, I wonder if they have an app controlled one as well :-D

fribse commented 2 years ago

Ahh can't wait, I don't see any lights twice currently, I guess I'll close it, and if it happens again, I'll reopen it.

taburineagle commented 2 years ago

Excellent! Sounds like a plan :)