Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Smart Lock v4 #49

Open
axute opened this issue Jun 3, 2024 · 17 comments
Open

Support for Smart Lock v4 #49

axute opened this issue Jun 3, 2024 · 17 comments
Labels
enhancement New feature or request

Comments

@axute
Copy link

axute commented Jun 3, 2024

I tried last week to pair with Smart Lock v4, but it doesn't work.
Are there any plans to support this?
Nukihub works with v4, but I would like to use Esphome.

@pazzotranquillo
Copy link

Same request here! Thanks.

@ssorgatem
Copy link

Another v4 owner here

@uriyacovy
Copy link
Owner

Apologies for the late response. AFAIK, the underlying library NukiBleEsp32 does not yet support v4.

@ssorgatem
Copy link

ssorgatem commented Jun 28, 2024

Apparently it does: I-Connect/NukiBleEsp32#65

@uriyacovy
Copy link
Owner

Great. There is no specific code in this module for either V2, V3 and V4.
Since I don't have the V4 version, can you explain what is the problem you experience?

@axute
Copy link
Author

axute commented Jun 28, 2024

It is simply not pairing.

@uriyacovy
Copy link
Owner

Please post the logs and the yaml.

@axute
Copy link
Author

axute commented Jul 4, 2024

Unfortunately I can't test it anymore, my dad is happy with the nukihub project, sorry.
I only have a Nuki V3 myself.

@ssorgatem
Copy link

I will be able to test once #51 is fixed

@uriyacovy
Copy link
Owner

I will be able to test once #51 is fixed

You can try now.

@AntorFr
Copy link

AntorFr commented Aug 12, 2024

Hi,

I experience the same issues.
I have one esphome device already paired with one v4 lock and works great.

I bought a new one / update all my lock and tried to config the a new esphome but pairing does not work anymore (even for my older v4 lock). So for devices already paired it fine but I can't paired new one.

Unfortunatly logs are not helping much, ESP is in pairing mode. When I put my lock in pairing mode (long press) I have a crash:

