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

[bug] zwavejs2mqtt does not reconnect if the serial port (TCP socket) is closed #1246

Closed
4 of 7 tasks
andyboeh opened this issue May 19, 2021 · 7 comments · Fixed by #1259 or #1266
Closed
4 of 7 tasks

[bug] zwavejs2mqtt does not reconnect if the serial port (TCP socket) is closed #1246

andyboeh opened this issue May 19, 2021 · 7 comments · Fixed by #1259 or #1266
Assignees
Labels
bug Something isn't working

Comments

@andyboeh
Copy link

andyboeh commented May 19, 2021

Version

Checklist:

  • I am not using HomeAssistant. Or: a developer has told me to come here.
  • I have checked the troubleshooting section and my problem is not described there.
  • I have read the changelog problem was not mentioned there.

Build/Run method

  • Docker
  • PKG
  • Snap package
  • Manually built (git clone - yarn install - yarn run build )

zwavejs2mqtt version: 4.3.0
zwave-js version: 7.5.0

Describe the bug

In #1167, a problem with detecting a dropped TCP socket connection to the serial device was reported and fixed in zwave-js/node-zwave-js#2601. However, the application needs to handle the lost connection. For now, the state is "Driver: The socket closed unexpectedly". IMHO, zwavejs2mqtt should try to auto-reconnect in this case, as the connection might become available (this could also be a configuration option, like auto-reconnect interval).

It finally reconnects if I go to Settings and click on "Save".

To Reproduce

Steps to reproduce the behavior:

  1. Connect the Z-Wave dongle via ser2net
  2. Stop ser2net
  3. Wait for the lost connection in zwavejs2mqtt
  4. Restart ser2net

Expected behavior

After 4., the connection should be auto-restored.

Additional context

Add any other context about the problem here.

@andyboeh andyboeh added the bug Something isn't working label May 19, 2021
@robertsLando
Copy link
Member

@AlCalzone Shouldn't the reconnection be handled by zwave-js once it comes back?

@AlCalzone
Copy link
Member

AlCalzone commented May 20, 2021

zwave-js/node-zwave-js#2601

Because the driver and controller state may go out of sync in this case, a closed socket will destroy the driver instance, which must be handled by the application - e.g. by restarting or shutting down.

The driver currently has no way of restarting itself.

robertsLando added a commit that referenced this issue May 21, 2021
robertsLando added a commit that referenced this issue May 21, 2021
* fix: detect driver failed and restart

Fixes #1246

* fix: error check

Co-authored-by: AlCalzone <d.griesel@gmx.net>

* fix: emit event before destroy

Co-authored-by: AlCalzone <d.griesel@gmx.net>
@robertsLando
Copy link
Member

@andyboeh Could you check with master?

@andyboeh
Copy link
Author

andyboeh commented May 22, 2021

@robertsLando It does reconnect, but reports a bunch of errors about nodes added twice:

2021-05-22 23:12:06.540 INFO ZWAVE: Controller status: Driver: connect ECONNREFUSED 192.168.17.235:5000
2021-05-22 23:12:06.540 WARN ZWAVE: Retry connection in 3 seconds...
2021-05-22 23:12:09.551 INFO ZWAVE: Connecting to tcp://sczubau.lan:5000
2021-05-22 23:12:09.846 INFO ZWAVE: Next update scheduled for: Sun May 23 2021 00:00:00 GMT+0200 (Central European Summer Time)
2021-05-22 23:12:12.061 INFO ZWAVE: Zwave driver is ready
2021-05-22 23:12:12.062 INFO ZWAVE: Controller status: Driver ready
2021-05-22 23:12:12.063 ERROR ZWAVE: Error while adding node 1 node has been added twice
Error: node has been added twice
at ZwaveClient._addNode (/usr/src/app/lib/ZwaveClient.js:2463:9)
at ZwaveClient._onDriverReady (/usr/src/app/lib/ZwaveClient.js:1732:12)
at Object.onceWrapper (node:events:484:28)
at Driver.emit (node:events:378:20)
at Driver.EventEmitter.emit (node:domain:470:12)
at Driver.initializeControllerAndNodes (/usr/src/app/node_modules/zwave-js/src/lib/driver/Driver.ts:805:8)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at Immediate.<anonymous> (/usr/src/app/node_modules/zwave-js/src/lib/driver/Driver.ts:700:5)
2021-05-22 23:12:12.064 ERROR ZWAVE: Error while adding node 2 node has been added twice
Error: node has been added twice
at ZwaveClient._addNode (/usr/src/app/lib/ZwaveClient.js:2463:9)
at ZwaveClient._onDriverReady (/usr/src/app/lib/ZwaveClient.js:1732:12)
at Object.onceWrapper (node:events:484:28)
at Driver.emit (node:events:378:20)
at Driver.EventEmitter.emit (node:domain:470:12)
at Driver.initializeControllerAndNodes (/usr/src/app/node_modules/zwave-js/src/lib/driver/Driver.ts:805:8)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at Immediate.<anonymous> (/usr/src/app/node_modules/zwave-js/src/lib/driver/Driver.ts:700:5)

[...]

2021-05-22 23:12:12.074 INFO ZWAVE: Scanning network with homeid: xxxxxx
2021-05-22 23:12:12.100 INFO ZWAVE-SERVER: ZwaveJS server listening on port 3000
2021-05-22 23:12:19.771 INFO ZWAVE: Controller status: Scan completed
2021-05-22 23:12:19.773 INFO ZWAVE: Network scan complete. Found: 10 nodes

Afterwards, events from the devices are reported to Home Assistant, but aren't visible in the control panel or in the log file!?

@robertsLando
Copy link
Member

Thanks for the feedback @andyboeh will try to fix it in a new PR

@robertsLando robertsLando reopened this May 24, 2021
robertsLando added a commit that referenced this issue May 24, 2021
robertsLando added a commit that referenced this issue May 24, 2021
@andyboeh
Copy link
Author

Thanks for the quick fix, much appreciated - I tested it again with the latest master docker container and it is working properly now!

@robertsLando
Copy link
Member

Great! Thanks for your feedback @andyboeh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants