mariusmotea / diyHue

Philips Hue emulator that is able to control multiple types of lights
Other
627 stars 107 forks source link

ZeroDivisionError: float division by zero with Hue Entertainment #305

Closed maxakuru closed 6 years ago

maxakuru commented 6 years ago

First, thanks for the awesome project. Amazing work.

Background:

Issues:

  1. Notice some flickering at the end of the strip. This is reduced/eliminated at low brightness (~10%). Is this the clock rate? Power supply? Solid colors work great, but animations flicker when using Hue Sync, which makes me think it's not the PS.
  2. Only the DotStars are syncing with Entertainment Mode/Hue Sync, it says all lights are on and part of the entertainment zone, but they stay solid color as they were before.
  3. Sometimes the DotStars stop lighting up, and need to restart the hue-emulator service. I stopped the service and ran the emulator manually and got an error that seems to be the root, here's the trace:

Trace:

pi@raspberrypi:/opt/hue-emulator $ sudo ./HueEmulator3.py 
Config loaded
starting ssdp...
start ssdp broadcast
sync with lights
Starting httpd...
127.0.0.1 - - [30/Jul/2018 03:03:11] "GET /api/a7161538be80d40b3de98dece6e91f90/ HTTP/1.0" 200 -
sync with lights
127.0.0.1 - - [30/Jul/2018 03:03:17] "GET /api/a7161538be80d40b3de98dece6e91f90/ HTTP/1.0" 200 -
127.0.0.1 - - [30/Jul/2018 03:03:18] "PUT /api/a7161538be80d40b3de98dece6e91f90/groups/6 HTTP/1.0" 200 -
in PUT method
/api/a7161538be80d40b3de98dece6e91f90/groups/6
b'{"stream":{"active":true}}'
start hue entertainment

  . Seeding the random number generator... ok
  . Loading the CA root certificate ... ok (0 skipped)
  . Loading the server cert. and key... ok
  . Bind on udp://*:2100/ ... ok
  . Setting up the SSL/TLS structure... ok
  . Waiting for a remote connection ...[
    {
        "success": {
            "/groups/6/stream": {
                "active": true
            }
        }
    }
]
 ok
  . Performing the SSL/TLS handshake... hello verification requested
  . Waiting for a remote connection ... ok
  . Performing the SSL/TLS handshake... ok
    [ Protocol is DTLSv1.2 ]
    [ Ciphersuite is TLS-PSK-WITH-AES-128-GCM-SHA256 ]
    [ Record expansion is 37 ]
    [ Maximum fragment length is 16384 ]
  . Verifying peer X.509 certificate... ok
Exception in thread Thread-5:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "./HueEmulator3.py", line 54, in entertainmentService
    sendLightRequest(str(lightId), {"xy": convert_rgb_xy(r, g, b)})
  File "/opt/hue-emulator/functions/colors.py", line 12, in convert_rgb_xy
    x = X / (X + Y + Z)
ZeroDivisionError: float division by zero

127.0.0.1 - - [30/Jul/2018 03:03:23] "GET /api/a7161538be80d40b3de98dece6e91f90/ HTTP/1.0" 200 -
^C mbedtls_ssl_read returned -0x45
 interrupted by SIGTERM (not in net_accept())
  . Cleaning up... done.
sync with lights
config saved
Traceback (most recent call last):
  File "./HueEmulator3.py", line 1565, in <module>
    sleep(10)
KeyboardInterrupt
Sending M-Search response to 192.168.1.24

What I've tried:

I just noticed the division by zero error, and figured I'd post an issue. While I'm here I decided to detail the other issues I've had. Any idea where I should look to next? Any ideas about the flickering?

Cheers!

mariusmotea commented 6 years ago

Hi,

Unfortunately i don't use DotStar LEDs in SPI mode to replicate, but one of the problem maybe be the division of the leds per lights (242 / 4 = 60.5), i recommend to setup the leds number to 240 so there will be no problem at this level. Regarding the error you paste i believe i understand what the problem may be. With native esp lights i send r,g,b values that i receive from entertainment application, but i cannot pass these values to deconz or original hue bridge (don't know what exactly what you use for Philips bulbs) because these accept xy or hs color modes so i convert the values to xy cie values. In order to turn off the lights completely i believe the application send the values 0 to r, g and b, and here the conversion formula fail. I will made a new commit to send "off" request when this happen.

BTW in the HueEmulator3.py file there is following syntax: if fremeID == 24 : #24 = every seconds, increase in case the destination device is overloaded For esp lights i send all frames because they have build it udp server and are able to process this rate, but deconz or original hue bridge need to receive these using http server that is slower and for this i implement one counter that is not optimised. I choose to send one request every second by setting this to 24, this works good with YeeLight bulbs, but i don't test with Deconz.

maxakuru commented 6 years ago

I’ve tried 240 pixels and it still has the issue. I understand you have no way of testing (and no reason to) so I’ll try to fix it myself. When/if I get it, I’ll post in a new issue my resolution or make a PR if it’s a significant change to the esp code.

Thanks for looking into the division by zero issue, 1 update/sec sounds good.

mariusmotea commented 6 years ago

May i know what is your gateway device to zigbee bulbs?

maxakuru commented 6 years ago

I use a gen 2 Philips Hue Bridge. All lights in my home are Hue except for the DotStar lightstrip.

UniCizin commented 6 years ago

Got the same error with yeelight strip (division by zero) before that, entertainment mode and Hue Sync App works great

have a look at the log. https://pastebin.com/eyGkTM1N

mariusmotea commented 6 years ago

I made now a new commit, can you test it? For Yeelight is plenty space for improvement because it accept raw rgb data that hue entertainment is sending.

UniCizin commented 6 years ago

i guess you have a typo somewhere

https://pastebin.com/JnYHZkuM

(i just used the install script again to update)

mariusmotea commented 6 years ago

Sorry, i fixed.

UniCizin commented 6 years ago

no problem.. i'm glad you are here to fix it :)

found another typo right now

https://pastebin.com/BH67tBdn

mariusmotea commented 6 years ago

something wired happened while i paste the new content. Hope this is last one.

mariusmotea commented 6 years ago

@UniCizin i can do one considerable improvement for yeelight, are you able tot test it?

UniCizin commented 6 years ago

i guess i still have a bit time for this tonight..

otherwise i can test it tomorrow (holidays, yey)

just tell me when the update is out :)

if we get these yeelights up and running i will buy a lot more i guess ^^

mariusmotea commented 6 years ago

Done, I'm waiting for feedback if nobody complain anymore about this i will consider the issue solved.

UniCizin commented 6 years ago

okay, i have some good news and some bad news..

the good ones...

it now runs flawless (from coding) even Razer Synapse can synchronize (even it is a bit slow)

the bad ones:

Blue and Red are only a purple tone .. Green is perfect.

mariusmotea commented 6 years ago

Please start new issue, this must remain opened for "ZeroDivisionError". I believe issue is just with Yeelight so i will install back mine and perfrom the test

UniCizin commented 6 years ago

okay, i will make a new post about this. And with the ZeroDivisionError gone, you could add Razer Synapse to the working apps i guess.

ghost commented 6 years ago

@maxakuru @UniCizin @mariusmotea I think this issue got a bit sidetracked towards the end. Does the ZeroDivisionError still exist or not?

maxakuru commented 6 years ago

@cheesemarathon The divide by zero is resolved. I can't speak to the color accuracy, but that's another issue that could be opened if someone feels the need.

Closing 👍