jnyjny / blynclight Goto Github PK
View Code? Open in Web Editor NEWPython bindings for the Embrava BlyncLight family of products.
License: Apache License 2.0
Python bindings for the Embrava BlyncLight family of products.
License: Apache License 2.0
I updated my virtualenv that includes blynclight
to v0.8.0 using Pip. Afterwards, I get an import error both in ptpython
and the same thing when using the CLI tool.
>>> from blynclight import BlyncLight
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "$HOME/python-virtual-environments/rgb_led_status/lib/python3.8/site-packages/blynclight/__init__.py", line 34, in <module>
from .blynclight import BlyncLight
File "$HOME/python-virtual-environments/rgb_led_status/lib/python3.8/site-packages/blynclight/blynclight.py", line 4, in <module>
import hid
File "$HOME/python-virtual-environments/rgb_led_status/lib/python3.8/site-packages/hid/__init__.py", line 30, in <module>
raise ImportError(error)
ImportError: Unable to load any of the following libraries:libhidapi-hidraw.so libhidapi-hidraw.so.0 libhidapi-libusb.so libhidapi-libusb.so.0 libhidapi-iohidmanager.so libhidapi-iohidmanager.so.0 libhidapi.dylib hidapi.dll libhidapi-0.dll
I'm looking into what's going on.
My update went from:
Working on a script to integrate Jabber and the Blync Light via Python.
When running the script, if no light is plugged in I received the following output from
Code:
light = BlyncLight.get_light()
print ("Light Status:\n",str(light))
Produces:
Light for 0 not found.
If I plug in the light and re-run my code, I get what I assume is the proper output:
Device: 0x2c0d:0x000c
0x00ff : red
0x0000 : blue
0x0000 : green
0x0000 : off
0x0000 : dim
0x0001 : flash
0x0000 : speed
0x0000 : music
0x0000 : play
0x0000 : repeat
0x0000 : volume
0x0000 : mute
0x0001 : immediate
But the light doesn't lite.... Also, the test programs like rainbow do not function. They run, but no output / errors are shown. Any assistance is appreciated!
The contrib directory has some API services for blynclight that I've been noodling around with, but it's time to get serious-ish.
I'm not sure if this is just python3, pip3, or whatever, but installing in editable mode fails:
➜ pip3 install -e .
ERROR: File "setup.py" not found. Directory cannot be installed in editable mode: /Users/me/workspace/blynclight
(A "pyproject.toml" file was found, but editable mode currently requires a setup.py based build.)
It installs fine without -e
➜ pip3 --version
pip 19.3.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
➜ python3 --version
Python 3.7.6
Create a sub-package in blynclight:
blynclight/effects/init.py
blynclight/effects/rainbow.py
blynclight/effects/candle.py
and move some of the implementation out of the command-line driver scripts and into the package to facilitate re-use.
Add blynclight/scripts/candle.py that causes the light to flicker like a candle:
contrib/candle.py -l light_id -r red -g green -b blue --flicker_level (additive)
Awesome source material: https://cpldcpu.wordpress.com/2016/01/05/reverse-engineering-a-real-candle/
I see that you are using a constant, called COMMAND_LENGTH = 9
. Where does this value originate from? As in - how did you come up with the length 9?
I know I've vacillated between using PyUSB and HIDAPI to access the hardware, the changes motivated by software availability/accessibility on my primary development platform (Mac OS). It occurs to me that it doesn't have to be an either/or choice, I could support either method of access.
@bkcrisler said:
Sorry. I was able to update to the latest, but it doesn't recognize my
Blynclight. Maybe the version I have is too old. I no longer have the
import Blynclight issues though.
Opened a new issue to track this problem.
Please post the output of 'system_profiler SPUSBDataType' here and maybe we can figure out how your light wants to be addressed.
Thanks for you help debugging this!
I've gotten an hidapi
error on macOS Catalina (v10.15.5, build 19F101). I saw there was an earlier issue and changes back and forth between using hidapi
and libusb
.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/me/python-virtual-environments/rgb_led_status/lib/python3.7/site-packages/blynclight/__init__.py", line 34, in <module>
from .blynclight import BlyncLight
File "/Users/me/python-virtual-environments/rgb_led_status/lib/python3.7/site-packages/blynclight/blynclight.py", line 5, in <module>
from .hid import HidDevice
File "/Users/me/python-virtual-environments/rgb_led_status/lib/python3.7/site-packages/blynclight/hid/__init__.py", line 99, in <module>
raise ImportError("failed to locate hidapi shared object")
ImportError: failed to locate hidapi shared object
My Python3 virtual environment was freshly created with Python 3.7.3 from the Python.org installer. I installed libusb
(libusb @1.0.23) and hidapi
(hidapi @0.9.0_0) with MacPorts.
$ sudo port selfupdate
$ sudo port upgrade outdated
$ sudo port install libusb
$ sudo port install hidapi
Here is what I see with system_profiler SPUSBDataType
. I have the Blynclight plugged into a port on an old Apple Cinema Display HD, which is plugged into the computer.
Blynclight Standard:
Product ID: 0x000c
Vendor ID: 0x2c0d
Version: 0.01
Speed: Up to 12 Mb/s
Location ID: 0x14810000 / 34
Current Available (mA): 500
Current Required (mA): 100
Extra Operating Current (mA): 0
I'm still messing around to see if I can figure things out, but I figured I'd file an issue in case it's known not to work with Catalina or something.
There are some examples in contrib, but I'd like to ship a driver script to /usr/local/bin that calls a command-line interface in the module.
I am unable to get the flash function to work. When using the Embrava Connect software it will flash properly. Light always remains on and steady
Environment
Mac OS 10.15.2
python3
Embrava Blynclight Standard BLYNCUSB40-191
light.flash set to false
Light Status:
Device: 0x2c0d:0x000c
0x00ff : red
0x0000 : blue
0x0000 : green
0x0000 : off
0x0000 : dim
0x0000 : flash
0x0000 : speed
0x0000 : music
0x0000 : play
0x0000 : repeat
0x0000 : volume
0x0000 : mute
0x0001 : immediate
light.flash set to true
Light Status:
Device: 0x2c0d:0x000c
0x00ff : red
0x0000 : blue
0x0000 : green
0x0000 : off
0x0000 : dim
0x0001 : flash
0x0000 : speed
0x0000 : music
0x0000 : play
0x0000 : repeat
0x0000 : volume
0x0000 : mute
0x0001 : immediate
Attempted to set speed in case this was needed
Light Status:
Device: 0x2c0d:0x000c
0x00ff : red
0x0000 : blue
0x0000 : green
0x0000 : off
0x0000 : dim
0x0001 : flash
0x0003 : speed
0x0000 : music
0x0000 : play
0x0000 : repeat
0x0000 : volume
0x0000 : mute
0x0001 : immediate
Request for enhancement
Can you please add a few lines on udev rules to the readme?
At least on Fedora 32 a user will not be allowed to access the blynclight by default.
For my BlyncLight Plus, I created the following rule (/etc/udev/rules.d/99-blynclight.rules
) to allow all users on this workstation read/write access to the device
SUBSYSTEM=="usb", ATTRS{idVendor}=="2c0d", ATTRS{idProduct}=="0010", MODE="0666"
If you have a list of all the USB IDs embrave uses, then I can make a PR if wished.
I have an Embrava Blynclight that I am trying to control on macOS Catalina (10.15.5). If I run system_profiler SPUSBDataType
, I can see the device:
Blynclight:
Product ID: 0x2517
Vendor ID: 0x0e53
Version: 1.00
Speed: Up to 1.5 Mb/s
Location ID: 0x14312000 / 14
Current Available (mA): 500
Current Required (mA): 100
Extra Operating Current (mA): 0
However, when I run blync
, I get an error:
Traceback (most recent call last):
File "/Users/pat/source/blynclight-base/.env/bin/blync", line 10, in <module>
sys.exit(cli())
File "/Users/pat/source/blynclight-base/.env/lib/python3.7/site-packages/typer/main.py", line 213, in __call__
return get_command(self)()
File "/Users/pat/source/blynclight-base/.env/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/pat/source/blynclight-base/.env/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/pat/source/blynclight-base/.env/lib/python3.7/site-packages/click/core.py", line 1236, in invoke
return Command.invoke(self, ctx)
File "/Users/pat/source/blynclight-base/.env/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/pat/source/blynclight-base/.env/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/pat/source/blynclight-base/.env/lib/python3.7/site-packages/typer/main.py", line 496, in wrapper
return callback(**use_params) # type: ignore
File "/Users/pat/source/blynclight-base/.env/lib/python3.7/site-packages/blynclight/__main__.py", line 102, in blync_callback
light = BlyncLight.get_light(light_id)
File "/Users/pat/source/blynclight-base/.env/lib/python3.7/site-packages/blynclight/blynclight.py", line 178, in get_light
return cls.from_dict(cls.available_lights()[light_id])
File "/Users/pat/source/blynclight-base/.env/lib/python3.7/site-packages/blynclight/blynclight.py", line 196, in from_dict
return cls(info["vendor_id"], info["product_id"])
File "/Users/pat/source/blynclight-base/.env/lib/python3.7/site-packages/blynclight/blynclight.py", line 252, in __init__
self.immediate = immediate
File "/Users/pat/source/blynclight-base/.env/lib/python3.7/site-packages/blynclight/blynclight.py", line 316, in __setattr__
n = self.device.write(self.bytes)
File "/Users/pat/source/blynclight-base/.env/lib/python3.7/site-packages/blynclight/hid/__init__.py", line 269, in write
return hidapi.hid_write(self.handle, data, len(data))
File "/Users/pat/source/blynclight-base/.env/lib/python3.7/site-packages/blynclight/hid/__init__.py", line 244, in handle
raise LookupError(f"no such device: {self.identifier}")
LookupError: no such device: 0x0e53:0x2517
This seems odd, since it does seem like the device vendor ID and the product code are correctly detected, it's just that the writing fails with the specified handle.
Running blync -l
actually detects the light as well:
Number of available lights: 1
KEY:ID:VALUE
path:00:
vendor_id:00:0xe53
product_id:00:0x2517
release_number:00:0x100
product_string:00:Blynclight
usage_page:00:0xff00
usage:00:0x1
interface_number:00:0x0
Afternoon -
While trying to import Blynclight, I get the following Error:
`Python 3.7.0 (default, Aug 17 2018, 21:14:48)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
from blynclight import BlyncLight
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.7/site-packages/blynclight/init.py", line 30, in
from .blynclight import BlyncLight
File "/usr/local/lib/python3.7/site-packages/blynclight/blynclight.py", line 6, in
from .hid import enumerate as hid_enumerate
File "/usr/local/lib/python3.7/site-packages/blynclight/hid/init.py", line 48, in
raise ImportError('failed to locate suitable hidapi shared object')
ImportError: failed to locate suitable hidapi shared object
`
As you might know, I am running Mac OS X with Python3.7. Also, it doesn't say, but could you post the package dependencies required? I suspect that may be the issue.
After the setup to poetry transition, poetry picked 3.7 as the base python level which wasn't strictly true. I don't believe I'm using any features that preclude using 3.5 at the least, however I should probably learn how to use tox to test this. At least I think tox is the right tool for that job.
Hi,
I'm trying to control blynclight from my iphone with iOS Shortcut Application.
if I run from my Pi on SSH: "/home/pi/.local/bin/blync -r 255 -n -D 3600 &" it's working perfectly
if I run the same command from the "Run script over SSH" from the iOS shortcut application, it's working and the light turn red but ... the action does not terminate and stay running...
if I manually stop it ... all it's ok ... but I should not have to do it... any idea?
I used the poetry defaults when creating the pyproject.toml file and forgot to relax the version of Python required from only 3.7 to 3.5 or better.
`>>> from blynclight import BlyncLight
BlyncLight.available_lights()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.7/site-packages/blynclight/blynclight.py", line 96, in available_lights
return [cls(d) for d in usb.core.find(idVendor=vendor_id, find_all=True)]
File "/usr/local/lib/python3.7/site-packages/usb/core.py", line 1263, in find
raise NoBackendError('No backend available')
usb.core.NoBackendError: No backend available
light = BlyncLight.first_light()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.7/site-packages/blynclight/blynclight.py", line 112, in first_light
return cls(usb.core.find(idVendor=vendor_id))
File "/usr/local/lib/python3.7/site-packages/usb/core.py", line 1263, in find
raise NoBackendError('No backend available')
usb.core.NoBackendError: No backend available`
Issue is resolved by:
brew install libusb
since they PyUSB won't work properly without libusb
Ok I hate when I'm falling on the install step like that...
I have a RPi3 who I would like to use for it but
apt-get install hidap or apt-get install PyUSB are both giving me:
"Unable to locate package" ... I found the solution and I have to install it like that:
"sudo apt install libhidapi-hidraw0 libhidapi-libusb0"
but now I'm failing on pip and I don't know if it's the model or something else there...:
Installing collected packages: blynclight, requests, typer, click, certifi, chardet, idna, urllib3
*** Error compiling '/tmp/pip-build-56szxyal/blynclight/blynclight/blynclight.py'...
File "/tmp/pip-build-56szxyal/blynclight/blynclight/blynclight.py", line 177
raise BlyncLightNotFound(f"Light for {light_id} not found.")
^
SyntaxError: invalid syntax
*** Error compiling '/tmp/pip-build-56szxyal/blynclight/blynclight/cli_options.py'...
File "/tmp/pip-build-56szxyal/blynclight/blynclight/cli_options.py", line 25
print(f"version: {version}")
^
SyntaxError: invalid syntax
*** Error compiling '/tmp/pip-build-56szxyal/blynclight/blynclight/hid/init.py'...
File "/tmp/pip-build-56szxyal/blynclight/blynclight/hid/init.py", line 205
raise ValueError(f"{self.identifier} already in use")
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.