How to send GCODE commands from the cli?

Not sure if 'Get Help' is the best category for this but 'General' seemed too general for it so here it goes...

How would I issue a single GCODE to my printer from a bash script?

I wrote a bash script to run after a new firmware build that checks some things, names and archives that particular build, scps it to printhost:/media/usb0, -
and there it is stuck. I would like it to issue some magic spell to have M997 go to the printer, then it waits a while and finally checks if the boot loader managed to rename the .bin to FIRMWARE.CUR or failed to do so (as it happens a lot recently, slowing the boot...)

I realize I could use mosquitto_pub to switch the power (controlled by a Tasmota) off and on again, that would force a reboot. So I'm not entirely helpless, it's more like:
can it be done?

Use the API with something like curl:

https://docs.octoprint.org/en/master/api/printer.html#send-an-arbitrary-command-to-the-printer

1 Like

ahh! I wasn't aware of that, will check this out.
Thank you so much for replying instantly

works like a charm once I got the syntax right.
I post it here in case someone gets here later from a search and is unsure about the syntax like I was.

curl -X POST -H "Content-Type: application/json" -H "X-Api-Key":"abcdef" -d '{"command":"M117 hello world"}' http://printhost.local/api/printer/command

1 Like