nutechsoftware/alarmdecoder

UnicodeDecodeError in multiple places

tagdara opened this issue · 6 comments

Every couple days, my USB AlarmDecoder seems to receive some string with garbage characters in it which causes my code to crash with the following exception. There's not a lot of consistency in the position or character. The same error can also occur on the decode commands in the decoder module.

I don't care if the data is discarded, since updates are so frequent, but it is problematic that this is an unhandled exception that crashes my app.

08/22 17:56:08.213 ERROR - 1305 - 40 Exception in thread Thread-1: 08/22 17:56:08.214 ERROR - 1305 - 40 Traceback (most recent call last): 08/22 17:56:08.214 ERROR - 1305 - 40 File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner 08/22 17:56:08.215 ERROR - 1305 - 40 self.run() 08/22 17:56:08.215 ERROR - 1305 - 40 File "/usr/local/lib/python3.4/dist-packages/alarmdecoder/devices.py", line 196, in run 08/22 17:56:08.216 ERROR - 1305 - 40 self._device.read_line(timeout=self.READ_TIMEOUT) 08/22 17:56:08.216 ERROR - 1305 - 40 File "/usr/local/lib/python3.4/dist-packages/alarmdecoder/devices.py", line 915, in read_line 08/22 17:56:08.217 ERROR - 1305 - 40 return data.decode('utf-8') 08/22 17:56:08.217 ERROR - 1305 - 40 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xef in position 61: invalid continuation byte

aschw commented

I'm seeing the same problem.

I added some logging to _handle_message in decoder.py :

    try:
        data = data.decode('utf-8')
    except UnicodeError:
        print repr(datetime.datetime.now()) + ": bad data: <" + data + ">"
        raise InvalidMessageError()

Then waited a few days and finally triggered it. Here's what I got:

datetime.datetime(2018, 3, 16, 20, 31, 17, 805089): bad data: <����*0000001100000003A--],008,[f70400ff1008001c28020000000000]," DISARMED CHIME Ready to Arm ">

tagdara, if you copy that code (and either "import datetime" at the top of the file or remove the print call), I suspect this will solve your app crashing problem.

What is the alarm panel model?
What is your firmware version?
What is your AD2USB hardware version?

aschw commented

I have a Vista 20P. The chip shows WA20P-10.23

My firmware version is:
!VER:ffffffff,V2.2a.8.2,TX;RX;SM;VZ;RF;ZX;RE;AU;3X;CG;DD;MF;LR;KE;MK;CB;DS;ER

Not sure how to tell my AD2USB hardware version. I purchased it from Amazon (Homeseer) in mid-November 2017.

You might consider checking what version of the alarmdecoder package you're running. I rewrote a lot of the IO routines a few months back to make it more stable. There may be a newer package available, or you can try installing from source.

Also, I'm excited to see you're running it under Python 3 =)

aschw commented

That's not it. That had previously occurred to me, so I installed from source before commenting on this issue. setup.py shows 1.13.2

I would say you have a hardware issue in the AD2* or the host UART. It could be a bad USB cable with poor shielding. Contact me at ad2usb@support.nutech.com to arrange a test or repair unit to narrow it down. In any case it can not be allowed to fail so I have hopefully prevented any future crashes with. cf9ed59