prusa3d / PrusaSlicer

G-code generator for 3D printers (RepRap, Makerbot, Ultimaker etc.)
https://www.prusa3d.com/prusaslicer/
GNU Affero General Public License v3.0
7.72k stars 1.93k forks source link

Executing an external program to power-on printer before uploading print #10836

Open stefanct opened 1 year ago

stefanct commented 1 year ago

Since it's now easily possible to directly start prints on remote network printers from within PrusaSlicer it would be nice to be able to turn on the printer automatically too before starting the print. To that end, it would suffice (for me) to be able to execute a script synchronously before PS uploads. The script would then turn on a remotely controllable power plug and wait for the printer's network interface to become ready before returning control to PS. Other use cases could for example be enabling exhaust fans, archiving *.stl files, or starting a video recording of the print.

foreachthing commented 1 year ago

This might help: https://help.prusa3d.com/article/post-processing-scripts_283913

stefanct commented 1 year ago

The post processing scripts are executed at slicing time and/or g-code export time (the documentation on the referenced page unfortunately does not say anything about the execution timing/scheduling). I don't see how this "might help" executing instructions at print time as they might not be the same. Assuming they are executed shortly before the gcode is sent to the printer, is it possible to distinguish this invocation within the scripts from other executions where gcode is produced? Does it also happens on reprints or is the gcode stored/cached somewhere and the scripts only executed once if their input does not change?

bubnikv commented 1 year ago

Post-processing scripts | Prusa Knowledge Base (prusa3d.com) https://help.prusa3d.com/article/post-processing-scripts_283913 SLIC3R_PP_HOST is set to the name of the host you are to send your G-code to PrusaLink, Octoprint ...

po 19. 6. 2023 v 10:51 odesílatel Stefan Tauner @.***> napsal:

The post processing scripts are executed at slicing time and/or g-code export time (the documentation on the referenced page unfortunately does not say anything about the execution timing/scheduling). I don't see how this "might help" executing instructions at print time as they might not be the same. Assuming they are executed shortly before the gcode is sent to the printer, is it possible to distinguish this invocation within the scripts from other executions where gcode is produced? Does it also happens on reprints or is the gcode stored/cached somewhere and the scripts only executed once if their input does not change?

— Reply to this email directly, view it on GitHub https://github.com/prusa3d/PrusaSlicer/issues/10836#issuecomment-1596775565, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMPSI5RWHKK6P3HAUTIM3DXMAHJ5ANCNFSM6AAAAAAZKRL474 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

stefanct commented 1 year ago

Yes, that seems to work. PS waits with the upload till the script is done (naturally, because the script might change the data sent to the printer in the expected use case). The documentation could be a bit more clear (e.g., when exactly the scripts get executed, if they are run serially) but overall I was just not looking at the right stuff. One thing that could definitely be improved is the user feedback: there is no indication that the script is run. It would be great if there would be some kind of activity indicator (ideally the script could report back the progress/liveliness via a pipe or similar).

For reference, this is what I use to turn the Sonoff Tasmota attached to the printer on and wait till its webserver becomes responsive:

#!/bin/sh

printer_host="prusa_mini"
plug_host="sonoff"
plug_user="admin"
plug_pwd="12345"

if [ "${SLIC3R_PP_HOST}" != "PrusaLink" ]; then
  exit 0
fi

while [ "$(curl --max-time 5 --silent --write-out "%{response_code}" -o /dev/null "$printer_host")" != "200" ]; do
  curl -s -m 5 -X POST "http://${plug_host}/cm?user=${plug_user}&password=${plug_pwd}&cmnd=Power%20on"
  sleep 1
done

Feel free to close this if you think the points above are not worth further discussion. Thanks for the help!

foreachthing commented 1 year ago

You could just display a progress [message | bar] in your script. I've done so with python and that works. PS will call the script, your script shows a [command prompt | terminal window] with your message.

stefanct commented 5 months ago

Hm, after an upgrade (to 2.7.4) the above script no longer works. The slicer prints an error message containing "PrusaLink: Error getting storage: Couldn't connect to server" before the script is even executed AFAICT. This is the result from calling get_storage() at https://github.com/prusa3d/PrusaSlicer/blob/dba0377c298ab2752d2f80b5ca89d619bb984415/src/slic3r/GUI/Plater.cpp#L7399 I am not 100% sure about the order of execution. Is this supposed to be executed before post-processing?