alexryd / node-shellies-ng

Handles communication with the next generation of Shelly devices
GNU General Public License v3.0
14 stars 30 forks source link

"Invalid password" after some period #12

Open cbrunnkvist opened 7 months ago

cbrunnkvist commented 7 months ago

I'm observing a consistent issue between my Homebridge and the two Shelly 1 PM that I have connected: it was all fine and dandy. I added password auth on the Shelly devices, and it still works, initially. What seems to happen with homebridge-shelly-ng though is that after a certain amount of time (haven't measured, but it seems to be about 60 mins) of idling, the accessories just stop working, and I see the following in the logs when I try and toggle their switches:

[2/9/2024, 9:11:50 PM] [Shelly NG] [Floor Fan] Failed to set switch: Invalid password
[2/9/2024, 11:05:41 PM] [Shelly NG] [Disco Light] Failed to set switch: Invalid password

I immediately suspected some kind of underlying code-related issue (since I didn't change passwords either in Homebridge or on the devices) so I added rudimentary extra logging to the place where the message originates:

[2/9/2024, 9:11:50 PM] [Shelly NG] [Floor Fan] Failed to set switch: Invalid password (correct-password-here): {"auth_type": "digest", "nonce": 1707487913, "nc": 1, "realm": "shellyplus1pm-441793aaaaaa", "algorithm": "SHA-256"}

so I can only conclude that that far, it looks like we have the right password and we are still seeing a Digest challenge with new nonce and so on.

Restarting the plugin/child-bridge clears the problem, but only until next period.

cbrunnkvist commented 7 months ago

I'm currently resorting to a lame workaround - a systemd timer & service that just pkill:s the named child bridge process every 58th minute - but that's clearly far from optimal.

I'm going to double-check that it is the password auth that provokes the issue, and that it's not something more general related to some missing resource de-allocation.

(I'm NOT using HTTPS btw)

cbrunnkvist commented 7 months ago

Okay, okay... Despite searching for anything similar, I didn't understand where the bug was originally so I didn't register the fact that the root-cause is already documented in both PR:s and Issues. Namely:

I will still opt to leave this issue open for now at least, let's see if @alexryd returns or whether the issue can be fixed by creation of new forks of both projects.

cbrunnkvist commented 7 months ago

Quite tangential topic, but in case anyone wants to replace what could be a crontab oneliner with a recurring systemd timer unit (as used on my Raspbian box), this is how:

# /etc/systemd/system/restart-shelly-ng.service 
[Unit]
Description=Trigger a restart of the Homebridge Shelly-NG plugin

DefaultDependencies=no

[Service]
Type=oneshot
User=1000
# NOTE: this obviously requires you to create a child-bridge for said plugin in Homebridge first
ExecStart=pkill -f 'homebridge: homebridge-shelly-ng'
SuccessExitStatus=0 1

[Install]
WantedBy=multi-user.target
# /etc/systemd/system/restart-shelly-ng.timer 
[Unit]
Description=Trigger Homebridge Shelly NG plugin restart

[Timer]
#OnUnitActiveSec=29min
OnUnitActiveSec=55min

[Install]
WantedBy=timers.target
sudo systemctl enable restart-shelly-ng.service
sudo systemctl enable restart-shelly-ng.timer
sudo systemctl start restart-shelly-ng.service