Pause/resume and Home printer Octoprint API

Hey guys,

I have been able to work out how to shutdown my printer using the function and HTTP nodes.

But no idea how to send this

POST /api/printer/printhead HTTP/1.1
Host: example.com
Content-Type: application/json
X-Api-Key: abcdef...

{
  "command": "home",
  "axes": ["x", "y"]
}

How do I pass that to the HTTP request?

Thanks :slight_smile:

EDIT;

I have a curl command here.

How would I inset the command part into the msg

'{"command":"G28 W"}'

prusa2_autohome: "curl -s http://x.x.x.x/api/printer/command -d '{"command":"G28 W"}' -H 'Content-Type: application/json' -H 'X-Api-Key: XXX'"

Here are two subflows I use for fetching data and controlling the printer. I haven't specifically done pause but hopefully you can work it out. This one is for controlling

[{"id":"4f52e314.3dc974","type":"subflow","name":"OctoPrint Post","info":"### Octoprint\n\nConfigure the node; IP/hostname, API key.\nSelect an option to query from OctoPrint\n\nConnected an inject node and a debug node\nInject anything\n","category":"","in":[{"x":44,"y":48,"wires":[{"id":"87d914a3.62cc7"}]}],"out":[{"x":647,"y":151,"wires":[{"id":"ff32c862.5e7ee","port":0},{"id":"c579c1f4.bda66","port":1}]},{"x":651,"y":206,"wires":[{"id":"3e677f54.d2d6a8","port":0},{"id":"c579c1f4.bda66","port":2}]}],"env":[{"name":"url","type":"str","value":"x201-1804.local:5000","ui":{"label":{"en-US":"http://"},"type":"input","opts":{"types":["str"]}}},{"name":"api","type":"str","value":"D8EB8EAB94164A29929CD6B8568FE859","ui":{"label":{"en-US":"API key"},"type":"input","opts":{"types":["str"]}}},{"name":"request","type":"str","value":"files","ui":{"label":{"en-US":"Type"},"type":"select","opts":{"opts":[{"l":{"en-US":"Printer Operations"},"v":"printer"},{"l":{"en-US":"Jobs"},"v":"job"},{"l":{"en-US":"Files"},"v":"files"},{"l":{"en-US":"Connection"},"v":"connection"}]}}}],"color":"#C7E9C0","icon":"font-awesome/fa-print"},{"id":"561a7887.6639c","type":"http request","z":"4f52e314.3dc974","name":"http POST","method":"POST","ret":"txt","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":341,"y":48,"wires":[["c579c1f4.bda66"]]},{"id":"87d914a3.62cc7","type":"function","z":"4f52e314.3dc974","name":"Build request","func":"msg.headers = {'X-Api-Key': env.get(\"api\")}\nlet request = msg.request || env.get(\"request\")\nmsg.url = `${env.get(\"url\")}/api/${request}`\nreturn msg\n","outputs":1,"noerr":0,"x":166,"y":48,"wires":[["561a7887.6639c"]]},{"id":"ff32c862.5e7ee","type":"json","z":"4f52e314.3dc974","name":"","property":"payload","action":"","pretty":false,"x":390,"y":120,"wires":[[]]},{"id":"233f22ca.e7400e","type":"comment","z":"4f52e314.3dc974","name":"OK","info":"","x":629,"y":97,"wires":[]},{"id":"72ca6601.e96f1","type":"comment","z":"4f52e314.3dc974","name":"Error","info":"","x":636,"y":263,"wires":[]},{"id":"3e677f54.d2d6a8","type":"catch","z":"4f52e314.3dc974","name":"","scope":null,"uncaught":false,"x":380,"y":220,"wires":[[]]},{"id":"c579c1f4.bda66","type":"switch","z":"4f52e314.3dc974","name":"","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"num"},{"t":"eq","v":"204","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":90,"y":160,"wires":[["ff32c862.5e7ee"],[],[]]},{"id":"7183d903.1ec4b8","type":"subflow:4f52e314.3dc974","z":"192e771b.93cec9","name":"","env":[{"name":"url","value":"your_ip:5000","type":"str"},{"name":"api","value":"put key here","type":"str"},{"name":"request","value":"connection","type":"str"}],"x":560,"y":260,"wires":[["102e244.10a7fdc"],["cbfd690.4ff3418"]]},{"id":"102e244.10a7fdc","type":"debug","z":"192e771b.93cec9","name":"op1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":200,"wires":[]},{"id":"cbfd690.4ff3418","type":"debug","z":"192e771b.93cec9","name":"op2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":320,"wires":[]},{"id":"e7904c21.ef3b88","type":"function","z":"192e771b.93cec9","name":"Raise 5 and Home","func":"msg.request = \"printer/printhead\"\nmsg.payload = {\n    command: \"jog\",\n    z: 5,\n    speed: 300\n}\nnode.send(msg)\nmsg2 = {\n    request: \"printer/printhead\",\n    payload: {\n        command: \"home\",\n        axes: [ \"x\", \"y\", \"z\" ]\n    }\n}\nnode.send(msg2)\nreturn","outputs":1,"noerr":0,"x":330,"y":180,"wires":[["7183d903.1ec4b8"]]},{"id":"a1b57e73.a3d248","type":"function","z":"192e771b.93cec9","name":"Heat Extruder","func":"msg.request = \"printer/tool\"\nmsg.payload = {\n    command: \"target\",\n    targets: {tool0: 180}\n}\nreturn msg","outputs":1,"noerr":0,"x":320,"y":220,"wires":[["7183d903.1ec4b8"]]},{"id":"9f093217.eb1448","type":"function","z":"192e771b.93cec9","name":"Cool down","func":"msg.request = \"printer/tool\"\nmsg.payload = {\n    command: \"target\",\n    targets: {tool0: 0}\n}\nnode.send(msg)\nmsg2 = {}\nmsg2.request = \"printer/bed\"\nmsg2.payload = {\n    command: \"target\",\n    target: 0\n}\nnode.send(msg2)\nreturn","outputs":1,"noerr":0,"x":310,"y":300,"wires":[["7183d903.1ec4b8"]]},{"id":"3e2f8571.59f3a2","type":"function","z":"192e771b.93cec9","name":"Squirt","func":"msg.request = \"printer/tool\"\nmsg.payload = {\n    command: \"extrude\",\n    amount: 5\n}\nreturn msg","outputs":1,"noerr":0,"x":290,"y":340,"wires":[["7183d903.1ec4b8"]]}]
1 Like

Oops, pressed send too early.
This one is for fetching

[{"id":"7f7083a4.f9da74","type":"subflow","name":"OctoPrint Get","info":"### Octoprint\n\nConfigure the node; IP/hostname, API key.\nSelect an option to query from OctoPrint\n\nConnected an inject node and a debug node\nInject anything\n","category":"","in":[{"x":44,"y":48,"wires":[{"id":"8870838d.4cce18"}]}],"out":[{"x":757,"y":79,"wires":[{"id":"7d2e6a84.e39484","port":0}]},{"x":761,"y":134,"wires":[{"id":"7d2e6a84.e39484","port":1},{"id":"45176bf5.a8223c","port":0}]}],"env":[{"name":"url","type":"str","value":"x201-1804.local:5000","ui":{"label":{"en-US":"http://"},"type":"input","opts":{"types":["str"]}}},{"name":"api","type":"str","value":"D8EB8EAB94164A29929CD6B8568FE859","ui":{"label":{"en-US":"API key"},"type":"input","opts":{"types":["str"]}}},{"name":"request","type":"str","value":"files","ui":{"label":{"en-US":"Type"},"type":"select","opts":{"opts":[{"l":{"en-US":"Printer Operations"},"v":"printer"},{"l":{"en-US":"Jobs"},"v":"job"},{"l":{"en-US":"Files"},"v":"files"},{"l":{"en-US":"Connection"},"v":"connection"}]}}}],"color":"#C7E9C0","icon":"font-awesome/fa-print"},{"id":"c87a6e04.901ed","type":"http request","z":"7f7083a4.f9da74","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":341,"y":48,"wires":[["bb4210f4.0275f8"]]},{"id":"8870838d.4cce18","type":"function","z":"7f7083a4.f9da74","name":"Build request","func":"msg.headers = {'X-Api-Key': env.get(\"api\")}\nlet request = msg.request || env.get(\"request\")\nmsg.url = `${env.get(\"url\")}/api/${request}`\nreturn msg\n","outputs":1,"noerr":0,"x":166,"y":48,"wires":[["c87a6e04.901ed"]]},{"id":"bb4210f4.0275f8","type":"json","z":"7f7083a4.f9da74","name":"","property":"payload","action":"","pretty":false,"x":500,"y":48,"wires":[["7d2e6a84.e39484"]]},{"id":"ed037175.b3e148","type":"comment","z":"7f7083a4.f9da74","name":"OK","info":"","x":739,"y":25,"wires":[]},{"id":"ae2d110a.60927","type":"comment","z":"7f7083a4.f9da74","name":"Error","info":"","x":746,"y":191,"wires":[]},{"id":"7d2e6a84.e39484","type":"switch","z":"7f7083a4.f9da74","name":"","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":620,"y":49,"wires":[[],[]]},{"id":"45176bf5.a8223c","type":"catch","z":"7f7083a4.f9da74","name":"","scope":null,"uncaught":false,"x":540,"y":134,"wires":[[]]},{"id":"c5671f24.35d51","type":"change","z":"ba146380.19dcc8","name":"Printer state","rules":[{"t":"set","p":"request","pt":"msg","to":"printer","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":150,"y":440,"wires":[["60264582.24861c"]]},{"id":"60264582.24861c","type":"subflow:7f7083a4.f9da74","z":"ba146380.19dcc8","name":"","env":[{"name":"url","value":"your_ip:5000","type":"str"},{"name":"api","value":"api key here","type":"str"},{"name":"request","value":"connection","type":"str"}],"x":326,"y":440,"wires":[["e18ca7bb.b9352","53f82250.8bcb54"],["b48027f8.66b42"]]}]

Hopefully those will get you going.

1 Like

Sorry mate,

Haven't been able to get back to this until today.

Thanks for that, it works and I think I have an handle on how the msgs work. So thanks so much for that :slight_smile:

Ill post the pause resume once I get that working if someone needs it

Thanks again for the start :slight_smile:

Hey all,

Here is the node for pause/resume if anyone is looking for it

[{"id":"e3522fd1bf3bcf1b","type":"function","z":"c9278714.1b4138","g":"2aee77b30c95560d","name":"Toggle pause/resume","func":"msg.request = \"job\"\nmsg.payload = {\n    command: \"pause\",\n    action: \"toggle\"\n}\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":2120,"wires":[["7183d903.1ec4b8"]]}]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.