kormax / apple-home-key-reader

Apple Home Key Reader Implementation
Apache License 2.0
557 stars 45 forks source link

Error While run first time #25

Closed dev-sence closed 5 months ago

dev-sence commented 5 months ago

/Users/sense/Desktop/apple-home-key-reader-main/venv/bin/python /Users/sense/Desktop/apple-home-key-reader-main/main.py [2024-04-06 23:06:57,166] [ ERROR] repository :42 Could not load Home Key configuration. Assuming that device is not yet configured... Traceback (most recent call last): File "/Users/sense/Desktop/apple-home-key-reader-main/repository.py", line 30, in _load_state_from_file configuration = json.load(open(self.storage_file_path, "r+")) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: 'homekey.json' [2024-04-06 23:06:57,172] [ INFO] accessory_driver :483 Loading Accessory state from hap.state [2024-04-06 23:06:57,173] [ ERROR] service :175 Connecting to the NFC reader... NoneType: None

I got this At first Run

Last login: Sat Apr 6 22:42:17 on ttys001 sense@senseuui-Macmini ~ % ls /dev/tty.*

/dev/tty.Bluetooth-Incoming-Port /dev/tty.usbserial-0001 /dev/tty.SLAB_USBtoUART sense@senseuui-Macmini ~ % Íß

anyyone can help me ?

kormax commented 5 months ago

It's an oversight that I've left to notify when a file cannot be read or opened.

Everything should actually be fine, as after this error a new file is created and application should continue to operate. The error should not reappear after that, even after a restart.

dev-sence commented 5 months ago

It's an oversight that I've left to notify when a file cannot be read or opened.

Everything should actually be fine, as after this error a new file is created and application should continue to operate. The error should not reappear after that, even after a restart.

So can I just wait? When I run it, the same error continues to occur.

dev-sence commented 5 months ago
sense@senseuui-Macmini apple-home-key-reader-main % source ./venv/bin/activate

(venv) sense@senseuui-Macmini apple-home-key-reader-main % python3 main.py

[2024-04-06 23:51:30,151] [   ERROR] repository        :42   Could not load Home Key configuration. Assuming that device is not yet configured...
Traceback (most recent call last):
  File "/Users/sense/Desktop/apple-home-key-reader-main/repository.py", line 30, in _load_state_from_file
    configuration = json.load(open(self.storage_file_path, "r+"))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'homekey.json'
[2024-04-06 23:51:30,162] [    INFO] accessory_driver  :483  Loading Accessory state from `hap.state`
[2024-04-06 23:51:30,164] [   ERROR] service           :175  Connecting to the NFC reader...
NoneType: None
[2024-04-06 23:51:30,164] [    INFO] accessory_driver  :320  Starting the event loop
[2024-04-06 23:51:30,164] [    INFO] __init__          :148  searching for reader on path tty:usbserial-0001:pn532
[2024-04-06 23:51:30,166] [    INFO] accessory_driver  :372  Starting accessory NFC Lock on addresses ['192.168.45.185'], port 51926.
To use the QR Code feature, use 'pip install HAP-python[QRCode]'
Enter this code in your HomeKit app on your iOS device: 139-84-272
[2024-04-06 23:51:30,855] [   ERROR] threads           :20   Unhandled exception in runner homekey. Continuing in 5 seconds
Traceback (most recent call last):
  File "/Users/sense/Desktop/apple-home-key-reader-main/util/threads.py", line 18, in function_
    target(*args, **kwargs)
  File "/Users/sense/Desktop/apple-home-key-reader-main/service.py", line 178, in run
    self.clf.open(self.clf.path)
  File "/Users/sense/Desktop/apple-home-key-reader-main/venv/lib/python3.11/site-packages/nfc/clf/__init__.py", line 149, in open
    self.device = device.connect(path)
                  ^^^^^^^^^^^^^^^^^^^^
  File "/Users/sense/Desktop/apple-home-key-reader-main/venv/lib/python3.11/site-packages/nfc/clf/device.py", line 112, in connect
    device = driver.init(tty)
             ^^^^^^^^^^^^^^^^
  File "", line 40, in init
  File "/Users/sense/Desktop/apple-home-key-reader-main/venv/lib/python3.11/site-packages/nfc/clf/transport.py", line 154, in read
    raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
