hansfriedrich / homebridge-feller-wiser

Homebridge Plugin for the Feller Wiser system.
Apache License 2.0
5 stars 2 forks source link

Homebridge FetchError and Socket Hang-Ups with Feller-Wiser Plugin on Raspberry Pi #20

Open Villagio88 opened 1 month ago

Villagio88 commented 1 month ago

Describe The Bug: I am experiencing frequent issues with Homebridge on my Raspberry Pi where I receive HTML instead of JSON responses from API calls, causing the server to crash and preventing scenes from executing properly. There are also frequent socket hang-ups.

To Reproduce:

  1. Start Homebridge with the feller-wiser plugin enabled.
  2. Attempt to control any accessory or trigger any scene.
  3. Observe the error in the Homebridge logs indicating JSON parsing errors and socket hang-ups.

Expected behavior: I expect that API calls should return valid JSON responses and not cause the server to hang or crash. The scenes and accessories should operate smoothly without any interruptions.

Logs: [22/05/2024, 21:34:39] FetchError: invalid json response body at http://192.168.1.XX/api/loads/33/target_state reason: Unexpected token '<', "<!DOCTYPE "... is not valid JSON. [22/05/2024, 21:34:40] This plugin threw an error from the characteristic 'Target Position': Unhandled error thrown inside write handler for characteristic: request to http://192.168.1.XX/api/loads/16/target_state failed, reason: socket hang up. [22/05/2024, 21:34:40] FetchError: request to http://192.168.1.XX/api/loads/13/target_state failed, reason: socket hang up. [More logs related to socket hang-ups and JSON parsing errors]

Plugin Config: { "bridge": { "name": "Homebridge", "username": "XX:XX:XX:XX:XX:XX", "port": XXXXX, "pin": "XXX-XX-XXX" }, "description": "Configuration for Homebridge and Feller-Wiser plugin.", "accessories": [], "platforms": [ { "platform": "FellerWiser", "name": "Feller Wiser", "host": "192.168.1.XX", "username": "username_placeholder", "password": "password_placeholder" } ] }

Environment: Plugin Version: @hansfriedrich/homebridge-feller-wiser@1.0.25 Homebridge Version: 1.8.1 Node.js Version: v20.12.2 NPM Version: 6.14.

hansfriedrich commented 1 month ago

Dear @Villagio88, thanks for reporting this.

Can you ensure, that your accessToken you provided in Config is a valid one? The implementation mainly is mainly following the "happy path" so the json-parsing expects (unchecked) json. Most likely html is return in cases where you're not authenticated.

Thank you in advance.

Villagio88 commented 1 month ago

Thank you for your swift response!

I can confirm that the accessToken provided in the config is valid. Operating individual switches works perfectly; however, when executing scenes, only about half of the actions complete successfully, and then I encounter the errors mentioned previously. This suggests that the issue occurs more frequently when there are multiple simultaneous requests.

Could there be an issue with how the plugin handles multiple simultaneous API calls during scene execution? Maybe it doesn't manage concurrent requests effectively, leading to these errors and partial scene execution.

Below, I have attached a log showing various errors that occur during these operations. You'll notice multiple "socket hang up" errors and "invalid JSON" responses, which seem to happen under the load of multiple requests. These details might help in identifying whether the issue is related to handling simultaneous API calls.

Thanks again for looking into this.

[22/05/2024, 21:34:04] FetchError: request to http://192.168.1.XX/api/loads/5/target_state failed, reason: socket hang up at ClientRequest.<anonymous> (/var/lib/homebridge/node_modules/@hansfriedrich/homebridge-feller-wiser/node_modules/node-fetch/lib/index.js:1491:11) at ClientRequest.emit (node:events:518:28) at Socket.socketOnEnd (node:_http_client:524:9) at Socket.emit (node:events:530:35) at endReadableNT (node:internal/streams/readable:1696:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) [22/05/2024, 21:34:04] Got SIGTERM, shutting down Homebridge... [22/05/2024, 21:34:04] FetchError: request to http://192.168.1.XX/api/loads/14/target_state failed, reason: socket hang up at ClientRequest.<anonymous> (/var/lib/homebridge/node_modules/@hansfriedrich/homebridge-feller-wiser/node_modules/node-fetch/lib/index.js:1491:11) at ClientRequest.emit (node:events:518:28) at Socket.socketOnEnd (node:_http_client:524:9) at Socket emit (node:events:530:35) at endReadableNT (node:internal/streams/readable:1696:12) at processTicks And Rejections (node:internal/process/task_queues:82:21) [22/05/2024, 21:34:06] This plugin threw an error from the characteristic 'Target Position': Unhandled error thrown inside write handler for characteristic: invalid json response body at http://192.168.1.XX/api/loads/3/target_state reason: Unexpected token '<', "<!DOCTYPE "... is not valid JSON. See https://homebridge.io/w/JtMGR for more info. [22/05/2024, 21:34:06] This plugin threw an error from the characteristic 'Target Position': Unhandled error thrown inside write handler for characteristic: request to http://192.168.1.XX/api/loads/16/target_state failed, reason: socket hang up. See https://homebridge.io/w/JtMGR for more info. [22/05/2024, 21:34:06] This plugin threw an error from the characteristic 'Target Position': Unhandled error thrown inside write handler for characteristic: request to http://192.168.1.XX/api/loads/23/target_state failed, reason: socket hang up. See https://homebridge.io/w/JtMGR for more info. [22/05/2024, 21:34:06] FetchError: request to http://192.168.1.XX/api/loads/13/target_state failed, reason: socket hang up at ClientRequest.<anonymous> (/var/lib/homebridge/node_modules/@hansfriedrich/homebridge-feller-wiser/node_modules/node-fetch/lib/index.js:1491:11) at ClientRequest.emit (node:events:518:28) at Socket.socketOnEnd (node:_http_client:524:9) at Socket emit (node:events:530:35) at endReadableNT (node:internal/streams/readable:1696:12) at processTicks And Rejections (node:internal/process/task_queues:82:21) [22/05/2024, 21:34:06] FetchError: request to http://192.168.1.XX/api/loads/22/target_state failed, reason: socket hang up at ClientRequest.<anonymous> (/var/lib/homebridge/node_modules/@hansfriedrich/homebridge-feller-wiser/node_modules/node-fetch/lib/index.js:1491:11) at ClientRequest.emit (node:events:518:28) at Socket.socketOnEnd (node:_http_client:524:9) at Socket emit (node:events:530:35) at endReadableNT (node:internal/streams/readable:1696:12) at processTicks And Rejections (node:internal/process/task_queues:82:21) [22/05/2024, 21:34:06] FetchError: request to http://192.168.1.XX/api/loads/31/target_state failed, reason: socket hang up at ClientRequest.<anonymous> (/var/lib/homebridge/node_modules/@hansfriedrich/homebridge-feller-wiser/node_modules/node-fetch/lib/index.js:1491:11) at ClientRequest.emit (node:events:518:28) at Socket.socketOnEnd (node:_http_client:524:9) at Socket emit (node:events:530:35) at endReadableNT (node:internal/streams/readable:1696:12) at processTicks And Rejections (node:internal/process/task_queues:82:21) [22/05/2024, 21:34:06] This plugin threw an error from the characteristic 'Target Position': Unhandled error thrown inside write handler for characteristic: invalid json response body at http://192.168.1.XX/api/loads/25/target_state reason: Unexpected token '<', "<!DOCTYPE "... is not valid JSON. See https://homebridge.io/w/JtMGR for more info.