[16:55:17][732347][E][Preferences.cpp:503] getBytesLength(): nvs_get_blob len fail: bleAddress NOT_FOUND
[16:55:17][732347][E][NukiBle.cpp:939] retrieveCredentials(): Error getting data from NVS
<< Just after turning my pairing mode on my Nuki >>
[16:55:22]E (741236) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
[16:55:22]E (741236) task_wdt:  - loopTask (CPU 1)
[16:55:22]E (741236) task_wdt: Tasks currently running:
[16:55:22]E (741236) task_wdt: CPU 0: IDLE
[16:55:22]E (741236) task_wdt: CPU 1: IDLE
[16:55:22]E (741236) task_wdt: Aborting.
[16:55:22]
[16:55:22]abort() was called at PC 0x400fc834 on core 0
[16:55:22]
[16:55:22]
[16:55:22]Backtrace:0x40083701:0x3ffbea0c |<-CORRUPTED
[16:55:22]
[16:55:22]
[16:55:22]
[16:55:22]
[16:55:22]ELF file SHA256: 0000000000000000
[16:55:22]
[16:55:22]Rebooting...
[16:55:22]ets Jul 29 2019 12:21:46
[16:55:22]
[16:55:22]rst:0xc (SW_CPU_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
[16:55:22]configsip: 0, SPIWP:0xee
[16:55:22]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[16:55:22]mode:DIO, clock div:2
[16:55:22]load:0x3fff0030,len:1184
[16:55:22]load:0x40078000,len:12784
[16:55:22]load:0x40080400,len:3032
[16:55:22]entry 0x400805e4
[16:55:22][I][logger:156]: Log initialized
[16:55:22][C][safe_mode:079]: There have been 0 suspected unsuccessful boot attempts
[16:55:22][D][esp32.preferences:114]: Saving 1 preferences to flash...
[16:55:22][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[16:55:22][I][app:029]: Running through setup()...
[16:55:22][I][nukilock.lock:160]: Starting NUKI Lock...
[16:55:23][   348][E][Preferences.cpp:503] getBytesLength(): nvs_get_blob len fail: bleAddress NOT_FOUND
[16:55:23][   349][E][NukiBle.cpp:939] retrieveCredentials(): Error getting data from NVS
[16:55:23][W][nukilock.lock:183]: ���? Nuki is not paired

@AntorFr
Copy link

AntorFr commented Aug 12, 2024

Adding more verbose logs

[17:24:29]I[37400][D][NukiBle.cpp:109] pairNuki(): Nuki in pairing mode found
[17:24:29] NimBLEScan: Updated advertiser: b8:7c:6f:7b:91:e3
[17:24:29]D NimBLEScan: >> stop()
[17:24:29]I NimBLEAdvertisedDevice: No service data found
[17:24:29]D NimBLEScan: << stop()
[17:24:29]I N[ 37419][D][NukiBle.cpp:163] connectBle(): connecting within: loopTask
[17:24:29][ 37426][D][NukiBle.cpp:177] connectBle(): connection attemnpt 0
[17:24:29]imBLEScan: Updated advertiser: e7:a7:29:e1:39:c8
[17:24:29]D NimBLEClient: >> connect(54:d2:72:93:48:bd)
[17:24:29]D NimBLEClient: Got Client event
[17:24:29]I NimBLEClient: Connected event
[17:24:29]D NimBLEClient: Got Client event
[17:24:29]I NimBLEClient: mtu update event; conn_handle=0 mtu=247
[17:24:29]I NimBLEClient: Connection established
[17:24:29]D NimBLEClient: >> deleteServices
[17:24:29]D NimBLEClient: Got Client event
[17:24:29]D NimBLEClient: << deleteServices
[17:24:29]D [ 37749][D][NukiBle.cpp:1506] onConnect(): BLE connected
[17:24:29]NimBLEClient: Peer requesting to update connection parameters
[17:24:29]D NimBLEClient: MinInterval: 12, MaxInterval: 12, Latency: 0, Timeout: 600
[17:24:29]D NimBLEClient: << connect()
[17:24:29]D NimBLEClientCallbacks: onConnParamsUpdateRequest: default
[17:24:29]D NimBLEClient: >> getService: uuid: a92ee100-5501-11e4-916c-0800200c9a66
[17:24:29]D NimBLEClient: Accepted peer params
[17:24:29]D NimBLEClient: >> retrieveServices
[17:24:29]D NimBLEClient: Got Client event
[17:24:29]I NimBLEClient: mtu update event; conn_handle=0 mtu=247
[17:24:29]D NimBLEClient: Service Discovered >> status: 0 handle: 23
[17:24:29]D NimBLERemoteService: >> NimBLERemoteService()
[17:24:29]D NimBLERemoteService: << NimBLERemoteService(): a92ee100-5501-11e4-916c-0800200c9a66
[17:24:29]D NimBLEClient: Service Discovered >> status: 14 handle: -1
[17:24:29]D NimBLEClient: << Service Discovered
[17:24:29]D NimBLEClient: << retrieveServices
[17:24:29]D NimBLERemoteService: >> getCharacteristic: uuid: a92ee101-5501-11e4-916c-0800200c9a66
[17:24:29]D NimBLERemoteService: >> retrieveCharacteristics() for service: a92ee100-5501-11e4-916c-0800200c9a66
[17:24:29]D NimBLEClient: Got Client event
[17:24:29]I NimBLEClient: Connection parameters updated.
[17:24:29]D NimBLERemoteService: Characteristic Discovered >> status: 0 handle: 25
[17:24:29]D NimBLERemoteCharacteristic: >> NimBLERemoteCharacteristic()
[17:24:29]D NimBLERemoteCharacteristic: << NimBLERemoteCharacteristic(): a92ee101-5501-11e4-916c-0800200c9a66
[17:24:29]D NimBLERemoteService: Characteristic Discovered >> status: 14 handle: -1
[17:24:29]D NimBLERemoteService: << Characteristic Discovered
[17:24:29]D NimBLERemoteService: << retrieveCharacteristics()
[17:24:29]D NimBLERemoteCharacteristic: >> setNotify(): Characteristic: uuid: a92ee101-5501-11e4-916c-0800200c9a66, handle: 25 0x0019, props: 0x28, 02
[17:24:29]D NimBLERemoteCharacteristic: >> getDescriptor: uuid: 0x2902
[17:24:29]D NimBLERemoteCharacteristic: >> retrieveDescriptors() for characteristic: a92ee101-5501-11e4-916c-0800200c9a66
[17:24:29]D NimBLERemoteCharacteristic: Next Characteristic >> status: 14 handle: -1
[17:24:29]D NimBLERemoteCharacteristic: Descriptor Discovered >> status: 0 handle: 26
[17:24:29]D NimBLERemoteDescriptor: >> NimBLERemoteDescriptor()
[17:24:29]D NimBLERemoteDescriptor: << NimBLERemoteDescriptor(): 0x2902
[17:24:29]D NimBLERemoteCharacteristic: << Descriptor Discovered. status: 0
[17:24:29]D NimBLERemoteCharacteristic: << retrieveDescriptors(): Found 1 descriptors.
[17:24:29]D NimBLERemoteCharacteristic: << setNotify()
[17:24:29]D NimBLERemoteDescriptor: >> Descriptor writeValue: Descriptor: uuid: 0x2902, handle: 26
[17:24:29]I NimBLERemoteDescriptor: Write complete; status=0 conn_handle=0
[17:24:29]D NimBLERemoteDescriptor: << Descriptor writeValue, rc: 0
[17:24:29][ 38420][D][NukiBle.cpp:1242] registerOnGdioChar(): GDIO characteristic registered
[17:24:30]D NimBLEClient: >> getService: uuid: a92ee200-5501-11e4-916c-0800200c9a66
[17:24:30]D NimBLEClient: >> retrieveServices
[17:24:30]D NimBLEClient: Service Discovered >> status: 0 handle: 27
[17:24:30]D NimBLERemoteService: >> NimBLERemoteService()
[17:24:30]D NimBLERemoteService: << NimBLERemoteService(): a92ee200-5501-11e4-916c-0800200c9a66
[17:24:30]D NimBLEClient: Service Discovered >> status: 14 handle: -1
[17:24:30]D NimBLEClient: << Service Discovered
[17:24:30]D NimBLEClient: << retrieveServices
[17:24:30]D NimBLERemoteService: >> getCharacteristic: uuid: a92ee202-5501-11e4-916c-0800200c9a66
[17:24:30]D NimBLERemoteService: >> retrieveCharacteristics() for service: a92ee200-5501-11e4-916c-0800200c9a66
[17:24:30]D NimBLERemoteService: Characteristic Discovered >> status: 0 handle: 32
[17:24:30]D NimBLERemoteCharacteristic: >> NimBLERemoteCharacteristic()
[17:24:30]D NimBLERemoteCharacteristic: << NimBLERemoteCharacteristic(): a92ee202-5501-11e4-916c-0800200c9a66
[17:24:30]D NimBLERemoteService: Characteristic Discovered >> status: 14 handle: -1
[17:24:30]D NimBLERemoteService: << Characteristic Discovered
[17:24:30]D NimBLERemoteService: << retrieveCharacteristics()
[17:24:30]D NimBLERemoteCharacteristic: >> setNotify(): Characteristic: uuid: a92ee202-5501-11e4-916c-0800200c9a66, handle: 32 0x0020, props: 0x28, 02
[17:24:30]D NimBLERemoteCharacteristic: >> getDescriptor: uuid: 0x2902
[17:24:30]D NimBLERemoteCharacteristic: >> retrieveDescriptors() for characteristic: a92ee202-5501-11e4-916c-0800200c9a66
[17:24:30]D NimBLERemoteCharacteristic: Next Characteristic >> status: 0 handle: 35
[17:24:30]D NimBLERemoteCharacteristic: Descriptor Discovered >> status: 0 handle: 33
[17:24:30]D NimBLERemoteDescriptor: >> NimBLERemoteDescriptor()
[17:24:30]D NimBLERemoteDescriptor: << NimBLERemoteDescriptor(): 0x2902
[17:24:30]D NimBLERemoteCharacteristic: << Descriptor Discovered. status: 0
[17:24:30]D NimBLERemoteCharacteristic: << retrieveDescriptors(): Found 1 descriptors.
[17:24:30]D NimBLERemoteCharacteristic: << setNotify()
[17:24:30]D NimBLERemoteDescriptor: >> Descriptor writeValue: Descriptor: uuid: 0x2902, handle: 33
[17:24:30]I NimBLERemoteDescriptor: Write complete; status=0 conn_handle=0
[17:24:30]D NimBLERemoteDescriptor: << Descriptor writeValue, rc: 0
[17:24:30][ 38855][D][NukiBle.cpp:1286] registerOnUsdioChar(): USDIO characteristic registered
[17:24:30][ 38977][D][NukiBle.cpp:980] pairStateMachine(): ##################### REQUEST REMOTE PUBLIC KEY #########################
[17:24:30]D NimBLEScan: >> stop()
[17:24:30]D NimBLEScan: << stop()
[17:24:30]D NimBLERemoteCharacteristic: >> writeValue(), length: 6
[17:24:30]I NimBLERemoteCharacteristic: Write complete; status=0 conn_handle=0
[17:24:30]D NimBLERemoteCharacteristic: << writeValue, rc: 0
[17:24:32]D NimBLEClient: Got Client event
[17:24:32]D NimBLEClient: Notify Recieved for handle: 25
[17:24:32]D NimBLEClient: checking service a92ee100-5501-11e4-916c-0800200c9a66 for handle: 25
[17:24:32]D NimBLEClient: Got Notification for characteristic Characteristic: uuid: a92ee101-5501-11e4-916c-0800200c9a66, handle: 25 0x0019, props: 0x28
[17:24:32]Descriptor: uuid: 0x2902, handle: 26
[17:24:32]D NimBLEClient: Invoking callback for notification on characteristic Characteristic: uuid: a92ee101-5501-11e4-916c-0800200c9a66, handle: 25 0x0019, props: 0x28
[17:24:32]Descriptor: uuid: 0x2902, handle: 26
[17:24:32][ 40889][D][NukiBle.cpp:1318] notifyCallback(): Notify callback for characteristic: a92ee101-5501-11e4-916c-0800200c9a66 of length: 36
[17:24:32][ 40901][D][NukiUtils.cpp:103] crcValid(): CRC CHECK OKE
[17:24:32][ 40971][D][NukiBle.cpp:996] pairStateMachine(): ##################### SEND CLIENT PUBLIC KEY #########################
[17:24:32]D NimBLEScan: >> stop()
[17:24:32]D NimBLEScan: << stop()
[17:24:32]D NimBLERemoteCharacteristic: >> writeValue(), length: 36
[17:24:32]I NimBLERemoteCharacteristic: Write complete; status=0 conn_handle=0
[17:24:32]D NimBLERemoteCharacteristic: << writeValue, rc: 0
[17:24:32]D NimBLEClien[ 41001][D][NukiBle.cpp:1003] pairStateMachine(): ##################### CALCULATE DH SHARED KEY s #########################
[17:24:32]t: Got Client event
[17:24:32]D NimBLEClient: Notify Recieved for handle: 25
[17:24:32]D NimBLEClient: checking service a92ee100-5501-11e4-916c-0800200c9a66 for handle: 25
[17:24:32]D NimBLEClient: Got Notifica[ 41028][D][NukiBle.cpp:1010] pairStateMachine(): ##################### DERIVE LONG TERM SHARED SECRET KEY k #########################
[17:24:32]tion for characteristic Characteristic: uuid: a92ee101-5501-11e4-916c-0800200c9a66, handle: 25 0x0019, props: 0x28
[17:24:32]Descriptor: uuid: 0x2902, handle: 26
[17:24:32]D NimBLEClient: Invoking callback for notification on characteristic Characteristic: uuid: a92ee101-5501-11e4-916c-0800200c9a66, handle: 25 0x0019, props: 0x28
[17:24:32]Descriptor: uuid: 0x2902, handle: 26
[17:24:32][ 41071][D][NukiBle.cpp:1318] notifyCallback(): Notify callback for characteristic: a92ee101-5501-11e4-916c-0800200c9a66 of length: 36
[17:24:32][ 41083][D][NukiUtils.cpp:103] crcValid(): CRC CHECK OKE
[17:24:32][ 41091][D][NukiBle.cpp:1022] pairStateMachine(): ##################### CALCULATE/VERIFY AUTHENTICATOR #########################
[17:24:32][ 41150][D][NukiBle.cpp:1039] pairStateMachine(): ##################### SEND AUTHENTICATOR #########################
[17:24:32]D NimBLEScan: >> stop()
[17:24:32]D NimBLEScan: << stop()
[17:24:32]D NimBLERemoteCharacteristic: >> writeValue(), length: 36
[17:24:32]I NimBLERemoteCharacteristic: Write complete; status=0 conn_handle=0
[17:24:32]D NimBLERemoteCharacteristic: << writeValue, rc: 0
[17:24:33]E (49286) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
[17:24:33]E (49286) task_wdt: - loopTask (CPU 1)
[17:24:33]E (49286) task_wdt: Tasks currently running:
[17:24:33]E (49286) task_wdt: CPU 0: btController
[17:24:33]E (49286) task_wdt: CPU 1: IDLE
[17:24:33]E (49286) task_wdt: Aborting.
[17:24:33]
[17:24:33]abort() was called at PC 0x401035d8 on core 0
[17:24:33]
[17:24:34]
[17:24:34]Backtrace:0x40083701:0x3ffbeb1c |<-CORRUPTED
[17:24:34]
[17:24:34]
[17:24:34]
[17:24:34]
[17:24:34]ELF file SHA256: 0000000000000000

@uriyacovy
Copy link
Owner

Thanks.

  1. Please post the full yaml.
  2. Instead of using this library - https://github.com/uriyacovy/NukiBleEsp32 please try the original repo https://github.com/I-Connect/NukiBleEsp32 and see if it works.

@AntorFr
Copy link

AntorFr commented Aug 12, 2024

Hi,

Thanks @uriyacovy for your replay.
I was already using https://github.com/I-Connect/NukiBleEsp32 with the differentes releases / branches.

After a full day of testing I thing i find the root cause, and a work arround allowing me to pair my device.

So the issues is that Esphome has reduce the wst watchdog timer to 5s and any task taking more time causing a reset.
Nuki is taking too much time to answer to the "SEND AUTHENTICATOR" test causing watchdog reset.

Adding a "esp_task_wdt_reset();" in the loop to prevent the watchdog to trigger had allow me to successfully end the pairing process (tested several time to confirm)

you can find there my ugly workarround
I-Connect/NukiBleEsp32@a1d9f9d

you can try it using
https://github.com/AntorFr/NukiBleEsp32#test instead of https://github.com/I-Connect/NukiBleEsp32

@uriyacovy
Copy link
Owner

Good catch! Thanks a lot!
I wonder why pairing takes longer in Nuki V4.
In any case, maybe there's a workaround that can be done in this library. Can you check the following?
In nuki_lock.cpp add #include "esphome/core/application.h" and just before line 266 add App.feed_wdt();
Let me know if it works, and if it does, I'll add it to the code.

@AntorFr
Copy link

AntorFr commented Aug 17, 2024

Hi @uriyacovy

Thanks, I tried it (you can look at the fix there https://github.com/AntorFr/ESPHome_nuki_lock/tree/fix-pairing-watchdog-reset) but a still had a watch dog reset.
I will try to find more time to investigate but for now I'm hosting some friends and family so do have much to do tecky stuff ^^

@AzonInc
Copy link

AzonInc commented Aug 25, 2024

I'm using a V4 as well and solved it a few months ago by increasing the timeout.
Add esp_task_wdt_init(15, false); to void NukiLockComponent::setup() {}

More details here: AzonInc@1acbb24

App.feed_wdt(); was not enough. But there is probably a more elegant way to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants