Best Octopi Power arrangement?

I'm currently running Octoprint on my Ubuntu Linux server machine with a TP Link wireless power outlet. I can turn off power to the printer via the TP Link outlet remotely as necessary. In general, this works pretty well, but every so often it ends up that my Ubuntu server can no longer "see" the printer via USB and I'm forced to restart the server. Given that the server drives a lot of things in the house, it is a huge pain to be forced to reboot the server.

I've been considering switching over to an Octopi setup instead, with the Pi driven off of a buck converter connected to my PSU. However, if I do that, I can't see how to avoid corrupting the SD card when the power is cut off.

How do other people handle this kind of setup? The other (better?) option would be if I was able to reset the USB subsystem on my current server setup without having to restart the whole server machine. Suggestions would be welcome there as well.

Thanks,
Craig

With my TPLink plugin you can configure the plug in a way to utilize the built in countdown timers of the device to delay the power off of the printer, which allows the use of the system command option to shutdown the pi prior to power off. There was a recent discussion about it over here, which ended up leading to updates to one of my other plugins, but there is a screenshot in that thread for tplink.

I am running your plugin, so that does seem like a potential option. Usually, when I kill power I do it directly via the Kasa app, which I assume would cause issues?

I'd really like to figure out why my server stops seeing the printer (MKS Gen L in this case), since it would allow me to leave everything else alone.

Yeah, that would still be a problem using the kasa app. I remember am old plugin that I'm not sure was ever published to the repo that would monitor for USB connection changes and attempt to auto connect when it saw a new device, which might be all you need. Of course I'm no linux guru so not sure if it would help. Have you tried just restarting octoprint instead of the whole machine?

This isn't the one I was thinking of, but could be promising.

Thanks. I will take a look. Unfortunately, when it goes "wrong", it doesn't even show in "lsusb" output, so I don't think that Octoprint can do anything at that point. I need to figure out why Linux isn't seeing it. At least this plugin is tied to UDEV.

I have the ModMyPi UPSPico hat. Has a delay after power is cut and performs a proper shutdown.

How hard would it be to do something like this: https://core-electronics.com.au/tutorials/how-to-make-a-safe-shutdown-button-for-raspberry-pi.html and use it to trigger the shutdown of the Pi as well as a delayed power-off for the TP Link plug? Can you point me to any good documentation on talking to the TP Link plugs?

My plugin was based on code from here.It has some fairly good documentation, but very technical. There is a link to the available commands there and you'd have to use the countdown timer options in order to pass off the command to the plug prior to shutdown. There may be a fork of that repository that modularizes the python library, at least I vaguely remember coming across one after I had gotten too far in development of my plugin. What I did was grab the encode/decode scripts from softScheck's python script with some minor changes from it's issue logs and pull requests and wrapped my own send command function within the plugin to send the encoded json commands to the plug. You could just grab those functions from my plugin's __init__.py file in my repo and modify to suit your needs as well.

Hi,

I use OctoPi along with a TP-Link plug and the PSU control plugin. My RPi is running 24x7, and I have not experienced what you are seeing. It happily recognizes and connects to my Creality CR10s Pro when I turn it on although I often have to click the connect button twice.

In order to make everything work, I wrote some simple python code (using this Python module) to turn the plug on/off and deliver the status although I think that this plugin might avoid that. I typically allow PSU Control to turn off my printer automatically versus doing it manually as well.

I see your buck converter suggestion and am scratching my head over why you would need that. My scripts could be modified to shutdown the pi quite easily, if you want.

Edit: One more thought, I am sure that there is a way to cleanly disconnect a USB device before poweroff. Another option would be to modify my poweroff script to first disconnect before powering off. It could solve your problem. I am happy to share the code. It is pretty simple.

I actually found or created some code to reset the USB bus.
The device always ends up in the same place, so I can reset it at USB level.
Now I am using an old OrangePi to control the printer. And I have the Pi able to control a $5 Sonoff powerswitch with better firmware. I never had issues on my Pi (or maybe I just reboot it). But I had on my Ubuntu running N54L.

#!/usr/bin/env python
import os
import sys
from subprocess import Popen, PIPE
import fcntl
driver = sys.argv[-1]
print "resetting driver:", driver
USBDEVFS_RESET= 21780

try:
    lsusb_out = Popen("lsusb | grep -i %s"%driver, shell=True, bufsize=64, stdin=PIPE, stdout=PIPE, close_fds=True).stdout.read().strip().split()
    bus = lsusb_out[1]
    device = lsusb_out[3][:-1]
    f = open("/dev/bus/usb/%s/%s"%(bus, device), 'w', os.O_WRONLY)
    fcntl.ioctl(f, USBDEVFS_RESET, 0)
except Exception, msg:
    print "failed to reset device:", msg
2 Likes

Also found this:
http://billauer.co.il/blog/2013/02/usb-reset-ehci-uhci-linux/

Should be another way. You can likely replace some ???? with specific value(s)

It might be helpful to know how you call the script since it's referring to argv[].

Thanks to everyone for their help. At the moment, I'm just using the TP Link plugin to shut everything down, using the built in delays in that plugin.