nitaybz / homebridge-switcher-platform

Homebridge plugin for Switcher Smart Accessories
MIT License
35 stars 9 forks source link

Changing the Boiler switch causes HomeBridge to crash #49

Closed tzickel closed 10 months ago

tzickel commented 1 year ago

So I had to change my network setup, and now my RPi running Homebridge is connected to the router via 2 connections (One via Ethernet to the home network, and one via Wifi to the guest network, which the Boiler Switcher).

The plugin manages to update the state of the switch if triggered from outside, but it trying to do it via HomeBridge, it crashes HomeBridge and does not work.

If I has to guess why, it's because the new stupid router, connects the RPi on the same subnet twice (Although the guest network devices can't talk to the home network).

I think that this plugin is sending the commands via the wrong NIC which causes it to crash. Can you add an option in config, to set from which interface (or IP) to send the commands from ? Here is the crash log:


[28/07/2023, 18:29:31] [Switcher Platform] Turning ON Switcher Touch B672 
[28/07/2023, 18:29:31] [Switcher Platform] login...
[28/07/2023, 18:29:31] [Switcher Platform] Received a message from 192.168.0.211
[28/07/2023, 18:29:31] [Switcher Platform] {
  device_id: 'XXX',
  device_ip: '192.168.0.211',
  name: 'Switcher Touch B672',
  type: 'v3',
  state: {
    power: 0,
    remaining_seconds: 0,
    default_shutdown_seconds: 3660,
    power_consumption: 0
  }
}
[28/07/2023, 18:29:34] [Switcher Platform] connection rejected, error: Error: connect EHOSTUNREACH 192.168.0.211:9957
[28/07/2023, 18:29:34] [Switcher Platform] ERROR for Switcher Touch B672
[28/07/2023, 18:29:34] [Switcher Platform] ConnectionError: connection error: failed to connect to switcher on ip: 192.168.0.211:9957. please make sure it is turned on and available.
    at Switcher._getsocket (/var/lib/homebridge/node_modules/homebridge-switcher-platform/node_modules/switcher-js2/src/switcher.js:506:27)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at p_session (/var/lib/homebridge/node_modules/homebridge-switcher-platform/node_modules/switcher-js2/src/switcher.js:686:19) {
  ip: '192.168.0.211',
  port: 9957
}
[28/07/2023, 18:29:34] [Switcher Platform] login failed due to an error Error: connect EHOSTUNREACH 192.168.0.211:9957
[28/07/2023, 18:29:34] [Switcher Platform] ERROR for Switcher Touch B672
[28/07/2023, 18:29:34] [Switcher Platform] Error: login failed due to an error: connect EHOSTUNREACH 192.168.0.211:9957
    at Switcher._login (/var/lib/homebridge/node_modules/homebridge-switcher-platform/node_modules/switcher-js2/src/switcher.js:709:27)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Switcher._run_power_command (/var/lib/homebridge/node_modules/homebridge-switcher-platform/node_modules/switcher-js2/src/switcher.js:801:19)
[28/07/2023, 18:29:34] [Switcher Platform] sending ON command
[28/07/2023, 18:29:34] [Switcher Platform] connection closed, had error: true
[28/07/2023, 18:29:36] [Switcher Platform] Received a message from 192.168.0.211
[28/07/2023, 18:29:36] [Switcher Platform] {
  device_id: 'XXX',
  device_ip: '192.168.0.211',
  name: 'Switcher Touch B672',
  type: 'v3',
  state: {
    power: 0,
    remaining_seconds: 0,
    default_shutdown_seconds: 3660,
    power_consumption: 0
  }
}
[28/07/2023, 18:29:36] [Switcher Platform] Switcher Switcher Touch B672 Watts: 0
[28/07/2023, 18:29:36] [Switcher Platform] Switcher Switcher Touch B672 Volts: 0
[28/07/2023, 18:29:36] [Switcher Platform] Switcher Switcher Touch B672 Amperes: 0
[28/07/2023, 18:29:36] [Switcher Platform] Switcher Switcher Touch B672 Total Consumption (KWh): 0
[28/07/2023, 18:29:37] [Switcher Platform] connection rejected, error: Error: connect EHOSTUNREACH 192.168.0.211:9957
[28/07/2023, 18:29:37] [Switcher Platform] ERROR for Switcher Touch B672
[28/07/2023, 18:29:37] [Switcher Platform] ConnectionError: connection error: failed to connect to switcher on ip: 192.168.0.211:9957. please make sure it is turned on and available.
    at Switcher._getsocket (/var/lib/homebridge/node_modules/homebridge-switcher-platform/node_modules/switcher-js2/src/switcher.js:506:27)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Switcher._run_power_command (/var/lib/homebridge/node_modules/homebridge-switcher-platform/node_modules/switcher-js2/src/switcher.js:806:16) {
  ip: '192.168.0.211',
  port: 9957
}
[28/07/2023, 18:29:37] Error: connect EHOSTUNREACH 192.168.0.211:9957
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)
[28/07/2023, 18:29:37] [Switcher Platform] connection closed, had error: true
[28/07/2023, 18:29:37] Got SIGTERM, shutting down Homebridge...```
tzickel commented 1 year ago

Just checked the if my hypostasis is correct, seems so, here is the Python code:

>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect(("192.168.0.211", 9957))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 113] No route to host
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.setsockopt(socket.SOL_SOCKET, 25, b'wlan0')
>>> s.connect(("192.168.0.211", 9957))
>>> 
tzickel commented 1 year ago

Found a manual temporary workaround, which works :/ (adding static IP to the Switcher)

ip route add 192.168.0.211/32 dev wlan0

Anyhow, even if you don't fix this bug, it shouldn't crash HomeBridge.

dudutwizer commented 1 year ago

how did you solve it? add ip route on the docker?

dudutwizer commented 1 year ago

I solved it by disabling all the other network adapters for homebridge

tzickel commented 1 year ago

I'm not using docker, installed directly on RPi. The current solution I've written above, manual IP routing rules.