derkarnold / pylifx

A Python library to control and monitor LIFX bulbs
BSD 2-Clause "Simplified" License
19 stars 4 forks source link

Tried running sunset example, got error on net_intf('broadcast'), #1

Closed ThomasWrobel closed 10 years ago

ThomasWrobel commented 10 years ago

Ok, its probably just my setup, as I have purely setup this Python today to try to get my new lifx working. I am not sure this program is even supposed to help me....the Android 4.2 tablet connects to the bulb, but the bulbs doesnt connect to the network. (using WP2 normally, but tried no security, tried channel changing etc). Never connects. I am using the standard mask (255.255.255.0). Is this software supposed to be able to connect even if the bulb has never once managed to connect to the local router?

Anyway, so I thought Id give this a go anyway seeing as am trying absolutely anything.

I setup the software as instructed, didnt seem to get any errors. I went to the IDLE ide, opened "sunrise.py" and went Run>>Run Module

However, this produced an error in the networking.py;

Traceback (most recent call last): File "C:\Users\Wolthera\Downloads\pylifx-0.0.2\pylifx-0.0.2\examples\sunrise.py", line 30, in <module> with LifxController(addr) as bulb: File "build\bdist.win32\egg\pylifx\__init__.py", line 74, in __init__ self._socket = LifxUDPSocket(site_addr, bulb_addr, net_intf, _LIFX_PORT, _LIFX_PORT) File "build\bdist.win32\egg\pylifx\networking.py", line 113, in __init__ LifxSocket.__init__(self, site_addr, bulb_addr, sock, (net_intf['broadcast'], send_port)) KeyError: 'broadcast'

What am I do horribly wrong ? ;)

derkarnold commented 10 years ago

Hi Thomas,

Unfortunately if the bulbs don't even connect to your wifi network, then this script won't work :(.

The error you get in the script is due to a different reason.. you could try out the following in the new

from pylifx import *
[n for n, i in networking.get_interfaces().items() if 'broadcast' in i and 'addr' in i]

Note down one of the interface names you get from this output (in Windows it'll be something like '{E7AC4B71-B6D8-313A-2AF0-8E59D98C4D2B}'. In the surise.py script, replace the line:

with LifxController(addr) as bulb:

with:

with LifxController(addr, intf_name='<interface name from above>') as bulb:

For example, using the above interface name:

with LifxController(addr, intf_name='{E7AC4B71-B6D8-313A-2AF0-8E59D98C4D2B}') as bulb:

Please also make sure addr points to your bulb.

Kind regards,

Deryck

ThomasWrobel commented 10 years ago

Ah, pitty. Kinda wish they just had the bulbs with a usb based setup at this rate ;)

I tried your diagnostic advice, but I guess my python ignorance is holding me up, because it doesnt seem to accept wildcards in the import.

"from pylifx import LifxController" works but "from pylifx import *"

results in a; " 'module' object as no attribute pylifx" error. I tried just modifying the sunrise.py replacing the import with a "*" and got the same thing.

Don't worry too much about helping my make this work, I might come back to it when I get the bulb connection working to start with.

derkarnold commented 10 years ago

Ok, no problem. I'll release a patch for the code to ensure only broadcast interfaces are used by default (my fault really). On 28 Feb 2014 22:57, "ThomasWrobel" notifications@github.com wrote:

Ah, pitty. Kinda wish they just had the bulbs with a usb based setup at this rate ;)

I tried your diagnostic advice, but I guess my python ignorance is holding me up, because it doesnt seem to accept wildcards in the import.

"from pylifx import LifxController" works but "from pylifx import *"

results in a; " 'module' object as no attribute pylifx" error. I tried just modifying the sunrise.py replacing the import with a "*" and got the same thing.

Don't worry too much about helping my make this work, I might come back to it when I get the bulb connection working to start with.

Reply to this email directly or view it on GitHubhttps://github.com/derkarnold/pylifx/issues/1#issuecomment-36403362 .

micolous commented 10 years ago

@ThomasWrobel I've found that the from pylifx import * issue is due to a bug in the code, which I've submitted PR #5 to fix.

derkarnold commented 10 years ago

The new version with this fix has been released on pypi as version 0.0.3.