nukiPyBridge icon indicating copy to clipboard operation
nukiPyBridge copied to clipboard

Configuration and Setup

Open add30417 opened this issue 5 years ago • 78 comments

Dear Giejay,

Thanks for maintaining this project. Honestly I have the issue now to setup at my raspberry. I recognized you are using docker, but besides of the 10 Steps out of the Readme file, I can't go ahead.

Maybe, can you please add more step how someone, like me, setup this from scratch ?

Thanks in advanced Daniel

add30417 avatar Sep 10 '20 04:09 add30417

The readme is a bit outdated. You can use this script to set it up: https://github.com/giejay/nukiPyBridge/blob/master/install-bluetooth-deps.sh

At what step are you stuck?

giejay avatar Sep 13 '20 13:09 giejay

Thanks for your answer.

First of all, I used a RP 3 B+. I downloaded the latest version from Raspbian and wrote a new sd card.

I found out the MAC address of my nuki.

I followed the 10 steps from the Readme file.

But now what is the next step, I couldn't found the NaCl utility on my sd card. And even what should I do with the files from the git Repository? Can I use a docker? Or should I used without docker?

Honestly, I guess isn't rocket sicence any more, but just the next steps and the best way would be very helpful.

But I'm thanksful to you, you are maintining this project.

add30417 avatar Sep 13 '20 13:09 add30417

Did you try to install it using the file I mentioned? After that, you should have a running supervised service on port 5000. You can browse to that port and checkout the methods to use in server.py.

giejay avatar Sep 13 '20 14:09 giejay

Just doing at the moment.

First run, with the error: ./install-bluetooth-deps.sh: line 20: ./install-bluez.sh: No such file or directory cp: cannot stat 'nuki-supervised.conf': No such file or directory

add30417 avatar Sep 13 '20 14:09 add30417

Did you clone the entire repo or just copied that file?

giejay avatar Sep 13 '20 14:09 giejay

I see, I guessed it is a "web" installer. I'm doing again. --- I will do the testing in the next days.

add30417 avatar Sep 13 '20 14:09 add30417

Now, I installed everything.

Following modifciation I did: connect-example.py: changing macaddress of nuki run.sh: changed with raspberry pi ip address nuki.conf: changed with raspberry pi ip address

I used the pi user.

When I'm excuting the server.py, following message I will got back:

./connect-example.py Starting BLE adapter... Failed to restart bluetooth.service: Unit bluetooth.service failed to load properly: Bad message. See system logs and 'systemctl status bluetooth.service' for details. Init Nuki BLE connection... Unable to connect, retrying..., retry count: 1 Starting BLE adapter... Failed to restart bluetooth.service: Unit bluetooth.service failed to load properly: Bad message. See system logs and 'systemctl status bluetooth.service' for details. Init Nuki BLE connection... Unable to connect, retrying..., retry count: 2 Starting BLE adapter... Failed to restart bluetooth.service: Unit bluetooth.service failed to load properly: Bad message. See system logs and 'systemctl status bluetooth.service' for details. Init Nuki BLE connection... Unable to connect, retrying..., retry count: 3 Nuki BLE connection established Traceback (most recent call last): File "./connect-example.py", line 18, in nuki.Nuki(nukiMacAddress).authenticateUser(myPublicKeyHex, myPrivateKeyHex, myID, myIDType, name) File "/home/pi/nuki/nuki.py", line 92, in authenticateUser pairingHandle = self.device.get_handle('a92ee101-5501-11e4-916c-0800200c9a66') AttributeError: 'NoneType' object has no attribute 'get_handle'

Error of bluetooth.service: /lib/systemd/system/bluetooth.service:1: Invalid section header '[Unit] Description=Bluetooth service Documentation=man:bluetoothd(8) Co...

add30417 avatar Sep 13 '20 16:09 add30417

There is something wrong with your bluetooth.service file. Can you post the content?

giejay avatar Sep 13 '20 16:09 giejay

cat /lib/systemd/system/bluetooth.service

[Unit] Description=Bluetooth service Documentation=man:bluetoothd(8) ConditionPathIsDirectory=/sys/class/bluetooth

[Service] Type=dbus BusName=org.bluez ExecStart=/usr/local/libexec/bluetooth/bluetoothd NotifyAccess=main #WatchdogSec=10 #Restart=on-failure CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE LimitNPROC=1 ProtectHome=true ProtectSystem=full

[Install] WantedBy=bluetooth.target Alias=dbus-org.bluez.service

add30417 avatar Sep 13 '20 16:09 add30417

Please put a line break between [Unit] and Description

giejay avatar Sep 13 '20 16:09 giejay

Seems like step ahead:

During the excution of "./connect-example.py" following output appears: Init Nuki BLE connection... Unable to connect, retrying..., retry count: 1 Starting BLE adapter... Init Nuki BLE connection... Unable to connect, retrying..., retry count: 2 Starting BLE adapter... Init Nuki BLE connection... Nuki BLE connection established Nuki Pairing UUID handle created: 008b Requesting Nuki Public Key using command: Nuki_REQ Payload: Nuki_PUBLIC_KEY Nuki Public key requested Nuki returned unexpected response (expecting PUBLIC_KEY): Nuki_ERROR Error Code: 10 Command Identifier: 0001

During second and third execution, following output appears: Starting BLE adapter... Init Nuki BLE connection... Unable to connect, retrying..., retry count: 1 Starting BLE adapter... Init Nuki BLE connection... Unable to connect, retrying..., retry count: 2 Starting BLE adapter... Init Nuki BLE connection... Unable to connect, retrying..., retry count: 3 Nuki BLE connection established Traceback (most recent call last): File "./connect-example.py", line 18, in nuki.Nuki(nukiMacAddress).authenticateUser(myPublicKeyHex, myPrivateKeyHex, myID, myIDType, name) File "/home/pi/nuki/nuki.py", line 92, in authenticateUser pairingHandle = self.device.get_handle('a92xxxxxxxxxxxxxxxxxxxxxxxxxx') AttributeError: 'NoneType' object has no attribute 'get_handle'

add30417 avatar Sep 13 '20 16:09 add30417

Did you start the pairing process on your Nuki by holding it for 5 seconds?

giejay avatar Sep 13 '20 17:09 giejay

Yes, I did.

Update: Even the config file (/home/pi/nuki/nuki.cfg) never created during the execution. I created (with touch command) a empty file, but no success.

add30417 avatar Sep 13 '20 17:09 add30417

Can you try it by using the connect endpoint? See server.py for the details

giejay avatar Sep 14 '20 05:09 giejay

Bascially the server.py isn't helpful me. Is it? I can't see any helpful information.

add30417 avatar Sep 14 '20 06:09 add30417

It mentions the exact methods you can use for connecting and unlocking. For example: @app.route("/connect/<mac_address>/")

So go to localhost:5000/connect/macaddress/frontdoor and it will try to pair

giejay avatar Sep 14 '20 06:09 giejay

the server isn't working at my raspberry

add30417 avatar Sep 14 '20 07:09 add30417

Are you running it using the supervised service? What does 'sudo supervisorctl status nuki' give you?

giejay avatar Sep 14 '20 07:09 giejay

sudo supervisorctl status nuki

nuki FATAL can't find command '/usr/local/bin/flask'

Seems not.

add30417 avatar Sep 14 '20 07:09 add30417

The install bluetooth deps script should have installed flask...

giejay avatar Sep 14 '20 07:09 giejay

It is located in /usr/local/, I changed the config file

add30417 avatar Sep 14 '20 07:09 add30417

When I execute the server.py, I got the same error message back.

