deiger / Alarm

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

pima.service hangs indefinitely after few days of running #9

Open maorcc opened 3 years ago

maorcc commented 3 years ago

Every few days I need to restart the pima.service when it stops functioning. Here is what I see in the log:

Aug 30 21:47:10 raspberrypi systemd[1]: Started PIMA alarm server.
Aug 31 00:02:48 raspberrypi python3[368]: E0831 00:02:48.733  pima_server.py:104] Exception raised by Alarm.
                                          Traceback (most recent call last):
                                            File "pima_server.py", line 97, in run
                                              status = self._alarm.get_status()  # type: pima.Status
                                            File "/usr/lib/pima/pima.py", line 172, in get_status
                                              response = self._read_message()
                                            File "/usr/lib/pima/pima.py", line 264, in _read_message
                                              self._make_hex(data), length + 3))
                                          pima.Error: Not enough data in channel: 62 0d 05 01 02 00 00 00 00 00 00 0b 00 00 00 01 00 08 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 00 00 05 should have 101 bytes.
Aug 31 00:02:49 raspberrypi python3[368]: E0831 00:02:49.631  pima_server.py:110] Failed to recreate Alarm object. Exit for a clean restart.
                                          Traceback (most recent call last):
                                            File "pima_server.py", line 97, in run
                                              status = self._alarm.get_status()  # type: pima.Status
                                            File "/usr/lib/pima/pima.py", line 172, in get_status
                                              response = self._read_message()
                                            File "/usr/lib/pima/pima.py", line 264, in _read_message
                                              self._make_hex(data), length + 3))
                                          pima.Error: Not enough data in channel: 62 0d 05 01 02 00 00 00 00 00 00 0b 00 00 00 01 00 08 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 00 00 05 should have 101 bytes.

                                          During handling of the above exception, another exception occurred:

                                          Traceback (most recent call last):
                                            File "pima_server.py", line 108, in run
                                              self._create_alarm()
                                            File "pima_server.py", line 135, in _create_alarm
                                              self._status = self._alarm.get_status()  # type: pima.Status
                                            File "/usr/lib/pima/pima.py", line 172, in get_status
                                              response = self._read_message()
                                            File "/usr/lib/pima/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 1285!
Aug 31 00:02:49 raspberrypi python3[368]: E0831 00:02:49.668  pima_server.py:104] Exception raised by Alarm.
                                          Traceback (most recent call last):
                                            File "pima_server.py", line 97, in run
                                              status = self._alarm.get_status()  # type: pima.Status
                                            File "/usr/lib/pima/pima.py", line 172, in get_status
                                              response = self._read_message()
                                            File "/usr/lib/pima/pima.py", line 269, in _read_message
                                              self._make_hex(data), self._crc(data), crc))
                                          pima.Error: Invalid input on channel, CRC for 05 05 05 05 01 00 is 2269, not 0!
Aug 31 00:42:08 raspberrypi python3[368]: E0831 00:42:08.832  pima_server.py:104] Exception raised by Alarm.
                                          Traceback (most recent call last):
                                            File "pima_server.py", line 97, in run
                                              status = self._alarm.get_status()  # type: pima.Status
                                            File "/usr/lib/pima/pima.py", line 172, in get_status
                                              response = self._read_message()
                                            File "/usr/lib/pima/pima.py", line 264, in _read_message
                                              self._make_hex(data), length + 3))
                                          pima.Error: Not enough data in channel: 62 0d 05 01 02 00 00 02 00 00 00 0b 00 00 00 14 00 08 0d 00 00 00 00 00 should have 101 bytes.

It looks like the process is blocked waiting on a mutex. Here is the output of strace:

pi@raspberrypi:~/pima $ sudo strace -p 368
strace: Process 368 attached
futex(0xb55005b8, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, NULL, FUTEX_BITSET_MATCH_ANY^Cstrace: Process 368 detached
 <detached ...>
Jens-Wymeersch commented 3 years ago

@maorcc I see you are using Dror's tool. I was wondering if you using it directly via a serial connection, or you bought the home automation kit from PIMA ? I've just tried it with the serial connection and can't get it to work for the moment. Which version of PIMA do you have ? I'm at HP896

maorcc commented 3 years ago

@Jens-Wymeersch , yes I use Dror's tool directly via a serial connection from a Raspberry PI Zero. I don't have the home automation kit or anything else between the PI and PIMA. I don't know the version of PIMA. It is about 10 years old.

Jens-Wymeersch commented 3 years ago

Great ! What about the command ? How did you find on your RPI the right serial port ? And which one is it ?

maorcc commented 2 years ago

Great! What about the command? How did you find on your RPI the right serial port? And which one is it?

Sorry for the late response @Jens-Wymeersch. It is probably no longer relevant for you, but Hopefully, it would help others. The PI serial devices can be found in the "All Hardware" dialog. To open the All Hardware dialog do the following:

  1. Open the Hardware page: Open your Home Assistant instance and show hardware information.
  2. Click the "3 dots" icon on the top right of the page to open an options dropdown menu.
  3. Click the "All Hardware" option. It will open a modal dialog.
  4. Type "USB" in the "Search hardware" field to see just relevant devices. Scroll toward the bottom of the list.
maorcc commented 1 year ago

I do not see this issue happening for a while now, so unless others still see it, I suggest closing this issue.

I don't know what fixed the issue. The code changes, the use of HomeAssistant AddOn, or the change of hardware that I described here: https://github.com/deiger/Alarm/pull/20#issuecomment-1258626221

In any case, I suggest closing this issue.