deiger / Alarm

Code to connect and control alarms by PIMA.
GNU General Public License v3.0
16 stars 11 forks source link

Script not gracefully handling serial communication issues. #6

Closed gibsonlp closed 4 years ago

gibsonlp commented 4 years ago

Hi Almost every time I try to start the script I get an error such as this:

Traceback (most recent call last): File "./pima_server.py", line 289, in _pima_server = AlarmServer() # type: AlarmServer File "./pima_server.py", line 79, in init self._status = self._alarm.get_status() # type: pima.Status File "/home/myuser/alarm/pima.py", line 172, in get_status response = self._read_message() File "/home/myuser/alarm/pima.py", line 264, in _read_message self._make_hex(data), length + 3)) pima.Error: Not enough data in channel: 00 f3 should have 3 bytes

It looks like it's getting some garbled data / connecting in the middle of a transmission and crashing. This is annoying but not that critical as at least the script exits and I can retry myself, If I am doing that immediately it works fine.

Additionally, I see this every once in a while:

File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner self.run() File "./pima_server.py", line 96, in run status = self._alarm.get_status() # type: pima.Status File "/home/myuser/alarm/pima.py", line 172, in get_status response = self._read_message() File "/home/myuser/alarm/pima.py", line 269, in _read_message self._make_hex(data), self._crc(data), crc)) pima.Error: Invalid input on channel, CRC for 00 is 0, not 23027!

At this stage the script is no longer logged in (I get a a logged in: false message when I test it from outside). Ideally the script would either crash at this point or at least attempt to re-login.

Thanks.

deiger commented 4 years ago

Added _thread.interrupt_main() to the secondary thread, please try now.

maorcc commented 4 years ago

I just had the Invalid input on channel error message, and the service is still up and running. So I guess that the fix is working as designed. Thanks. It would be nice if there was a message in the log about a retry or something.

deiger commented 4 years ago

Cool. Adding the log message.