kind3r / hass-addons

Integration of the offline TTLock sdk into Home Assistant
63 stars 23 forks source link

Paired but hangs when attempting any function #34

Open MarkGardiner opened 2 years ago

MarkGardiner commented 2 years ago

Hello,

Thank you so much for this project, was over the moon when I saw all you have done.

I have managed to pair my lock but cannot seem to get any functions to work. The UI also seems to become unresponsive (some screens don't load) after I attempt any actions. Here is my log for a an unlock action:

`IGNORE CRC TRUE Debug communication ON Debug MQTT Debug gateway

ttlock-hass-integration@0.2.1 start node ./index.js MQTT connected Monitor started Discovered paired lock: F8:08:70:XX:XX:XX Monitor stopped Peripheral connect start Server started Peripheral connect triggered Peripheral state: connected Device emiting connected BLE Device reading basic info BLE Device discover services start BLE Device discover services end BLE Device read characteristics start BLE Device read characteristics end BLE Device read characteristics start BLE Device read characteristics end BLE Device read basic info BLE Device subscribed Connected to known lock, reading general data ========= feature list Sending command: 7f5a0503010001000101aa001c0d0a Lock waiting for connection to be completed Received response: 7f5a050302000a000c54aa1026033ba449ce33205035b7504424240fc20d0a Bad CRC should be 68 and we got 194 Command: 640004f1f1 <Buffer 64 00 04 f1 f1> ========= feature list Set(11) { 0, 4, 5, 6, 7, 8, 12, 13, 14, 15, 18 } ========= check admin Sending command: 7f5a0503010001000141aa10ae91280a07b04f38d02c4f7a9bda4a5e100d0a Received response: 7f5a050302000a000c54aa1091630a32759dcd907ce9088185c8715ed30d0a Command: 000096da ========= check admin: 38618 ========= check random Sending command: 7f5a0503010001000130aa1052ca51236963709b3fd58b4ef981cdbd9a0d0a Received response: 7f5a050302000a000c54aa10f37ef645a01bd7a0ef05cc4a6704983a090d0a Command: 64 ========= check random ========= autoLockTime Sending command: 7f5a0503010001000136aa10edbdb44f6c2d8af816a9a0a56872924a930d0a Received response: 7f5a050302000a000c54aa1099a17f00e9aedb75158e4a64b748e29b490d0a Command: 640100000005007801 ========= autoLockTime: 0 ========= lockSound Sending command: 7f5a0503010001000162aa10edbdb44f6c2d8af816a9a0a56872924a6d0d0a Received response: 7f5a050302000a000c54aa109b5f3473eb9c01dfdab986abfee228da580d0a Command: 640101 ========= lockSound: 1 Connected to paired lock F8:08:70:XX:XX:XX MQTT Publish homeassistant/lock/f80870xxxxxx/lock/config {"unique_id":"ttlock_f80870xxxxxx","name":"BL01_xxxxxx","device":{"identifiers":["ttlock_f80870xxxxxx"],"name":"BL01_xxxxxx","manufacturer":"Sciener","model":"SN138-AOEL","sw_version":"4.3.3.190429"},"state_topic":"ttlock/f80870xxxxxx","command_topic":"ttlock/f80870xxxxxx/set","payload_lock":"LOCK","payload_unlock":"UNLOCK","state_locked":"LOCK","state_unlocked":"UNLOCK","value_template":"{{ value_json.state }}","optimistic":false,"retain":false} MQTT Publish homeassistant/sensor/f80870xxxxxx/battery/config {"unique_id":"ttlock_f80870xxxxxx_battery","name":"BL01_xxxxxx Battery","device":{"identifiers":["ttlock_f80870xxxxxx"],"name":"BL01_xxxxxx","manufacturer":"Sciener","model":"SN138-AOEL","sw_version":"4.3.3.190429"},"device_class":"battery","unit_of_measurement":"%","state_topic":"ttlock/f80870xxxxxx","value_template":"{{ value_json.battery }}"} MQTT Publish homeassistant/sensor/f80870xxxxxx/rssi/config {"unique_id":"ttlock_f80870xxxxxx_rssi","name":"BL01_xxxxxx RSSI","device":{"identifiers":["ttlock_f80870xxxxxx"],"name":"BL01_xxxxxx","manufacturer":"Sciener","model":"SN138-AOEL","sw_version":"4.3.3.190429"},"unit_of_measurement":"dB","icon":"mdi:signal","state_topic":"ttlock/f80870xxxxxx","value_template":"{{ value_json.rssi }}"} MQTT Publish ttlock/f80870xxxxxx {"battery":100,"rssi":-53,"state":"LOCK"} Successful connect attempt to paired lock F8:08:70:XX:XX:XX ========= get OperationLog 65535 Sending command: 7f5a0503010001000125aa10082c5f08e62ee0de3b76d24f6fa2809e230d0a Received response: 7f5a050302000a000c54aa2035160523704298e4ebece5c18bb035fdae936f7019e3648f1de852231ca946f83c0d0a Command: 001000060d07150a12101618640438353835 ========= get OperationLog 6 Sending command: 7f5a0503010001000125aa10b5deafa0ea08bbcaa53dc86256bcd5a9780d0a Received response: 7f5a050302000a000c54aa20c51c38103fcfdfc2d5b176192d8f0684dd3e45fb1533d521040e37732d71e3327a0d0a Bad CRC should be 99 and we got 122 Command: 001000070d07150a12101622640435353835 ========= get OperationLog 7 Sending command: 7f5a0503010001000125aa10b3cc3215c277fbb25c7205135cfc545e990d0a Received response: 7f5a050302000a000c54aa10c4c708fbbbd73873542a4b60b45b44b50a0d0a Command: 0000 Disconnected from lock F8:08:70:XX:XX:XX`

What am I missing?

kind3r commented 2 years ago

I don't see anything particulary wrong in the logs, except for the usual random CRC errors and that there is no unlock command send (just reading the logs, which it does at startup in general).

First try to restart the addon, let it settle for about 1 min (look at the logs, it should report it's connecting to a known lock to read it's current data), note the last line in the log (should be the disconnected from lock) and then try the unlock from UI. That should be the relevant log.

What I have noticed tho is the firmware version that is rather old (4.3.3 from 2019). You might wanna try pairing with the official app and update (I have 5.1.0 from 2020 on mine). Also, your lock does not seem to have CARD and Fingerprint reader. Could you post a link to the model ?

MarkGardiner commented 2 years ago

Thank you!

Following your steps (after restart the second line below is the disconnect. The following appeard after trying to 'unlock' which was stuck on grey after pressing. Going back to the screen it was blue but pressing it again, it would instantly turn blue and not attempt to load as such (let me know if you would like a har trace or something if it would be useful). ========= get OperationLog 7 Disconnected from lock F8:08:70:XX:XX:XX Connect allready in progress Connect to lock failed F8:08:70:XX:XX:XX Connect allready in progress Connect to lock failed F8:08:70:XX:XX:XX Connect allready in progress Connect to lock failed F8:08:70:XX:XX:XX Connect allready in progress ....

I am not sure if this will give any more insight. Below is a fresh reset, pair and attempt to set a code. Once an action like this is attempted, parts of the UI wont load and it seems unresponsive. Restarting the addon doesn't seem to do much. MQTT logs are full of:

1634555093: Socket error on client , disconnecting. 1634555112: New connection from 172.30.32.2 on port 1883. 1634555112: Socket error on client , disconnecting. 1634555213: New connection from 172.30.32.1 on port 1883.

TTLock addon logs:

[Error: ENOENT: no such file or directory, access '/data/aliasData.json'] { errno: -2, code: 'ENOENT', syscall: 'access', path: '/data/aliasData.json' } MQTT connected Monitor started Server started Monitor stopped BLE Scan started Discovered new lock: {"id":"f80870xxxxxx","manufacturer":"unknown","model":"unknown","hardware":"unknown","firmware":"unknown","address":"F8:08:70:XX:XX:XX","rssi":-54,"protocolType":5,"protocolVersion":3,"scene":2,"groupId":0,"orgId":0,"lockType":5,"isTouch":true,"isUnlock":false,"hasEvents":false,"isSettingMode":true,"txPowerLevel":0,"batteryCapacity":100,"date":0,"isWristband":false,"isRoomLock":true,"isSafeLock":false,"isBicycleLock":false,"isLockcar":false,"isGlassLock":false,"isPadLock":false,"isCyLinder":false,"isRemoteControlDevice":false,"isDfuMode":false,"isNoLockService":false,"remoteUnlockSwitch":0,"disconnectStatus":0,"parkStatus":0,"lockSound":-1,"autoLockTime":-1,"privateData":{},"operationLog":[]} New lock found, stopping scan BLE Scan stopped Refreshing paired locks Monitor started Monitor stopped Peripheral connect start Peripheral connect triggered Peripheral state: connected Device emiting connected BLE Device reading basic info BLE Device discover services start BLE Device discover services end BLE Device read characteristics start BLE Device read characteristics end BLE Device read characteristics start BLE Device read characteristics end BLE Device read basic info BLE Device subscribed Lock waiting for connection to be completed ========= init ========= init ========= AES key ========= AES key: 5bac00990c4XXXXXXXXXXXX ========= admin Setting adminPs XXXXXX and unlockKey XXXXXXX ========= admin: { adminPs: XXXXXXX, unlockKey: XXXXXXXX } ========= time ========= time ========= feature list <Buffer 64 00 04 f1 f1> ========= feature list Set(11) { 0, 4, 5, 6, 7, 8, 12, 13, 14, 15, 18 } ========= lockSound ========= lockSound: 1 ========= autoLockTime ========= autoLockTime: 0 ========= getAdminCode ========= getAdminCode ========= set adminPasscode Generated adminPasscode: XXXXXX SetAdminKeyboardPwdCommand received: <Buffer 64> ========= set adminPasscode: XXXXXX ========= remoteUnlock ========= remoteUnlock: 0 ========= finished ========= finished ========= device info Bad CRC should be 137 and we got 12 Bad CRC should be 137 and we got 12 Bad CRC should be 137 and we got 12 ========= device info: { featureValue: '', modelNum: 'SN138-AOEL_PV53', hardwareRevision: '1.2', firmwareRevision: '4.3.3.190429', nbNodeId: '', nbOperator: '', nbCardNumber: '', nbRssi: -1, factoryDate: '20190626', lockClock: '' } ========= check admin ========= check admin: 57054 ========= check random ========= check random ========= autoLockTime ========= autoLockTime: 0 ========= get passCodes 0 ========= get passCodes { sequence: -1, data: [] } Disconnected from lock F8:08:70:XX:XX:XX Connect allready in progress Connect to lock failed F8:08:70:XX:XX:XX Connect allready in progress Connect to lock failed F8:08:70:XX:XX:XX Connect allready in progress Connect to lock failed F8:08:70:XX:XX:XX Connect allready in progress Connect to lock failed F8:08:70:XX:XX:XX Connect allready in progress Connect to lock failed F8:08:70:XX:XX:XX Connect allready in progress Connect to lock failed F8:08:70:XX:XX:XX Connect allready in progress Connect to lock failed F8:08:70:XX:XX:XX Connect allready in progress Connect to lock failed F8:08:70:XX:XX:XX Connect allready in progress Connect to lock failed F8:08:70:XX:XX:XX

As for updating the firmware, the iphone app reports 'No updates' and version 4.3.3.190429. Visually, the lock I have is: https://ttlock.com.ua/shop/ttlock-rent/ (ttlock rent?). It doesn't have a card or fingerprint reader.

brunosalezze commented 2 years ago

I received my lock yesterday and I'm havind the exact same issue as discribed, I've paired with a phone and upgraded the firmware as instructed to 5.1 (I'm on android) But after a factory reset the lock pairs with the raspberry, but this is the only command I can give, the addon fails to read any credential, change any settings or even unpair it. My log is the following:

ttlock-hass-integration@0.2.1 start node ./index.js MQTT connected Monitor started Server started Discovered paired lock: D8:D9:AE:75:8B:AE Monitor stopped Peripheral connect start Peripheral connect triggered Peripheral state: connected Device emiting connected BLE Device reading basic info BLE Device discover services start BLE Device discover services end BLE Device read characteristics start BLE Device read characteristics end BLE Device read characteristics start BLE Device read characteristics end BLE Device read basic info BLE Device subscribed Connected to known lock, reading general data ========= feature list Lock waiting for connection to be completed <Buffer 55 2c 4c d1 f7> ========= feature list Set(15) { 0, 1, 2, 4, 5, 6, 7, 8, 12, 14, 15, 18, 19, 22, 29 } ========= check admin ========= check admin: 56186 ========= check random ========= check random ========= autoLockTime Bad CRC should be 201 and we got 122 Bad CRC should be 201 and we got 122 Bad CRC should be 201 and we got 122 ========= autoLockTime: 1 ========= lockSound ========= lockSound: 1 Connected to paired lock D8:D9:AE:75:8B:AE Successful connect attempt to paired lock D8:D9:AE:75:8B:AE ========= get OperationLog 65535 ========= get OperationLog 65535 ========= get OperationLog 65535 Disconnected from lock D8:D9:AE:75:8B:AE

And when I try to do anything:

Connect allready in progress Connect to lock failed D8:D9:AE:75:8B:AE Connect allready in progress Connect to lock failed D8:D9:AE:75:8B:AE

MarkGardiner commented 2 years ago

I re-did the steps with the debug flags enabled. After the first disconnect, the log just repeats the "Connect allready in progress" messages.

MarkGardiner commented 2 years ago

Interestingly, I was able to reset, pair and send an unlock command quickly at one point. I am not sure how the handshake and protocol works but is it possible it'll work until the first disconnect? It feels like the software side is getting into a state where it isn't prepared to attempt sending?

kind3r commented 2 years ago

There are lots of quirks in the BLE api (noble) that I had to work around, especially around the connect and disconnect which don't have a builtin timeout etc. Also the lock sometimes behaves haotically, it mostly has a timeout about 8s of idle and then closes connections, but this does not always happen and it closes connection during active communication.

I chose noble because it is cross platform compatible, at least in theory because some behaviours are actually different between various OSes. I will try to look again in the near future for other BLE implementations in node maybe there is something better, maybe linux only.

In my experience, using an ESP32 as a BLE gateway proved to be very reliable with more range (I have a module with an external antena) so maybe you want to give that a try until I find some time to look more into the current issue.

brunosalezze commented 2 years ago

Well, the door lock is installed, but I have an ESP32 WROVER with an external antenna (gateway homing back to the cloud all the time was never an option, my IOT rule is local or die, net goes down but everything is still up). As soon as it arives, I will test it.

MarkGardiner commented 2 years ago

@brunosalezze - did you have any luck with a BLE gateway? If so I may try the same and get my head around setting up an ESP32.

MarkGardiner commented 2 years ago

I flashed an ESP32 gateway but I cannot get the gateway to find the lock. https://github.com/kind3r/esp32-ble-gateway/issues/2#issuecomment-998510676

JesperWe commented 2 years ago

Having the same issue... I'd be happy to assist in debugging if it can be managed somehow. I have HA running in under KVM on an Ubuntu 20 machine.

My lock has firmware 5.1.200320, no updates available when paired with official app.

Like others are reporting, pairing is OK, but no other operation works. I get error message: Connect allready in progress

Below log is from server restart followed by an attempt to save settings:

IGNORE CRC TRUE
Debug communication ON
> ttlock-hass-integration@0.2.1 start
> node ./index.js
MQTT connected
Monitor started
Discovered paired lock: D4:39:49:D6:A4:7A
Monitor stopped
Peripheral connect start
Server started
Peripheral connect triggered
Peripheral state: connected
Device emiting connected
BLE Device reading basic info
BLE Device discover services start
BLE Device discover services end
BLE Device read characteristics start
BLE Device read characteristics end
BLE Device read characteristics start
BLE Device read characteristics end
BLE Device read basic info
BLE Device subscribed
Connected to known lock, reading general data
========= feature list
Sending command: 7f5a0503010001000101aa001c0d0a
Lock waiting for connection to be completed
Received response: 7f5a050302000a002254aa103ea4bffddd9a325e5c57a2589208a0c57a0d0a
Command: 64344cd1f7
<Buffer 64 34 4c d1 f7>
========= feature list Set(16) { 0, 1, 2, 4, 5, 6, 7, 8, 12, 14, 15, 18, 19, 22, 28, 29 }
========= check admin
Sending command: 7f5a0503010001000141aa10999654050bdc0d7a8406cc051d050ae3150d0a
Received response: 7f5a050302000a002254aa10119c0dc3122c0be64d0caef2e0719789c50d0a
Bad CRC should be 8 and we got 197
Command: 000063d2
========= check admin: 25554
========= check random
Sending command: 7f5a0503010001000130aa10b173031c39cdcb545df86a3a29a3cee3230d0a
Received response: 7f5a050302000a002254aa103c91574436208cd41258e39abc5ee517080d0a
Command: 64
========= check random
========= autoLockTime
Sending command: 7f5a0503010001000136aa1056d696acf03a377dff7af39bd517cf0b5e0d0a
Received response: 7f5a050302000a002254aa103ce00ba816151803490574c73bda8671c30d0a
Command: 6401000500050384
========= autoLockTime: 5
========= lockSound
Sending command: 7f5a0503010001000162aa1056d696acf03a377dff7af39bd517cf0ba00d0a
Received response: 7f5a050302000a002254aa104228f8011225b9a71a2c219f2b363433480d0a
Command: 640101
========= lockSound: 1
Connected to paired lock D4:39:49:D6:A4:7A
Successful connect attempt to paired lock D4:39:49:D6:A4:7A
Disconnected from lock D4:39:49:D6:A4:7A
Connect allready in progress
Connect to lock failed D4:39:49:D6:A4:7A