JnyJny / blynclight

Python bindings for the Embrava BlyncLight family of products.
Apache License 2.0
21 stars 3 forks source link

Commands to Light Not Processing #10

Closed dusty81 closed 5 years ago

dusty81 commented 5 years ago

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!

JnyJny commented 5 years ago

So looking at the state dump of the light, I see that the light should be "on" since the off word is all zeros and dim is currently set. The light color is configured to be r,b,g = (0,0,0) so the light is on and shining "black". Which is a specific failure mode called out in the docs :) I learned that one the hard way.

Edit: I misread the device dump. The light should be "on" and "red" but it's not.

I'm a little more concerned that rainbow isn't working. Does your light work with Embrava's software?

What does this script do?

from blynclight import BlyncLight

l = BlyncLight.get_light()
l.red = 0xff
l.on = True

For reference:

>>> print(l)
Device: 0x2c0d:0x0001
    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

With the light plugged in, that should set the light's color to red and turn the light on.

dusty81 commented 5 years ago

I should have added, I'm running Python 3.7.3 on MacOS 10.14.5. I was thinking the line "0x00ff : red" should be showing solid red. I was afraid for a long time I was doing as you described.

The Embrava utility allows me to manually change the status of the light just like I would expect. I also ensure that is shutdown when I run my script so I can access the devices. I will try to run the test script tomorrow when I'm at the office (with my light) setting the hex directly. Thank you for the assistance!

dusty81 commented 5 years ago

I tried to run the lines you provided, without luck! I remove the light and do get an error thrown.

`Python 3.7.3 (default, Mar 27 2019, 09:23:15) [Clang 10.0.1 (clang-1001.0.46.3)] on darwin Type "help", "copyright", "credits" or "license" for more information.

from blynclight import BlyncLight

l = BlyncLight.get_light() l.red = 0xff l.on = True print (l) 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

` I tested with the Embrava Connect client again and verified the light worked there.

Blynclight Plus:

  Product ID:   0x000c
  Vendor ID:    0x2c0d
  Version:  1.00
  Speed:    Up to 1.5 Mb/sec
  Location ID:  0x00400000 / 3
  Current Available (mA):   500
  Current Required (mA):    100
  Extra Operating Current (mA): 0
JnyJny commented 5 years ago

That all looks good unfortunately.

Now I'm wondering if your hidapi library is the problem. On macOS I use brew to install hidapi.

$ brew info hidapi
hidapi: stable 0.8.0-rc1 (bottled), HEAD
Library for communicating with USB and Bluetooth HID devices
https://github.com/signal11/hidapi
/usr/local/Cellar/hidapi/0.8.0-rc1 (17 files, 131.1KB) *
  Poured from bottle on 2019-04-03 at 20:08:10
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/hidapi.rb
==> Dependencies
Build: autoconf ✘, automake ✘, libtool ✘, pkg-config ✔
==> Options
--HEAD
    Install HEAD version
==> Analytics
install: 794 (30 days), 2,310 (90 days), 10,192 (365 days)
install_on_request: 222 (30 days), 533 (90 days), 2,261 (365 days)
build_error: 0 (30 days)

Any chance you could attach a photo of the bottom of your light? I'm wondering if different models might be self-identifying the way I expect them to and perhaps I'm sending the wrong command format to the light.

We'll get this figured out one way or another.

dusty81 commented 5 years ago

I did the same:

$ brew info hidapi hidapi: stable 0.8.0-rc1 (bottled), HEAD Library for communicating with USB and Bluetooth HID devices https://github.com/signal11/hidapi /usr/local/Cellar/hidapi/0.8.0-rc1 (17 files, 131.1KB) * Poured from bottle on 2019-06-10 at 15:04:24 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/hidapi.rb ==> Dependencies Build: autoconf ✘, automake ✘, libtool ✘, pkg-config ✔ ==> Options --HEAD Install HEAD version ==> Analytics install: 794 (30 days), 2,310 (90 days), 10,192 (365 days) install_on_request: 222 (30 days), 533 (90 days), 2,261 (365 days) build_error: 0 (30 days)

Photo is attached. I notice the light is copyright 2017.. so hopefully nothing new. :-)

IMG_5354 copy

JnyJny commented 5 years ago

I like your style @dusty81 we can be friends :) All your software seems to at least match my own so that brings it back to my software not driving the light correctly.

You have a much newer light than my test article, so it's possible the command set is different. I'm not quite sure how to debug this and I'm going to have to do some research. Sorry for the delay.

dusty81 commented 5 years ago

A bit more...

I went and grabbed a 'mini' light from a co-worker, just to make sure it wasn't the hardware and I couldn't get it to light either.

I did pull the source for HIDAPI and can run the Test GUI.
Screen Shot 2019-06-12 at 12 53 23 PM

Sure thing @JnyJny thank you for being so responsive, I appreciate the help.

JnyJny commented 5 years ago

Ok, I'm going to order a light off of Amazon so I have something to test with. Before I order, can you confirm that this is your model of light?

https://www.amazon.com/Blynclight-Plus-light-office-ringer/dp/B01MQTZL59

dusty81 commented 5 years ago

Yup, that's it. I'm also going to take the light home tonight and set it up on my home MacBook Pro to see if I have a software issue on my OS. I'll report back.

JnyJny commented 5 years ago

I've ordered a light to test with, I'll update when I have something to report figured out.

dusty81 commented 5 years ago

Just to follow-up, I did test on another Mojave machine and no luck with my script or the test scripts. I'll await what you find! Thanks again.

JnyJny commented 5 years ago

Good news, bad news. I can recreate the bug, I don't know how to fix it yet. I don't have as much free time as I'd like to work on this, so don't expect a lot of progress on this in the short term. I'm confident I'll get it figured out eventually.

JnyJny commented 5 years ago

Better news. I know what the problem is and have a proof-of-concept hack that is driving the light correctly. The BlyncLight Plus wants it's command buffer terminated with 0xff22 instead of 0xffff. Hurray for wireshark! Look for a fix probably sometime this week, in the meantime if you feel brave, you can apply this patch:

diff --git a/blynclight/blynclight.py b/blynclight/blynclight.py
index 7d6ed72..7838fce 100644
--- a/blynclight/blynclight.py
+++ b/blynclight/blynclight.py
@@ -125,11 +125,11 @@ class BlyncLight(Structure):
         ("volume", c_uint64, 4),
         ("pad2", c_uint64, 3),
         ("mute", c_uint64, 1),
-        ("eoc", c_uint64, 8),
+        ("eoc", c_uint64, 16),
         # End of Command Word
         # - pad3 and immediate round out the
         #   length of _fields_ to 128 bits
-        ("pad3", c_uint64, 63),
+        ("pad3", c_uint64, 55),
         ("immediate", c_uint64, 1),
     ]

diff --git a/blynclight/constants.py b/blynclight/constants.py
index 025796a..0bd6f9a 100644
--- a/blynclight/constants.py
+++ b/blynclight/constants.py
@@ -4,7 +4,7 @@
 import enum

 EMBRAVA_VENDOR_IDS = [0x2C0D, 0x0E53]
-END_OF_COMMAND = 0xFF
+END_OF_COMMAND = 0xFF22
 COMMAND_LENGTH = 9
 PAD_VALUE = 0
dusty81 commented 5 years ago

I'll see if I can figure out how to pull and test today. :)

JnyJny commented 5 years ago

Just pushed release 0.4.7 to PyPI so you can just pip install -U blynclight and give it a spin.

dusty81 commented 5 years ago

Easy to upgrade, pulled from git! Confirmed test programs function and my script is doing as expected! I appreciate the help and the fix! I'll keep working on my script to see if I can enhance it. See: MacJabberBlync.

If I can help test anything in the future, just let me know! Thank you again. Closing.

JnyJny commented 5 years ago

Awesome, glad you are using it to do something fun! Open issues if/when you run into trouble.