-
Notifications
You must be signed in to change notification settings - Fork 5
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
No bulbs seen #3
Comments
Hey, thanks for filing an issue! I'll see what I can do to help. Everything in your code snippet looks good to me. One thing you could try, that's hopefully quick, is to call import lazylights
print lazylights.find_bulbs(expected_bubs=1, timeout=60) If it still doesn't work with the exaggerated timeout, we can dig in a little deeper. I will say I don't currently have access to a Windows machine, and I've done no real testing on Windows. It might be the case that the some of the socket options in use don't work quite the same way in Windows -- that's something I could look into.
As an aside on this, the test suite is meant to be run through Nose -- so you'd
Just to be super extra sure, you got the zip file from https://github.com/mpapi/lazylights/archive/2.0.zip (and not master.zip), right?
What do you get when you run |
Hi Matt, Thank you for replying and offering to help. 1- I tried the extended timeout and there was no change. I made sure I could ping and control the pulb first via my iphone app and http API. See output:
2- I had already installed nosetests since the tesT_lazylights wouldn't work without it. I ran nosetests and it just sat there with a "EE" in the output until I cancelled it with a Control-C. It looks like it was running some other python scripts that I wrote in the past. I have no idea what it is supposed to be used for. I would have thought that a test python script would be the thing to run when attempting a test. Maybe I am misunderstanding something. See output below:
3- I didn't use the link you provided. I did the only thing I thought I could do and that was go to the repository at: https://github.com/mpapi/lazylights and then click on "Download zip" and used that to do the setup from. How else would I do it? Where would I get your link from? 4-
|
Are you sure your code supports the new v2.0 firmware? In your credits, you reference the "lifxjs Protocol wiki page " project and I see that it is based on the v1.x firmware. Could this be the issue? |
Okay, I think I understand what might be happening. The support for the 2.0 firmware is only on the 2.0 branch, and it sounds like you're actually running code from the master branch. To get 2.0, you'd either have to use the The master branch still only has 1.x support, mostly because I hadn't done much testing of the 2.0 code. But, yes, the 2.0 branch supports the 2.0 protocol, which I ended up reverse engineering using Now that 2.0 has been out for a while and I've done quite a bit of real-world testing, I can merge the 2.0 branch into master the next time I have a chance, to make things clearer going forward. The repository is definitely in need of some love. :) Thanks again for these reports, by the way -- it's super useful for me to see what's confusing to users, and I'm always glad to see that other people are interested in the project! |
Thanks for clearing that up. I didn't even know about the other branch. So I tried downloading the new zip and running the test script also failed. Thinking it had something to do with having installed the original/master scripts, I deleted all references to lazylights on my computer and started again. This time, I upgraded pip and tried the github method. That didn't work either unfortunately. See output below:
So then I just manually downloaded the 2.0 branch's zip file and tested with that instead. I ran "python setup.py install" and ran the test script with the longer timeout and still got the empty set...
|
If I know the IP and MAC addresses of the bulbs, can't I leverage that to make it work better? I know I can ping the bulbs so maybe the code can be improved to allow that to be specified then it wouldn't have to try (and in my case fail) to find the bulb(s). |
@frakman1 Try changing the broadcast address in lazylights.py to your personal network broadcast address. If your network is 192.168.1.0 with netmask 255.255.255.0 then set it to 192.168.1.255. I tested this on my Raspberry Pi (with Python 2.7) and it works. Also tested on Windows (with Python 3.4 (via 2to3 script) but then i get socket errors. btw, sending state (or power) commands are not reliable with this script. You have to check if the given command were really executed on the bulb by checking the get_state against the executed command. After playing around a bit i created a (dirty) function that does just that: (only power on/off) def setBulbPower(bulbs, power):
for bulb in bulbs:
x = 0
while True:
print(("Re-sending" if x>0 else "Sending") + " power command to " + bulb.addr[0])
lazylights.set_power([bulb], power)
if x>0: time.sleep(1)
print('Retrieving bulbstate from ' + bulb.addr[0])
bulbState = lazylights.get_state([bulb])
if len(bulbState) > 0:
if bulbState[0].power==0 and not power:
print(bulbState[0].label + ' is powered OFF!')
break
elif bulbState[0].power>0 and power:
print(bulbState[0].label + ' is powered ON!')
break;
else:
print('The bulb did not respond yet...')
x = x+1
return I've read somewhere that Lifx Firmware 2 also works with TCP instead of UDP. packets for controlling the bulbs. that would result in a reliable connection... edit: cleaned-up code a bit. |
okay, tcp is only for cloud, which i don't want. So we stick with the UDP protocol. Just saw a python 3 script forked from Lazylights2.0. (by georgwaechter). Tested on windows and has the same, non reliable, functionality. Powering ON 2 bulbs takes 0.02 seconds. (almost every time) @frakman1 my testscript: """
Created by VinzzB on 2015/08/23
-------------------------------
Argument:
1 = power all bulbs
0 = set all bulbs off
-------------------------------
"""
import lazylights
import time
import struct
import sys, string
import binascii
if sys.version_info[0] > 2:
PY3K = True
else:
PY3K = False
def setBulbPower(bulbs, power, timeout=5):
try:
starttime = time.time()
for x in range(timeout): #iterate for timeout seconds max. Stop executing if not all bulbs were found within this time
print("Sending power command to " + str(len(bulbs)) + " bulbs")
lazylights.set_power(bulbs, power)
print("Retrieving State from " + str(len(bulbs)) + " bulbs")
for y in range(20): # ~1sec max
bulbState = lazylights.get_state(bulbs) #Get state from all bulbs given in the args.
if len(bulbState) == len(bulbs): #Did we find all the bulbs? If not, check again...
if powerState(bulbState) == power: #What prowerState do we have? Did the command exceute on all bulbs?
print(getLabels(bulbState) + ' bulbs powered '+ ("ON" if power else "OFF") + '!')
return #exit function
else:
print('Not all bulbs responded yet... Found {0} bulb(s) - Retry {1}'.format(len(bulbState), str(y+x+1)))
time.sleep(0.05)
print("The command timed-out. (" + str(time.time() - starttime) + " seconds)" )
finally:
print("setBulbPower() was executed in %1.2f seconds" % (time.time() - starttime))
return
#Check if all bulbs are powered on or off
def powerState(bulbs):
power = False #Off by default.
for bulb in bulbs:
power |= bulb.power>0 #once True, always True!
print("bulb " + getLabels([bulb]) + " is " + ("ON" if bulb.power>0 else "OFF"))
return power
def getLabels(bulbs):
r =""
for bulb in bulbs:
if PY3K:
r += ("" if r=="" else ", ") + str(bulb.label,'ASCII').split('\x00')[0]
else:
r += ("" if r=="" else ", ") + str(bulb.label).split('\x00')[0]
return r
def createBulb(ip, macString, port = 56700):
return lazylights.Bulb(b'LIFXV2', binascii.unhexlify(macString.replace(':', '')), (ip,port))
if __name__ == "__main__":
#Create our own Bulbs
myBulb1 = createBulb('192.168.0.1','00:00:00:00:00:00') #FILL IN
myBulb2 = createBulb('192.168.0.2','00:00:00:00:00:00') #FILL IN
print('MyBulb1: ' + str(myBulb1))
print('MyBulb2: ' + str(myBulb2))
#append to bulbs list
bulbs = [myBulb1, myBulb2]
#Or discover bulbs
# bulbs = lazylights.find_bulbs(2,0.075,5)
#print('done searching. Found ' + str(len(bulbs)) + ' bulbs')
#for bulb in bulbs: print(bulb)
setBulbPower(bulbs,sys.argv[1] == '1') Edit: and now is see that the power value is going down from 65535 (max) to zero in steps when powering down. (same with On) Now i understand why powering off is taking longer. my script waits until power (brightness) is zero. So my question: can we power down immediately? |
Thank you for the insight and sample code. I will try them out and let you know. 1- I ran this script on my jail broken iPhone's command line/Python prompt and althoug it works sometimes, it was unreliable. I've had varying degrees of success with windows and Mac laptops (Win7 and 10) 2- Regarding powering on and off. I doubt it I the firmware because I wrote an iOS program that uses their/LIFX SDK and it works perfectly and is very responsive. I imagine they use the same functions at the lower level. 3- Did you know that they have release the documentation for their bulbs? Full IP packet protocol so no need to reverse engineer everything. |
What i'm looking for now is a way to see changes in the lightbulbs. If i dim the lights with my phone, my script should see these changes almost immediately. The Lifx app handles that quite well. Just have to figure out how they do it (Do they use polling or just listen to broadcasts/multicasts messages) |
|
I figured out that the your discovery implementation isn't working well. Once you manually add the bulbs (like i did in my testscript) your script actually is reliable. Although UDP isn't reliable by nature, i did not noticed any flaws yet. Luckily i have a stable home network. :-) I just tried an other python script form smarthall. (https://github.com/smarthall/python-lifx-sdk) He actually has a good discovery implementation and his script also listens to incoming messages for bulb changes. (+ it has transition time argument in power method) About the power transition: |
@VinzzB By the way, I've used smarthall's library too and was able to get it to work. |
Hi there,
I tried using the test code in the readme but it returns 0 bulbs even though I have one LIFX bulb up and running and pingable from the prompt. I confirmed that I can control it from the app as well.
This is the code I used ( I printed bulbs to make sure it really is empty in this case):
running it on my windows dos prompt:
What am I missing?
I also tried "python test_lazylights.py" but nothing happened there either.
Thank you
-I am using Python 2.7.5 on windows 7 64bit with a LIFX bulb running latest 2.0 firmware
-I installed lazylights2.0 by downloading the zip file and running "python setup.py install" . The github way didn't work for some reason and gave me a " error: invalid command 'egg_info'" error.
The text was updated successfully, but these errors were encountered: