oyooyo / keyble

Command line tools and library for controlling eqiva eQ-3 Bluetooth smart locks
91 stars 28 forks source link

UnhandledPromiseRejectionWarning and other errors #34

Open corgan2222 opened 3 years ago

corgan2222 commented 3 years ago

I tried now for months to get this running stable, but every few minutes it stopped working. And i can't really reproduce the problem. Its such a strange behavior.

I restart bluetooth, the restart the keyble-mqtt service. And some seconds later i get this error.

18:52:03 raspizero2 keyble-mqtt.sh[23658]: (node:23659) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'write' of undefined │ 18:52:03 raspizero2 keyble-mqtt.sh[23658]: at Key_Ble.send_message_fragment (/opt/nodejs/lib/node_modules/keyble-mqtt/node_modules/keyble/keyble.js:498:28) │ 18:52:03 raspizero2 keyble-mqtt.sh[23658]: at processTicksAndRejections (internal/process/task_queues.js:93:5) │ 18:52:03 raspizero2 keyble-mqtt.sh[23658]: at async Key_Ble.send_message_fragments (/opt/nodejs/lib/node_modules/keyble-mqtt/node_modules/keyble/keyble.js:506:4) │ 18:52:03 raspizero2 keyble-mqtt.sh[23658]: at async Key_Ble.send_message (/opt/nodejs/lib/node_modules/keyble-mqtt/node_modules/keyble/keyble.js:530:3) │ 18:52:03 raspizero2 keyble-mqtt.sh[23658]: at async Key_Ble.ensure_nonces_exchanged (/opt/nodejs/lib/node_modules/keyble-mqtt/node_modules/keyble/keyble.js:575:3) │ 18:52:03 raspizero2 keyble-mqtt.sh[23658]: at async Key_Ble.send_message (/opt/nodejs/lib/node_modules/keyble-mqtt/node_modules/keyble/keyble.js:513:4) │ 18:52:03 raspizero2 keyble-mqtt.sh[23658]: at async Key_Ble.send_command (/opt/nodejs/lib/node_modules/keyble-mqtt/node_modules/keyble/keyble.js:405:3) │ 18:52:03 raspizero2 keyble-mqtt.sh[23658]: at async Key_Ble.lock (/opt/nodejs/lib/node_modules/keyble-mqtt/node_modules/keyble/keyble.js:364:3) │ 18:52:03 raspizero2 keyble-mqtt.sh[23658]: at async MqttClient. (/opt/nodejs/lib/node_modules/keyble-mqtt/keyble-mqtt.js:159:7) │ 18:52:03 raspizero2 keyble-mqtt.sh[23658]: (Use node --trace-warnings ... to show where the warning was created) │ 18:52:03 raspizero2 keyble-mqtt.sh[23658]: (node:23659) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or │ 18:52:03 raspizero2 keyble-mqtt.sh[23658]: (node:23659) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js p│

grafik

Then i repeat this, restart BT and keyble i got a different error from noble

│ │May 19 18:55:03 raspizero2 keyble-mqtt.sh[23658]: /opt/nodejs/lib/node_modules/keyble-mqtt/node_modules/@abandonware/noble/lib/hci-socket/hci.js:120 │ │May 19 18:55:03 raspizero2 keyble-mqtt.sh[23658]: this._socket.bindRaw(this._deviceId); │ │May 19 18:55:03 raspizero2 keyble-mqtt.sh[23658]: ^ │ │May 19 18:55:03 raspizero2 keyble-mqtt.sh[23658]: Error: EALREADY, Operation already in progress │ │May 19 18:55:03 raspizero2 keyble-mqtt.sh[23658]: at Hci.init (/opt/nodejs/lib/node_modules/keyble-mqtt/node_modules/@abandonware/noble/lib/hci-socket/hci.js:120:18) │ │May 19 18:55:03 raspizero2 keyble-mqtt.sh[23658]: at Hci.pollIsDevUp (/opt/nodejs/lib/node_modules/keyble-mqtt/node_modules/@abandonware/noble/lib/hci-socket/hci.js:135:14) │ │May 19 18:55:03 raspizero2 keyble-mqtt.sh[23658]: at listOnTimeout (internal/timers.js:554:17) │ │May 19 18:55:03 raspizero2 keyble-mqtt.sh[23658]: at processTimers (internal/timers.js:497:7) { │ │May 19 18:55:03 raspizero2 keyble-mqtt.sh[23658]: errno: 114, │ │May 19 18:55:03 raspizero2 keyble-mqtt.sh[23658]: code: 'EALREADY', │ │May 19 18:55:03 raspizero2 keyble-mqtt.sh[23658]: syscall: 'bind' │ │May 19 18:55:03 raspizero2 keyble-mqtt.sh[23658]: }

