Git Product home page Git Product logo

blynclight's Introduction

Erik can be summed up...

Husband, father, hacker, gamer, storyteller, egregious guitarist, hoplophile, space exploration enthusiast, UNIX system programmer, scuba diver, amatuer radio operator, remote-control neophyte, part-time sci-fi snob, passing cartoonist, enthusiastic karateka, whiskey drinker, acolyte of Schwa, semi-good pythonista, recovering trombonist, mechanical keyboard aficionado, unapologetic Apple fanboi, pickup truck driver, naked-eye exoplanet hunter and seriously grouchy in the morning before the first cup of coffee.

I like making computers do weird and/or useful things. Useful is often optional.

I've written some articles on Opensource.com about programming in C and Python.

My handle, JnyJny, is a diminution of "Johnny Johnny" who is a character in the book "The Long Run" by Daniel Keys Moran.

blynclight's People

Contributors

erikoshaughnessy avatar jnyjny avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blynclight's Issues

"No such device" error with blync CLI

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

RFE: add a udev rule to docs

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.

Python version testing with tox

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.

Add an effects package.

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.

Commands to Light Not Processing

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!

Installing on a Raspberry Pi

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")

Create a simple API server and ship in scripts directory.

The contrib directory has some API services for blynclight that I've been noodling around with, but it's time to get serious-ish.

  1. make a CLI to start a daemon process that collects all the lights connected and acts as a proxy hub for client commands.
  2. update blynclight.BlyncLight to use the proxy transparently
  3. ...
  4. profit. (j/k Embrava, nobody is paying me for this)

ImportError: failed to locate hidapi shared object on macOS Catalina

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.

Flash not working

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

ImportError after Pip update to v0.8.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:

  • blynclight-0.5.1 to blynclight-0.8.0
  • not sure if hidapi was installed to hidapi-0.9.0.post3

Control from iOS shortcut application

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?

pip3 install in editable mode doesn't work

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

➜ pip3 --version
pip 19.3.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

python3 version

➜ python3 --version
Python 3.7.6

ImportError: failed to locate suitable hidapi shared object

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.

[QUESTION] Source of COMMAND_LENGTH

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?

Light not recognized.

@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!

MacOSX - usb.core.NoBackendError: No backend available when calling BlyncLight.available_lights()

`>>> 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

Support PyUSB & HIDAPI

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.