TimeoutError: [Errno 60] Operation timed out
[2024-04-06 23:51:35,861] [   ERROR] service           :175  Connecting to the NFC reader...
NoneType: None
[2024-04-06 23:51:35,861] [    INFO] __init__          :148  searching for reader on path tty:usbserial-0001:pn532
[2024-04-06 23:51:36,568] [   ERROR] threads           :20   Unhandled exception in runner homekey. Continuing in 5 seconds
Traceback (most recent call last):
  File "/Users/sense/Desktop/apple-home-key-reader-main/util/threads.py", line 18, in function_
    target(*args, **kwargs)
  File "/Users/sense/Desktop/apple-home-key-reader-main/service.py", line 178, in run
    self.clf.open(self.clf.path)
  File "/Users/sense/Desktop/apple-home-key-reader-main/venv/lib/python3.11/site-packages/nfc/clf/__init__.py", line 149, in open
    self.device = device.connect(path)
                  ^^^^^^^^^^^^^^^^^^^^
  File "/Users/sense/Desktop/apple-home-key-reader-main/venv/lib/python3.11/site-packages/nfc/clf/device.py", line 112, in connect
    device = driver.init(tty)
             ^^^^^^^^^^^^^^^^
  File "", line 40, in init
  File "/Users/sense/Desktop/apple-home-key-reader-main/venv/lib/python3.11/site-packages/nfc/clf/transport.py", line 154, in read
    raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
TimeoutError: [Errno 60] Operation timed out
[2024-04-06 23:51:41,571] [   ERROR] service           :175  Connecting to the NFC reader...
NoneType: None
[2024-04-06 23:51:41,571] [    INFO] __init__          :148  searching for reader on path tty:usbserial-0001:pn532
[2024-04-06 23:51:42,254] [   ERROR] threads           :20   Unhandled exception in runner homekey. Continuing in 5 seconds
Traceback (most recent call last):
  File "/Users/sense/Desktop/apple-home-key-reader-main/util/threads.py", line 18, in function_
    target(*args, **kwargs)
  File "/Users/sense/Desktop/apple-home-key-reader-main/service.py", line 178, in run
    self.clf.open(self.clf.path)
  File "/Users/sense/Desktop/apple-home-key-reader-main/venv/lib/python3.11/site-packages/nfc/clf/__init__.py", line 149, in open
    self.device = device.connect(path)
                  ^^^^^^^^^^^^^^^^^^^^
  File "/Users/sense/Desktop/apple-home-key-reader-main/venv/lib/python3.11/site-packages/nfc/clf/device.py", line 112, in connect
    device = driver.init(tty)
             ^^^^^^^^^^^^^^^^
  File "", line 40, in init
  File "/Users/sense/Desktop/apple-home-key-reader-main/venv/lib/python3.11/site-packages/nfc/clf/transport.py", line 154, in read
    raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
TimeoutError: [Errno 60] Operation timed out
^C[2024-04-06 23:51:46,940] [    INFO] main              :76   SIGNAL 15
[2024-04-06 23:51:47,259] [    INFO] accessory_driver  :432  Stopping accessory NFC Lock on address ['192.168.45.185'], port 51926.
[2024-04-06 23:51:47,260] [    INFO] accessory_driver  :342  Closed the event loop
[2024-04-06 23:51:47,279] [   ERROR] base_events       :1771 Task was destroyed but it is pending!
task: <Task pending name='Task-7' coro=<Zeroconf._async_broadcast_service() done, defined at /Users/sense/Desktop/apple-home-key-reader-main/venv/lib/python3.11/site-packages/zeroconf/_core.py:390> wait_for=<Future pending cb=[Task.task_wakeup()]>>
(venv) sense@senseuui-Macmini apple-home-key-reader-main % 
kormax commented 5 months ago

Verify that the directory that the project is at and the file has proper permissions.

Or, try running with "sudo".

dev-sence commented 5 months ago

[2024-04-07 00:05:36,065] [   ERROR] repository        :42   Could not load Home Key configuration. Assuming that device is not yet configured...
Traceback (most recent call last):
  File "/Users/sense/Desktop/apple-home-key-reader-main/repository.py", line 30, in _load_state_from_file
    configuration = json.load(open(self.storage_file_path, "r+"))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'homekey.json'
[2024-04-07 00:05:36,078] [    INFO] accessory_driver  :483  Loading Accessory state from `hap.state`
[2024-04-07 00:05:36,080] [   ERROR] service           :175  Connecting to the NFC reader...
NoneType: None
[2024-04-07 00:05:36,080] [    INFO] __init__          :148  searching for reader on path tty:usbserial-0001:pn532
[2024-04-07 00:05:36,081] [    INFO] accessory_driver  :320  Starting the event loop
[2024-04-07 00:05:36,082] [    INFO] accessory_driver  :372  Starting accessory NFC Lock on addresses ['192.168.45.185'], port 51926.
To use the QR Code feature, use 'pip install HAP-python[QRCode]'
Enter this code in your HomeKit app on your iOS device: 258-14-990
[2024-04-07 00:05:36,793] [   ERROR] threads           :20   Unhandled exception in runner homekey. Continuing in 5 seconds
Traceback (most recent call last):
  File "/Users/sense/Desktop/apple-home-key-reader-main/util/threads.py", line 18, in function_
    target(*args, **kwargs)
  File "/Users/sense/Desktop/apple-home-key-reader-main/service.py", line 178, in run
    self.clf.open(self.clf.path)
  File "/Users/sense/Desktop/apple-home-key-reader-main/venv/lib/python3.11/site-packages/nfc/clf/__init__.py", line 149, in open
    self.device = device.connect(path)
                  ^^^^^^^^^^^^^^^^^^^^
  File "/Users/sense/Desktop/apple-home-key-reader-main/venv/lib/python3.11/site-packages/nfc/clf/device.py", line 112, in connect
    device = driver.init(tty)
             ^^^^^^^^^^^^^^^^
  File "", line 40, in init
  File "/Users/sense/Desktop/apple-home-key-reader-main/venv/lib/python3.11/site-packages/nfc/clf/transport.py", line 154, in read
    raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
TimeoutError: [Errno 60] Operation timed out

Sorry for the same reply The same error appears when i runs in sudo

kormax commented 5 months ago

Please show me the contents of your configuration.json file.

And which port is the one that pn532 connected to.

dev-sence commented 5 months ago
    "logging": {
        "level": 20
    },

    "nfc": {
        "port": "usbserial-0001",
        "driver": "pn532",
        "broadcast": true
    },

    "hap": {
        "port": 51926,
        "persist": "hap.state",
        "default": "locked"
    },

    "homekey": {
        "persist": "homekey.json",
        "express": true,
        "finish": "silver",
        "flow": "fast"
    }
}

config.json

(venv) sense@senseuui-Macmini apple-home-key-reader-main %  ls /dev/tty.*                                     

/dev/tty.Bluetooth-Incoming-Port    /dev/tty.SLAB_USBtoUART         /dev/tty.usbserial-0001
kormax commented 5 months ago

Looks like there's a communication problem with the reader.

Either a bad connection/adapter or module itself.

Also, verify that your PN532 is configured for proper communication mode. There are switches on the PCB, check that they are set properly (UART OR SERIAL OR HSU).