grafik

And now, if I repeat this one more time, restart bt and keyble, I get this smp error, but keyble does the job and turn the key. At first i was worried about the snp error, but now its a hint that the communication is working.

grafik

This behavior is completely random. ATM i have a cron job running, which restarts BT and keyble every 5min, but even with this, the chance that the look opens if needed are <50%.

Is there anything i can do to help?

corgan2222 commented 3 years ago

running on a pi zero

Linux raspizero2 5.10.17+

Drivers: ii bluetooth 5.50-1.2~deb10u1+rpt2 all Bluetooth support (metapackage) ii bluez 5.50-1.2~deb10u1+rpt2 armhf Bluetooth tools and daemons ii bluez-firmware 1.2-4+rpt8 all Firmware for Bluetooth devices ii bluez-hcidump 5.50-1.2~deb10u1+rpt2 armhf Analyses Bluetooth HCI packets ii libbluetooth-dev:armhf 5.50-1.2~deb10u1+rpt2 armhf Development files for using the BlueZ Linux Bluetooth library ii libbluetooth3:armhf 5.50-1.2~deb10u1+rpt2 armhf Library to use the BlueZ Linux Bluetooth stack ii lxplug-bluetooth 0.21 armhf Bluetooth plugin for lxpanel ii pi-bluetooth 0.1.16 all Raspberry Pi 3 bluetooth ii pulseaudio-module-bluetooth 12.2-4+deb10u1+rpi3 armhf Bluetooth module for PulseAudio sound server

jeeck-jan commented 1 year ago

Had the same problems for a long time. Found a solution by mirovdm/le_autoconnect_timeout.md in github "This tool changes default HCI_LE_AUTOCONN_TIMEOUT for Bluetooth adapter on Linux" And it works fine !

oyooyo commented 1 year ago

Hello @jeeck-jan, could you provide a link where I can find some more information on this?

jeeck-jan commented 1 year ago

https://gist.github.com/mironovdm/cb7f47e8d898e9a3977fc888d990e8a9 [https://github.githubassets.com/images/modules/gists/gist-og-image.png]https://gist.github.com/mironovdm/cb7f47e8d898e9a3977fc888d990e8a9 Change LE autoconnect timeout · GitHubhttps://gist.github.com/mironovdm/cb7f47e8d898e9a3977fc888d990e8a9 Clone via HTTPS Clone with Git or checkout with SVN using the repository’s web address. gist.github.com greetings,

Jan Eeckhout


Van: oyooyo @.> Verzonden: woensdag 14 december 2022 18:58 Aan: oyooyo/keyble @.> CC: jeeck-jan @.>; Mention @.> Onderwerp: Re: [oyooyo/keyble] UnhandledPromiseRejectionWarning and other errors (#34)

Hello @jeeck-janhttps://github.com/jeeck-jan, could you provide a link where I can find some more information on this?

— Reply to this email directly, view it on GitHubhttps://github.com/oyooyo/keyble/issues/34#issuecomment-1351864536, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOBJH3PVJPPRJEUNT6S5NM3WNIDEVANCNFSM45FDLIMA. You are receiving this because you were mentioned.Message ID: @.***>

oyooyo commented 1 year ago

@jeeck-jan Thanks!

jeeck-jan commented 1 year ago

Some advice to make keyble software function fast and sure : for raspberry pi

1 enable bluetooth in /boot config.txt #dtoverlay=disable-bt 2 enable hciuart : sudo systemctl start hciuart 3 trust doorlock : sudo bluetoothctl trust xx:xx:xx:xx:xx (doorlock mac adresss), this is not so easy, do it in loop in python or manually in bluetoothctl (several times till successful); you only have to do this one's : stays in raspi's memory : this speeds up
connection 4 adjust le connect timeout : see above (you can do this one's at every pi reboot ) 5 do not change settings for --status_update_time : if to short your commands will be overruled by the status command, and the doorlock will not move. (and you don't know what's happening) 6 I change the setting for timeout --timeout to 20, if you don't get a reaction after 10 seconds, you won't get any. This setting is not realy necessary : I always have reaction in less than 10 seconds. 7 this is very important : before sending a command : stop bluetooth (sudo systemctl stop bluetooth), and then start bluetooth (sudo systemctl start bluetooth), then send your command

That's it.

For me 100% successfull commands, time between command and moving the lock = 4 to 6 seconds (medium 5s)

Have fun !