renssies / homebridge-am43-blinds

A homebridge plugin to control the AM43 based blind motors in HomeKit
MIT License
18 stars 6 forks source link

Plugin makes homebridge server restarting #13

Closed bpelech closed 3 years ago

bpelech commented 4 years ago

When I go into the accessories view in the HB web view after few seconds the server is hit by this error end then it restarts: TypeError: Cannot read property 'writeAsync' of null at AM43Device.sendCommandAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:325:44) at AM43Device.updatePositionAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:281:16) at AM43Device.prepareAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:196:16) at Noble. (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Platform.js:136:16)

TypeError: Cannot read property 'writeAsync' of null at AM43Device.sendCommandAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:325:44) at AM43Device.updatePositionAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:281:16) at AM43Device.prepareAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:196:16) at Noble. (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Platform.js:136:16)

[9/11/2020, 8:28:13 PM] Got SIGTERM, shutting down Homebridge... [9/11/2020, 8:28:13 PM] [am43-blinds] Homebridge is shutting down, disconnecting AM43 motors and saving state

bpelech commented 4 years ago

Update:

  1. loading statuses inside the home app does not seems to have problem with this error
  2. after adding "hap_interaction_timeout": "0", to the config the error changed to:

TypeError: Cannot read property 'writeAsync' of null at AM43Device.sendCommandAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:325:44) at AM43Device.updatePositionAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:281:16) at Characteristic. (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Platform.js:461:32) at Characteristic.emit (events.js:315:20) at Characteristic.EventEmitter.emit (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/EventEmitter.js:60:38) at Characteristic._this.getValue (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Characteristic.js:203:23) at /usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Accessory.js:768:32 at Array.forEach (:null:null) at Bridge.Accessory._this._handleGetCharacteristics (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Accessory.js:709:18) at HAPServer.emit (events.js:315:20) at HAPServer.EventEmitter.emit (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/EventEmitter.js:60:38) at HAPServer._this._handleCharacteristics (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/HAPServer.js:677:23) at IncomingMessage. (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/HAPServer.js:240:39) at IncomingMessage.emit (events.js:315:20) at endReadableNT (_stream_readable.js:1220:12) at processTicksAndRejections (internal/process/task_queues.js:84:21)

TypeError: Cannot read property 'writeAsync' of null at AM43Device.sendCommandAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:325:44) at AM43Device.updatePositionAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:281:16) at Characteristic. (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Platform.js:461:32) at Characteristic.emit (events.js:315:20) at Characteristic.EventEmitter.emit (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/EventEmitter.js:60:38) at Characteristic._this.getValue (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Characteristic.js:203:23) at /usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Accessory.js:768:32 at Array.forEach (:null:null) at Bridge.Accessory._this._handleGetCharacteristics (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Accessory.js:709:18) at HAPServer.emit (events.js:315:20) at HAPServer.EventEmitter.emit (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/EventEmitter.js:60:38) at HAPServer._this._handleCharacteristics (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/HAPServer.js:677:23) at IncomingMessage. (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/HAPServer.js:240:39) at IncomingMessage.emit (events.js:315:20) at endReadableNT (_stream_readable.js:1220:12) at processTicksAndRejections (internal/process/task_queues.js:84:21)

TypeError: Cannot read property 'writeAsync' of null at AM43Device.sendCommandAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:325:44) at AM43Device.updateBatteryStatusAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:287:16) at Characteristic. (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Platform.js:421:30) at Characteristic.emit (events.js:315:20) at Characteristic.EventEmitter.emit (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/EventEmitter.js:60:38) at Characteristic._this.getValue (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Characteristic.js:203:23) at /usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Accessory.js:768:32 at Array.forEach (:null:null) at Bridge.Accessory._this._handleGetCharacteristics (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Accessory.js:709:18) at HAPServer.emit (events.js:315:20) at HAPServer.EventEmitter.emit (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/EventEmitter.js:60:38) at HAPServer._this._handleCharacteristics (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/HAPServer.js:677:23) at IncomingMessage. (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/HAPServer.js:240:39) at IncomingMessage.emit (events.js:315:20) at endReadableNT (_stream_readable.js:1220:12) at processTicksAndRejections (internal/process/task_queues.js:84:21)

