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

Refresh USB-OTG g_mass_storage after file upload/delete #20

Open
bwright86 opened this issue Mar 22, 2022 · 4 comments
Open

Refresh USB-OTG g_mass_storage after file upload/delete #20

bwright86 opened this issue Mar 22, 2022 · 4 comments

Comments

@bwright86
Copy link

Could support be added to refresh the USB-OTG "piusb.bin" file after certain events?

I'm wondering if there are hooks in Octoprint that could run system commands after events occur?

Step 10 of this article shares steps to "unplug/Plug" the media, so the printer can pickup the new files:
https://magpi.raspberrypi.com/articles/pi-zero-w-smart-usb-flash-drive

Essentially the steps are:

  • Plug in drive:
    sudo modprobe g_mass_storage file=/piusb.bin stall=0 ro=1
  • Unplug drive:
    sudo modprobe -r g_mass_storage

It would be nice to have some blocking in place, if a file is being printed.
Exposing some configuration settings, so this could be disabled if it cause issues, could be helpful.

But i'm also not sure what happens to a resin printer when the drive is pulled during a print. Does it pause? Does it cancel?
I might have to try this and see...

@bwright86
Copy link
Author

It would probably help to share my printer model and software version, to help snapshot this issue. I think some resin printers do refreshes the USB Drive contents automatically.

Printer Model: Anycubic Photon Mono X
Printer Firmware: v3.5.4
octopi_version: 0.18.0
octopiuptodate_build: 0.18.0-1.7.3-20220120112925
python.pip: 20.3.3
python.version: 3.7.3

@bwright86
Copy link
Author

I've found that OctoPrint has an Event Manager section in the settings. I am currently leveraging this to run a System command.

It appears the have some decent events to trigger on, like: FileAdded, FileRemoved, Upload, UpdatedFiles

Based on debug logging, it appears UpdatedFiles event is triggered during both Upload and FileRemoved. So this seems to cover both or all scenarios of file changes.

I am currently using the following command to refresh the USB Drive contents:
sleep 5 && sudo modprobe -r g_mass_storage && sudo modprobe g_mass_storage file=/piusb.bin stall=0 ro=1

Currently, the debug shows that sleep commands are removed. I will have to play around with getting some delay introduced. Right now, Upload needs about 2 seconds for the filesystem to stabilize, and FileRemoved needs about 5-10 seconds, as it is triggered before the system removes the file.

@rudetrooper
Copy link
Owner

I don't do this in the plugin because its generally bad practice to run sudo commands within a python application.

@bwright86
Copy link
Author

Fair point, I’ve been looking to see if there are projects to do this “as a user”. There appears to be python-FunctionFS project that might be able to do this.

The hardest part is figuring out when to “unplug/plug” for a refresh. I wouldn't want to do this during a print. So knowing whether a print is in progress would be helpful to block the “unplug/plug” function.

I want to say there is a way to block “uploads” during a print. I’m not in a good place to check this right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants