Control octoprint from printer?

Is there already a way to pause/continue/abort/restart a print directly from the printer menu? That would be really handy since I often don't have my notebook/phone nearby or running when taking a look at the current messed up print. I'm thinking of a new menu section in marlin that would send serial commands and thus trigger events in octoprint. Is there a protocol/specification for data pushed from the printer (like those temperature updates) and is it possible to process these in a plugin?

Klipper can do something like that. At least, I've seen the option on my own printer.

Yep, see here: http://docs.octoprint.org/en/master/features/action_commands.html

Yeah, got it. Here is my complete solution (since there is no native "start job" command):

  1. Python script to execute Octoprint API calls
#!/home/octoprint2/OctoPrint/bin/python

OCTOPRINT_URL = 'http://localhost:5001/api/'
API_KEY = '***'

import requests
import sys

port = sys.argv[1]
headers = {'X-Api-Key': API_KEY}
json = {
  "command": sys.argv[1]
}
r = requests.post(
        OCTOPRINT_URL + "job",
        json=json,
        headers=headers
)

if (r.status_code == 204):
    json = {
      "command": "M117 Octo \"" + sys.argv[1] + "\" done."
    }
else:
    json = {
      "command": "M117 Octo \"" + sys.argv[1] + "\" failed."
    }

r = requests.post(
        OCTOPRINT_URL + "printer/command",
        json=json,
        headers=headers
)
  1. Custom Action commands plugin https://github.com/benlye/OctoPrint-ActionCommandsPlugin Setup:
action: octo_start |  type: system | command: /path/to/script.py start
action: octo_cancel |  type: system | command: /path/to/script.py cancel
  1. Marlin Configuration_adv.h
#define CUSTOM_USER_MENUS
#if ENABLED(CUSTOM_USER_MENUS)
  #define USER_SCRIPT_DONE "M117 User Script Done"
  #define USER_SCRIPT_AUDIBLE_FEEDBACK
  #define USER_SCRIPT_RETURN  // Return to status screen after a script

  #define USER_DESC_1 "Octoprint Cancel"
  #define USER_GCODE_1 "M118 //action:octo_cancel"

  #define USER_DESC_2 "Octoprint Start"
  #define USER_GCODE_2 "M118 //action:octo_start"
2 Likes