kormax / apple-home-key-reader

Apple Home Key Reader Implementation
Apache License 2.0
470 stars 32 forks source link

Unhandled exception in runner homekey. #6

Closed chrispi68 closed 6 months ago

chrispi68 commented 6 months ago

Hi,

The software works, but after a few opening and closing processes it gets stuck in an error loop. To solve the problem, I have to completely power down my Pi and thus also the NFC reader and reboot.

Any ideas?

Raspberry Pi 4 with Raspbian OS, 64bit

Best regards Christoph

Log:

[2023-12-10 17:59:44,546] [   ERROR] service           :178  Connecting to the NFC reader...
NoneType: None
[2023-12-10 17:59:44,546] [    INFO] __init__          :148  searching for reader on path tty:serial0:pn532
[2023-12-10 17:59:44,652] [   ERROR] threads           :19   Unhandled exception in runner homekey. Continuing in 5 seconds
Traceback (most recent call last):
  File "/home/christoph/venv/util/threads.py", line 17, in function_
    target(*args, **kwargs)
  File "/home/christoph/venv/service.py", line 181, in run
    self.clf.open(self.clf.path)
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/__init__.py", line 149, in open
    self.device = device.connect(path)
                  ^^^^^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/device.py", line 112, in connect
    device = driver.init(tty)
             ^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/pn532.py", line 411, in init
    if not transport.read(timeout=initial_timeout) == Chipset.ACK:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/transport.py", line 154, in read
    raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
TimeoutError: [Errno 110] Connection timed out
[2023-12-10 17:59:49,657] [   ERROR] service           :178  Connecting to the NFC reader...
NoneType: None
[2023-12-10 17:59:49,658] [    INFO] __init__          :148  searching for reader on path tty:serial0:pn532
[2023-12-10 17:59:49,763] [   ERROR] threads           :19   Unhandled exception in runner homekey. Continuing in 5 seconds
Traceback (most recent call last):
  File "/home/christoph/venv/util/threads.py", line 17, in function_
    target(*args, **kwargs)
  File "/home/christoph/venv/service.py", line 181, in run
    self.clf.open(self.clf.path)
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/__init__.py", line 149, in open
    self.device = device.connect(path)
                  ^^^^^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/device.py", line 112, in connect
    device = driver.init(tty)
             ^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/pn532.py", line 411, in init
    if not transport.read(timeout=initial_timeout) == Chipset.ACK:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/transport.py", line 154, in read
    raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
TimeoutError: [Errno 110] Connection timed out

After a restart of the software (without power cycle):

[2023-12-10 18:08:04,564] [    INFO] accessory_driver  :483  Loading Accessory state from `hap.state`
[2023-12-10 18:08:04,566] [    INFO] accessory_driver  :320  Starting the event loop
[2023-12-10 18:08:04,566] [   ERROR] service           :178  Connecting to the NFC reader...
NoneType: None
[2023-12-10 18:08:04,567] [    INFO] __init__          :148  searching for reader on path tty:serial0:pn532
[2023-12-10 18:08:04,569] [    INFO] accessory_driver  :372  Starting accessory NFC Lock on addresses ['172.30.160.67'], port 51926.
[2023-12-10 18:08:04,606] [    INFO] hap_protocol      :82   ('172.30.134.147', 64446): Connection made to NFC Lock
[2023-12-10 18:08:04,618] [    INFO] accessory         :138  get_hardware_finish
[2023-12-10 18:08:04,618] [    INFO] service           :284  get_hardware_finish=AQTj4+MA
[2023-12-10 18:08:04,618] [    INFO] accessory         :115  get_lock_current_state
[2023-12-10 18:08:04,618] [    INFO] accessory         :119  get_lock_target_state
[2023-12-10 18:08:04,618] [    INFO] accessory         :129  get_lock_version
[2023-12-10 18:08:04,619] [    INFO] accessory         :158  get_configuration_state
[2023-12-10 18:08:04,619] [    INFO] service           :339  get_configuration_state
[2023-12-10 18:08:04,619] [    INFO] accessory         :148  get_nfc_access_control_point
[2023-12-10 18:08:04,619] [    INFO] service           :297  get_nfc_access_control_point
[2023-12-10 18:08:04,619] [    INFO] accessory         :143  get_nfc_access_supported_configuration
[2023-12-10 18:08:04,620] [    INFO] service           :293  TODO get_nfc_access_supported_configuration=AQEQAgEQ
[2023-12-10 18:08:04,680] [   ERROR] threads           :19   Unhandled exception in runner homekey. Continuing in 5 seconds
Traceback (most recent call last):
  File "/home/christoph/venv/util/threads.py", line 17, in function_
    target(*args, **kwargs)
  File "/home/christoph/venv/service.py", line 181, in run
    self.clf.open(self.clf.path)
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/__init__.py", line 149, in open
    self.device = device.connect(path)
                  ^^^^^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/device.py", line 112, in connect
    device = driver.init(tty)
             ^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/pn532.py", line 411, in init
    if not transport.read(timeout=initial_timeout) == Chipset.ACK:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/transport.py", line 154, in read
    raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
TimeoutError: [Errno 110] Connection timed out
[2023-12-10 18:08:06,924] [    INFO] accessory         :119  get_lock_target_state
[2023-12-10 18:08:06,924] [    INFO] accessory         :115  get_lock_current_state
[2023-12-10 18:08:09,694] [   ERROR] service           :178  Connecting to the NFC reader...
NoneType: None
[2023-12-10 18:08:09,695] [    INFO] __init__          :148  searching for reader on path tty:serial0:pn532
[2023-12-10 18:08:09,803] [   ERROR] threads           :19   Unhandled exception in runner homekey. Continuing in 5 seconds
Traceback (most recent call last):
  File "/home/christoph/venv/util/threads.py", line 17, in function_
    target(*args, **kwargs)
  File "/home/christoph/venv/service.py", line 181, in run
    self.clf.open(self.clf.path)
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/__init__.py", line 149, in open
    self.device = device.connect(path)
                  ^^^^^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/device.py", line 112, in connect
    device = driver.init(tty)
             ^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/pn532.py", line 411, in init
    if not transport.read(timeout=initial_timeout) == Chipset.ACK:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/transport.py", line 154, in read
    raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
TimeoutError: [Errno 110] Connection timed out
[2023-12-10 18:08:14,808] [   ERROR] service           :178  Connecting to the NFC reader...
NoneType: None
[2023-12-10 18:08:14,809] [    INFO] __init__          :148  searching for reader on path tty:serial0:pn532
[2023-12-10 18:08:14,914] [   ERROR] threads           :19   Unhandled exception in runner homekey. Continuing in 5 seconds
Traceback (most recent call last):
  File "/home/christoph/venv/util/threads.py", line 17, in function_
    target(*args, **kwargs)
  File "/home/christoph/venv/service.py", line 181, in run
    self.clf.open(self.clf.path)
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/__init__.py", line 149, in open
    self.device = device.connect(path)
                  ^^^^^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/device.py", line 112, in connect
    device = driver.init(tty)
             ^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/pn532.py", line 411, in init
    if not transport.read(timeout=initial_timeout) == Chipset.ACK:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/transport.py", line 154, in read
    raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
TimeoutError: [Errno 110] Connection timed out
[2023-12-10 18:08:19,918] [   ERROR] service           :178  Connecting to the NFC reader...
NoneType: None
[2023-12-10 18:08:19,919] [    INFO] __init__          :148  searching for reader on path tty:serial0:pn532
[2023-12-10 18:08:20,024] [   ERROR] threads           :19   Unhandled exception in runner homekey. Continuing in 5 seconds
Traceback (most recent call last):
  File "/home/christoph/venv/util/threads.py", line 17, in function_
    target(*args, **kwargs)
  File "/home/christoph/venv/service.py", line 181, in run
    self.clf.open(self.clf.path)
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/__init__.py", line 149, in open
    self.device = device.connect(path)
                  ^^^^^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/device.py", line 112, in connect
    device = driver.init(tty)
             ^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/pn532.py", line 411, in init
    if not transport.read(timeout=initial_timeout) == Chipset.ACK:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christoph/venv/lib/python3.11/site-packages/nfc/clf/transport.py", line 154, in read
    raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
TimeoutError: [Errno 110] Connection timed out
kormax commented 6 months ago

Hello.

I think that's the same issue as in https://github.com/kormax/apple-home-key-reader/issues/3

If that's the case, power cycle the PN532 to resolve it this time. As for preventing this in the future, right now this can only be done by patching the nfcpy library by hand as said in the link.

I'll think about possible ways of fixing it via monkey patching the external function, but can provide no timeline for that.

chrispi68 commented 6 months ago

I patched the file pn532.py and now it works

Old: change_baudrate = True # try higher speeds

New: change_baudrate = False # try higher speeds

kormax commented 6 months ago

Hello.

This PR should be able to fix this issue for everyone automatically (by monkey-patching nfcpy library code at runtime).

If you have some time, I would be glad if you could try it out. With this change manual changes to nfcpy would no longer be necessary.

chrispi68 commented 6 months ago

If you have some time, I would be glad if you could try it out. With this change manual changes to nfcpy would no longer be necessary.

I am preparing a second test device with a RasPi Zero 2W and the current code. I will report if this is completed.

chrispi68 commented 6 months ago

It is stable. Great work!