TypeError: Cannot read property 'writeAsync' of null at AM43Device.sendCommandAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:325:44) at AM43Device.updateBatteryStatusAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:287:16) at Characteristic. (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Platform.js:421:30) at Characteristic.emit (events.js:315:20) at Characteristic.EventEmitter.emit (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/EventEmitter.js:60:38) at Characteristic._this.getValue (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Characteristic.js:203:23) at /usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Accessory.js:768:32 at Array.forEach (:null:null) at Bridge.Accessory._this._handleGetCharacteristics (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Accessory.js:709:18) at HAPServer.emit (events.js:315:20) at HAPServer.EventEmitter.emit (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/EventEmitter.js:60:38) at HAPServer._this._handleCharacteristics (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/HAPServer.js:677:23) at IncomingMessage. (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/HAPServer.js:240:39) at IncomingMessage.emit (events.js:315:20) at endReadableNT (_stream_readable.js:1220:12) at processTicksAndRejections (internal/process/task_queues.js:84:21)

[9/11/2020, 8:44:33 PM] Got SIGTERM, shutting down Homebridge... [9/11/2020, 8:44:33 PM] [am43-blinds] Homebridge is shutting down, disconnecting AM43 motors and saving state

renssies commented 4 years ago

This looks like an error that can occur when it can discover but not connect to the motor. Try to make sure the blinds engine app is closed on all devices (swipe up). The motor only supports 1 device connected.

bpelech commented 4 years ago

Thanks for the tip. Unfortunately blinds engine app is for sure closed and not making this problem.

There might be another issue somewhere on my side. As I mentioned in the "overcoming 5 min shutdown" issue post - I am connecting to the BT devices via remote Raspbery PI. I'm using this RPI as a USB over IP device (homebridge is running inside the VM on a freenas server and somewhere on the LAN sits RPI with BT usb dongle which is exposed over IP to the homebridge server - see more info here if you are interested: https://derushadigital.com/other%20projects/2019/02/19/RPi-USBIP-ZWave.html)

Today I was messing around with the bluetooth libraries (because of the bt xiaomi hygrothermograph I got recently) and I might broke something for the blinds motor. I'll investigate this further and get back once I'll solve it.

Thanks!

renssies commented 4 years ago

I forgot to comment on this issue: I did an update yesterday that could possibly fix this as well.

bpelech commented 4 years ago

Plugin still keeps crashing the whole homebridge. To be sure, I reinstalled the plugin, but unfortunately, it keeps crashing. This is a bummer, since I possible found the solution to overcome that 5 min autostop.

Output in the console: TypeError: Cannot read property 'writeAsync' of null at AM43Device.sendCommandAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:332:44) at AM43Device.updatePositionAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:288:16) at Characteristic. (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Platform.js:461:32) at Characteristic.emit (events.js:315:20) at Characteristic.EventEmitter.emit (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/EventEmitter.js:60:38) at Characteristic._this.getValue (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Characteristic.js:203:23) at /usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Accessory.js:782:32 at Array.forEach (:null:null) at Bridge.Accessory._this._handleGetCharacteristics (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Accessory.js:723:18) at HAPServer.emit (events.js:315:20) at HAPServer.EventEmitter.emit (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/EventEmitter.js:60:38) at HAPServer._this._handleCharacteristics (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/HAPServer.js:677:23) at IncomingMessage. (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/HAPServer.js:240:39) at IncomingMessage.emit (events.js:315:20) at endReadableNT (_stream_readable.js:1220:12) at processTicksAndRejections (internal/process/task_queues.js:84:21)

TypeError: Cannot read property 'writeAsync' of null at AM43Device.sendCommandAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:332:44) at AM43Device.updatePositionAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:288:16) at Characteristic. (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Platform.js:461:32) at Characteristic.emit (events.js:315:20) at Characteristic.EventEmitter.emit (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/EventEmitter.js:60:38) at Characteristic._this.getValue (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Characteristic.js:203:23) at /usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Accessory.js:782:32 at Array.forEach (:null:null) at Bridge.Accessory._this._handleGetCharacteristics (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Accessory.js:723:18) at HAPServer.emit (events.js:315:20) at HAPServer.EventEmitter.emit (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/EventEmitter.js:60:38) at HAPServer._this._handleCharacteristics (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/HAPServer.js:677:23) at IncomingMessage. (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/HAPServer.js:240:39) at IncomingMessage.emit (events.js:315:20) at endReadableNT (_stream_readable.js:1220:12) at processTicksAndRejections (internal/process/task_queues.js:84:21)

[10/5/2020, 5:25:36 PM] Got SIGTERM, shutting down Homebridge...

bpelech commented 4 years ago

FYI for anyone interested on that 5 min limit - I intend to use combination of:

First that came to my mind is having a fake switches to open and close and those switches will set timer that will virtually keep pressing up or down for pre-set period of time. Motor seems to behave in a way that if it is already in the up/down limit position it ignores up/down commands.

bpelech commented 4 years ago

Interestingly it looks like it always crash during scanning for the Xiaomi hygrotermograph. Not sure if it's related (probably it is), but the TypeError and HB restart always pops up after "[Temperature & Humidity] Start scanning.". Always. How can scanning for other BT device affect this plugin?

Console output: [10/5/2020, 5:36:28 PM] [Temperature & Humidity] Start scanning. TypeError: Cannot read property 'writeAsync' of null at AM43Device.sendCommandAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:332:44) at AM43Device.updatePositionAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:288:16) at PlatformAccessory.accessory.updateInformation (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Platform.js:281:29) at poll (/usr/lib/node_modules/homebridge-am43-blinds/node_modules/poll/dist/cjs/poll.js:16:9)

TypeError: Cannot read property 'writeAsync' of null at AM43Device.sendCommandAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:332:44) at AM43Device.updatePositionAsync (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:288:16) at PlatformAccessory.accessory.updateInformation (/usr/lib/node_modules/homebridge-am43-blinds/lib/AM43Platform.js:281:29) at poll (/usr/lib/node_modules/homebridge-am43-blinds/node_modules/poll/dist/cjs/poll.js:16:9)

[10/5/2020, 5:41:18 PM] Got SIGTERM, shutting down Homebridge...

renssies commented 4 years ago

I do not have the Xiaomi hygrothermograph.

Could you download the nRF Connect app on an iPhone (or Android) and see if there are UUIDs of Services or characteristics that are the same between the Xiaomi hygrothermograph and the blinds engine?

neil-morrison44 commented 4 years ago

@renssies I started an experimental branch a couple of weeks back where I tried to look into these things at https://github.com/neil-morrison44/homebridge-am43-blinds/tree/nm/slats_experiment

There's some stuff that's probably worth PRing into here but it wasn't the "fix everything" solution I was looking for (nor did I actually experiment with slats...)

Have a look, see what you think - on the whole it's not much of an improvement stability-wise to what I was getting on the master branch on the Raspberry Pi 3. (Also only tested on the Raspberry Pi 3).

renssies commented 4 years ago

@neil-morrison44 Sorry for the late reply, I'm working on something with a rather tight deadline but I finally have some time off.

Like I'm said I'm not that good at JavaScript/Node so every change that others think is an improvement I will accept.

As long as the user doesn't have to reconfigure anything I'm happy to merge it into main if you create a PR with the changes.

If you're not comfortable with that I could also make a develop branch and merge it into that instead.

bpelech commented 4 years ago

