neveroddoreven
Posts: 7
Joined: Tue Aug 12, 2014 7:47 pm

Execute terminal commands after the print finishes/stops

Thu Jun 04, 2015 12:49 am

In the Process configuration window's scripts tab, there already exists a post-processing feature to execute a terminal/command after g-code generation has completed. Can this functionality be replicated for two more states?

I would like to invoke a command/terminal executable just prior to starting the print. For example, I wish to call cURL.exe or similar with arguments that tells a home automation device to turn on the mains power to my printer PSU, and perhaps also to turn on an exhaust fan.

I would also like to invoke a command/terminal executable immediately after the print has terminated. If S3D is aware of the termination mode, it would be awesome if that could be passed in via environmental variable (for example, it would be useful to know if the print has successfully completed, versus an abnormal termination due to filament depletion, thermistor problem, printer unresponsiveness, etc.). For example, I wish to call cURL.exe or similar with arguments that tells a home automation device to evaluate some other factors and possibly turn off the mains power to my printer PSU after the print terminates, depending on the termination mode.

EDIT: For those not using home automation, this sort of script could also be used with your favorite command utilities to start a camera stream at the beginning of a print, and play a sound or send an email/text message when your print has finished.
Last edited by neveroddoreven on Sat Jun 06, 2015 7:14 pm, edited 1 time in total.

User avatar
DarthRevan
Posts: 477
Joined: Wed Feb 18, 2015 8:29 am

Re: Execute terminal commands after the print finishes/stops

Fri Jun 05, 2015 3:47 pm

This would be really interesting. Home automation is, by itself, incredibly neat.

neveroddoreven
Posts: 7
Joined: Tue Aug 12, 2014 7:47 pm

Re: Execute terminal commands after the print finishes/stops

Sat Jun 06, 2015 2:34 pm

Yeah, it can be a time suck but really rewarding when it works. My printer is currently only tied into the system by means of a smoke/CO alarm that will immediately cut the printer power if smoke is detected.

KC_703
Posts: 238
Joined: Tue Aug 26, 2014 5:23 pm

Re: Execute terminal commands after the print finishes/stops

Mon Jun 08, 2015 4:39 pm

I've been using a motion sensor to turn off the printer after a certain period of inactivity. The motion sensor sits under my print bed, when it stops moving a script is kicked off to turn the machine off after 20mins. Its saved a lot of late nights waiting for prints to end in the early morning.

PS - also have a smoke/co alarm in the enclosure to shut down the printer on a fire... but I guess that's only half the battle. :)

BaudR8
Posts: 183
Joined: Fri Aug 29, 2014 9:59 am

Re: Execute terminal commands after the print finishes/stops

Tue Jun 09, 2015 12:30 am

depending on the firmware/electronics set up, you may be able to do this. For example, if you have Marlin Firmware:

http://reprap.org/wiki/G-code#M42:_Switch_I.2FO_pin
Example: M42 P7 S255
M42 switches a general purpose I/O pin. Use M42 Px Sy to set pin x to value y, when omitting Px the LEDPIN will be used.
Seems like it will allow you to toggle a gpio pin, so you can edit the ending gcode to toggle an unused GPIO pin and then attach that to your home automation microcontroller

david-hunter
Posts: 4
Joined: Sat May 23, 2020 12:07 am

Re: Execute terminal commands after the print finishes/stops

Wed Sep 30, 2020 6:29 am

This would be a hugely useful feature.

I realise it won't be feasible when saving the gcode files to an SD card, but when controlling the 3D printer directly in S3D, S3D certainly knows when a print has finished (or it should be trivial to know, given that it communicates with the printer in real-time). Therefore, it should be fairly straightforward to run a terminal command once a print is complete.

I'd love to be able to use cURL to send myself an SMS via Twilio, for example, and then turn off my Philips Hue lights and cut power to the printer, all automatically once a print is finished.

david-hunter
Posts: 4
Joined: Sat May 23, 2020 12:07 am

Re: Execute terminal commands after the print finishes/stops

Wed Oct 07, 2020 1:12 am

david-hunter wrote:
Wed Sep 30, 2020 6:29 am
This would be a hugely useful feature.

I realise it won't be feasible when saving the gcode files to an SD card, but when controlling the 3D printer directly in S3D, S3D certainly knows when a print has finished (or it should be trivial to know, given that it communicates with the printer in real-time). Therefore, it should be fairly straightforward to run a terminal command once a print is complete.

I'd love to be able to use cURL to send myself an SMS via Twilio, for example, and then turn off my Philips Hue lights and cut power to the printer, all automatically once a print is finished.
Turns out you can do this if you use Octoprint. I use S3D to create a gcode file, which then gets uploaded to Octoprint (a web server which controls the printer itself). This is done using an Octoprint plugin called "GCODE System Commands". Hope this helps someone.

Return to “Feature Requests”