kantlivelong / OctoPrint-PSUControl

Smart control of your power supply via GPIO, GCODE Command, System Command, or variety of sub-plugins.
GNU Affero General Public License v3.0
202 stars 112 forks source link

Connect on external power on #229

Open oerkel47 opened 2 years ago

oerkel47 commented 2 years ago

Thank you for your interest into contributing to OctoPrint-PSUControl, it's highly appreciated!

Before submitting please make sure you have ticked all points on this checklist:

Feel free to delete all this help text, then describe your PR further. You may use the template provided below to do that. The more details the better!


What does this PR do and why is it necessary?

Adds option to connect the printer when the relay/switch is controlled from outside of psu control.

How was it tested? How can it be tested by the reviewer?

Turn on relay externally and see if it connects.

Any background context you want to provide?

What are the relevant tickets if any?

discussion in discord

Screenshots (if appropriate)

Further notes

Dunstkreis commented 2 years ago

copied this into my setup. Nice and useful feature cos when I power my printer on any other way than through PSU control it was not connected. So I wasnt able to start a print right away (like from PrusaSlicer). But I think this could need a "disconnect on external power off" function too?

oerkel47 commented 2 years ago

But I think this could need a "disconnect on external power off" function too?

I don't think this is possible, because PSU Control has no way of knowing that you will turn off the relay if you do it externally. So it can not disconnect properly before turning off.

Dunstkreis commented 2 years ago

Yeah I know. But that was not my intention. After powering off two things happen here. Either after about 35ish seconds I get an error message saying something about communication loss. Or if I turn the power on within this time I get the info about a printer reset.

Both is kinda correct but I just though, well its PSU is off, we dont need to wait for the error message to know its disconnected. We could just trigger the disconnect right away.

Within the timeout and regarding the "printer reset" message, aka Octoprint kinda recovering the connection, this wont be necessary if we reconnect after external PSU switching on. We will end up with a running connection to the printer.

So we would not need to keep trying if the printer comes back online (while PSU off) and we could just depend on this feature to reconnect after power is back on.

Yeah, we would loose the info box about the printer reconnect. So we could just go with something in between, lets wait 10 secs or any given time out (like half of timeout for reconnecting and the error message) and then lets just trigger the Octoprint disconnect.

Obviously this should only work and only be active if "connect on external power on" is active.

oerkel47 commented 2 years ago

I see. My printer behaves differently apparently. Octoprint will instantly go to "Offline after error" when I shut it off externally and it didn't bother me.

You could try adding the disconnect to the code and see if does the trick. Also, I just saw your post and PR. Check out the different branch in my fork of PSU Control. It implements some more changes, also related to the turn on and start printing things, and should be a fix for that.