172.17.0.50 - - [14/Sep/2020 21:19:55] "GET /favicon.ico HTTP/1.1" 404 - [2020-09-14 21:20:27,854] ERROR in app: Exception on /connect/xxxxxxx/FrontDoor [GET] Traceback (most recent call last): File "/usr/lib/python3/dist-packages/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "/usr/lib/python3/dist-packages/flask/app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/lib/python3/dist-packages/flask/app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/lib/python3/dist-packages/flask/_compat.py", line 35, in reraise raise value File "/usr/lib/python3/dist-packages/flask/app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "/usr/lib/python3/dist-packages/flask/app.py", line 1799, in dispatch_request return self.view_functionsrule.endpoint File "/home/pi/nuki/server.py", line 40, in connect nuki.Nuki(mac_address).authenticateUser(myPublicKeyHex, myPrivateKeyHex, myID, myIDType, name) File "/home/pi/nuki/nuki.py", line 92, in authenticateUser pairingHandle = self.device.get_handle('a92ee101-5501-11e4-916c-0800200c9a66') AttributeError: 'NoneType' object has no attribute 'get_handle' 172.17.0.50 - - [14/Sep/2020 21:20:27] "GET /connect/xxxxxxxxx/FrontDoor HTTP/1.1" 500 - 172.17.0.50 - - [14/Sep/2020 21:20:27] "GET /favicon.ico HTTP/1.1" 404 -

add30417 avatar Sep 14 '20 20:09 add30417

Are you using a nuki v2?

giejay avatar Sep 14 '20 20:09 giejay

Yes, I'm using v2

add30417 avatar Sep 14 '20 20:09 add30417

Can you add --experimental to: ExecStart=/usr/local/libexec/bluetooth/bluetoothd.

What version are you using of bluez?

giejay avatar Sep 14 '20 20:09 giejay

I got following log:

Sep 14 22:05:22 rasppi bluetoothd[2448]: Endpoint registered: sender=:1.43 path=/org/bluez/hci0/A2DP/SBC/Source/1 Sep 14 22:05:22 rasppi bluetoothd[2448]: Endpoint registered: sender=:1.43 path=/org/bluez/hci0/A2DP/SBC/Source/2 Sep 14 22:05:22 rasppi kernel: [ 176.998435] debugfs: File 'le_min_key_size' in directory 'hci0' already present! Sep 14 22:05:22 rasppi kernel: [ 176.998459] debugfs: File 'le_max_key_size' in directory 'hci0' already present! Sep 14 22:05:31 rasppi systemd[1]: Stopping BluezALSA proxy... Sep 14 22:05:31 rasppi bluetoothd[2448]: Endpoint unregistered: sender=:1.43 path=/org/bluez/hci0/A2DP/SBC/Source/1 Sep 14 22:05:31 rasppi bluetoothd[2448]: Endpoint unregistered: sender=:1.43 path=/org/bluez/hci0/A2DP/SBC/Source/2 Sep 14 22:05:31 rasppi systemd[1]: bluealsa.service: Succeeded. Sep 14 22:05:31 rasppi systemd[1]: Stopped BluezALSA proxy. Sep 14 22:05:31 rasppi bluetoothd[2448]: Terminating Sep 14 22:05:31 rasppi systemd[1]: Stopping Bluetooth service... Sep 14 22:05:31 rasppi bluetoothd[2448]: Stopping SDP server Sep 14 22:05:31 rasppi bluetoothd[2448]: Exit Sep 14 22:05:31 rasppi systemd[1]: bluetooth.service: Succeeded. Sep 14 22:05:31 rasppi systemd[1]: Stopped Bluetooth service. Sep 14 22:05:32 rasppi systemd[1]: Starting Bluetooth service... Sep 14 22:05:32 rasppi bluetoothd[2597]: Bluetooth daemon 5.51 Sep 14 22:05:32 rasppi systemd[1]: Started Bluetooth service. Sep 14 22:05:32 rasppi bluetoothd[2597]: Starting SDP server Sep 14 22:05:32 rasppi bluetoothd[2597]: Bluetooth management interface 1.14 initialized Sep 14 22:05:32 rasppi systemd[1]: Started BluezALSA proxy. Sep 14 22:05:32 rasppi bluetoothd[2597]: Endpoint registered: sender=:1.45 path=/org/bluez/hci0/A2DP/SBC/Source/1 Sep 14 22:05:32 rasppi bluetoothd[2597]: Endpoint registered: sender=:1.45 path=/org/bluez/hci0/A2DP/SBC/Source/2 Sep 14 22:05:32 rasppi kernel: [ 187.132985] debugfs: File 'le_min_key_size' in directory 'hci0' already present! Sep 14 22:05:32 rasppi kernel: [ 187.133011] debugfs: File 'le_max_key_size' in directory 'hci0' already present! Sep 14 22:05:38 rasppi systemd[1]: Stopping BluezALSA proxy... Sep 14 22:05:38 rasppi systemd[1]: bluealsa.service: Succeeded. Sep 14 22:05:38 rasppi bluetoothd[2597]: Endpoint unregistered: sender=:1.45 path=/org/bluez/hci0/A2DP/SBC/Source/1 Sep 14 22:05:38 rasppi bluetoothd[2597]: Endpoint unregistered: sender=:1.45 path=/org/bluez/hci0/A2DP/SBC/Source/2 Sep 14 22:05:38 rasppi systemd[1]: Stopped BluezALSA proxy. Sep 14 22:05:38 rasppi bluetoothd[2597]: Terminating Sep 14 22:05:38 rasppi systemd[1]: Stopping Bluetooth service... Sep 14 22:05:38 rasppi bluetoothd[2597]: Stopping SDP server Sep 14 22:05:38 rasppi bluetoothd[2597]: Exit Sep 14 22:05:38 rasppi systemd[1]: bluetooth.service: Succeeded. Sep 14 22:05:38 rasppi systemd[1]: Stopped Bluetooth service. Sep 14 22:05:38 rasppi systemd[1]: Starting Bluetooth service... Sep 14 22:05:38 rasppi bluetoothd[2774]: Bluetooth daemon 5.51 Sep 14 22:05:38 rasppi systemd[1]: Started Bluetooth service. Sep 14 22:05:38 rasppi bluetoothd[2774]: Starting SDP server Sep 14 22:05:38 rasppi bluetoothd[2774]: Bluetooth management interface 1.14 initialized Sep 14 22:05:38 rasppi systemd[1]: Started BluezALSA proxy. Sep 14 22:05:38 rasppi kernel: [ 193.211177] debugfs: File 'le_min_key_size' in directory 'hci0' already present! Sep 14 22:05:38 rasppi kernel: [ 193.211200] debugfs: File 'le_max_key_size' in directory 'hci0' already present! Sep 14 22:05:40 rasppi bluetoothd[2774]: Endpoint registered: sender=:1.47 path=/org/bluez/hci0/A2DP/SBC/Source/1 Sep 14 22:05:40 rasppi bluetoothd[2774]: Endpoint registered: sender=:1.47 path=/org/bluez/hci0/A2DP/SBC/Source/2

add30417 avatar Sep 14 '20 21:09 add30417

bluez is already the newest version (5.50-1.2~deb10u1+rpt2).

add30417 avatar Sep 14 '20 21:09 add30417

Any recommendation how I can fix this topic?

Thanks in advanced.

add30417 avatar Oct 03 '20 16:10 add30417

Something is stopping your Bluez service and I'm not sure what. Before doing anything with the lock, you have to make sure you have a stable bluetooth service.

Do you only see those logs when interacting with the lock or are the logs always visible?

giejay avatar Oct 03 '20 18:10 giejay

https://learn.adafruit.com/install-bluez-on-the-raspberry-pi/installation

Blues should work out of the box. Maybe check in the raspberry installation menu : raspi-config

Maybe restart the raspberry : sudo reboot

Does : hcitool lescan show devices?

Try step 2 from this tutorial: https://github.com/tobiasfeistmantl/python-nuki-client

Did you copy the gattool to path : ... Pyhton3.7 ....

Btw: thank you @giejay !

NopfatGithub avatar Oct 03 '20 19:10 NopfatGithub