Hi @renssies , sorry for late reply.

After a while I decided to throw away the setup I had and just went with pure Homebridge on rpi. Both your and homebridge-mi-hygrothermograph plugins works fine and out of the box.

However, the log is flooded with these: (node:639) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'writeAsync' of null at AM43Device.sendCommandAsync (/usr/local/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:343:44) at AM43Device.updateBatteryStatusAsync (/usr/local/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:305:16) at Characteristic.<anonymous> (/usr/local/lib/node_modules/homebridge-am43-blinds/lib/AM43Platform.js:421:30) at Characteristic.emit (events.js:315:20) at Characteristic.EventEmitter.emit (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/EventEmitter.ts:42:22) at Characteristic._this.getValue (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:489:12) at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1217:22 at Array.forEach (<anonymous>) at Bridge.Accessory._this._handleGetCharacteristics (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1145:10) at HAPServer.emit (events.js:315:20) (node:639) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag--unhandled-rejections=strict(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 84)

FYI I'm using:

renssies commented 4 years ago

Hmm, this is once again something I can't reproduce on my end.

However, I did see an issue from Neil (#20) that might be related to this. I will wait until Neil knows more

neil-morrison44 commented 4 years ago

I've not actually seen the 'writeAsync' of null issue since the "possible fix for fe51 error" commit went in, was getting it a lot before then - now, at least for me, it appears to be trying to reconnect before writing (even if that connection ends up failing)

bpelech commented 3 years ago

Hi guys, I'm back at the beginning. As I mentioned before, I changed the setup and I'm running pure homebridge on raspbery pi with BT dongle plugged directly to rpi. What's happening now is quite the same as it did at the beginning (see my first post). But now on a different setup.

Now, everytime when homekit (or homberidge) loads the status from the plugin, it crashes the homekit.

Once I open homekit, or loads accessories in homebridge there is this error in the logs and HB crashes: TypeError: Cannot read property 'writeAsync' of null at AM43Device.sendCommandAsync (/usr/local/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:343:44) at AM43Device.updateBatteryStatusAsync (/usr/local/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:305:16) at Characteristic.<anonymous> (/usr/local/lib/node_modules/homebridge-am43-blinds/lib/AM43Platform.js:421:30) at Characteristic.emit (events.js:315:20) at Characteristic.EventEmitter.emit (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/EventEmitter.ts:42:22) at Characteristic._this.getValue (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:489:12) at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1217:22 at Array.forEach (<anonymous>) at Bridge.Accessory._this._handleGetCharacteristics (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1145:10) at HAPServer.emit (events.js:315:20) TypeError: Cannot read property 'writeAsync' of null at AM43Device.sendCommandAsync (/usr/local/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:343:44) at AM43Device.updateBatteryStatusAsync (/usr/local/lib/node_modules/homebridge-am43-blinds/lib/AM43Device.js:305:16) at Characteristic.<anonymous> (/usr/local/lib/node_modules/homebridge-am43-blinds/lib/AM43Platform.js:421:30) at Characteristic.emit (events.js:315:20) at Characteristic.EventEmitter.emit (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/EventEmitter.ts:42:22) at Characteristic._this.getValue (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:489:12) at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1217:22 at Array.forEach (<anonymous>) at Bridge.Accessory._this._handleGetCharacteristics (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1145:10) at HAPServer.emit (events.js:315:20) [14/11/2020, 22:40:34] Got SIGTERM, shutting down Homebridge...

I have to stop using the plugin unfortunately, since it's making my whole HB unstable and unusable.

@renssies if you need something from me to help you debug the issue, just let me know. I'll do my best to help.

renssies commented 3 years ago

Since this issue seems to happen for more people I've created a new issue with some more information to help me find the root of this issue: https://github.com/renssies/homebridge-am43-blinds/issues/21.

@bpelech in the issue you can find some things to help me find the root of this issue.

I will be closing this issue to keep everything tidy.