Breina / ha-artnet-led

DMX lighting Integration for Home Assistant. Using the HA Color Mode update and Pyartnet library to control lights in multiple DMX universes over ethernet with the Art-Net protocol.
MIT License
125 stars 11 forks source link

UnicodeDecodeError when running in controller mode #70

Open jwacalex opened 4 days ago

jwacalex commented 4 days ago

Error

When I'm trying to use the integration to run in controller mode and broadcast values to more than one ArtNet Interface, an UnicodeDecodeError appears: UnicodeDecodeError: 'ascii' codec can't decode byte 0x8e in position 37: ordinal not in range(128)

Configuration

The relevant configuration

- platform: artnet_led
  host: 10.11.12.200
  max_fps: 30
  refresh_every: 1
  node_type: artnet-controller

OS Version: Home Assistant OS 13.2 Home Assistant Core: 2024.11.2

Logs

DEBUG (MainThread) [custom_components.artnet_led.client.artnet_server] Sending ArtPoll
DEBUG (MainThread) [custom_components.artnet_led.client.artnet_server] Sleeping a few seconds before polling again...
DEBUG (MainThread) [custom_components.artnet_led.client.artnet_server] Received ArtPoll from 192.168.3.5
DEBUG (MainThread) [custom_components.artnet_led.client.artnet_server] Ignoring ArtPoll as it came from ourselves
DEBUG (MainThread) [custom_components.artnet_led.client.artnet_server] Received ArtPollReply from LedPixelStrip140
DEBUG (MainThread) [custom_components.artnet_led.client.artnet_server]   0001 [0001] -artnet
DEBUG (MainThread) [custom_components.artnet_led.client.artnet_server] Existing node checking in 10.11.12.80@0 with 0:1:[10,11,12,13,14,15]
DEBUG (MainThread) [custom_components.artnet_led.client.artnet_server] Addresses of the node at 10.11.12.80@0:
 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback _SelectorDatagramTransport._read_ready() (None)
    self.handle_datagram(addr, data)
  File "/config/custom_components/artnet_led/client/artnet_server.py", line 389, in handle_datagram
    reply.deserialize(data)
  File "/config/custom_components/artnet_led/client/__init__.py", line 773, in deserialize
    self.long_name, index = self._consume_str(packet, index, 64)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/artnet_led/client/__init__.py", line 453, in _consume_str
    str_bytes = str(packet[index:index + length - 1], "ASCII")
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8e in position 37: ordinal not in range(128)
Breina commented 3 days ago

Interesting!

So the integration shouts around to find anyone, and your controller replies. One of the fields of this reply is this field:

image

The spec didn't specify which encoding it uses, so I assumed ASCII, since that was used elsewhere as well. But your device name has a byte (0x8E) that is outside the range of ASCII (max 0x7F).

This can mean two things.

It might be that there's an unwritten standard in the ArtNet community. Can you please use The Artnetnominator to figure out the full name of your device? From the 37th character, I can deduce the encoding.

https://www.lightjams.com/artnetominator/

Might also be interesting if you can post the device model and manufacturer, so that I can ask them what encoding they're using.

jwacalex commented 3 days ago

I'll dump the ArtNet names later, maybe there should be some try/catch statements to prevent an exception.

the affected device: Stairville Pixel Rail Drive 640R

Breina commented 3 days ago

Yeah it's definitely an oversight on my end. Try/except (= python equivalent) would have prevented this. If it's going to be Unicode, then I'll add exception handling.

I've sent an email to Artistic license and Stairville to shed some light on this.

jwacalex commented 3 days ago

I'll prepare a pull request for the exception handling. if you need any further information/data let me know

jwacalex commented 3 days ago

The interesting part is, that the string should be the following ascii output NetWork Node 2(42:4C:84:66:EE:F8). this is shown while scanning the universes via dmxworkshop

I've extracted the offending string in hexadecimal representation from the warning message introduced in #71: 4e6574576f726b204e6f646520322834323a34433a38343a36363a45453a463829002e00708eb00201002300426f6f74204d6f64653a20426f6f746564206600

this string contains the same output but also some control characters leaking from a boot sequence?: NetWork Node 2(42:4C:84:66:EE:F8) NUL *. NUL p?? SYN LF NUL # NUL Boot Mode: Booted f