MQTT 3D Printer Management with Node-Red and OctoPrint

Hello, does anyone know how @nicedevil did the dashboard in this thread (thread link here) using MQTT with 3D printer data, controls and uploading of STL from the dashboard to the 3D printer to start printing?

Why not just use the octoprint interface, this sounds like reinventing the wheel ?

I'm trying to use MQTT for IIoT applications. Instead of the OctoPrint interface which is limited to 3D printer itself.

So what exactly do you need help with?

If it is general information about MQTT then see this tutorial MQTT Essentials - All Core Concepts explained

I'm trying to figure out how to integrate OctoPrint with Node-Red.

I'm trying to use MQTT for IIoT applications.

I'm trying to figure out how to integrate OctoPrint with Node-Red.

Instead of the OctoPrint interface which is limited to 3D printer itself.

Which is it ?

Do you want a dashboard using data received via MQTT ?
Do you want a dashboard controlling your printer ?

For Octoprint with node-red I started off trying to use the MQTT plugin, but there were some problems, so I opted for using the http interface. Here are a couple of subflows I developed which may be useful. I should put them on the flows site.

[{"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":"localhost: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"}]}}}],"meta":{},"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":"7bd596f.f231b68","type":"inject","z":"ba146380.19dcc8","name":"","repeat":"5","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":115,"y":102,"wires":[["ba765a80.7a6eb","c5671f24.35d51"]]},{"id":"ba765a80.7a6eb","type":"change","z":"ba146380.19dcc8","name":"Connection","rules":[{"t":"set","p":"request","pt":"msg","to":"connection","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":287,"y":102,"wires":[["342a8c78.5bf5ec"]]},{"id":"342a8c78.5bf5ec","type":"subflow:7f7083a4.f9da74","z":"ba146380.19dcc8","name":"","env":[{"name":"url","value":"localhost:5000","type":"str"},{"name":"api","value":"1F891C5F4667474D8F893F1FBAA314A6","type":"str"},{"name":"request","value":"connection","type":"str"}],"x":463,"y":102,"wires":[["2ce7b756.e0d95","14f4766.24e118a"],["d9f25a41.321358"]]},{"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":"api","value":"1F891C5F4667474D8F893F1FBAA314A6","type":"str"},{"name":"request","value":"connection","type":"str"}],"x":326,"y":440,"wires":[["e18ca7bb.b9352","53f82250.8bcb54"],["b48027f8.66b42"]]}]
[{"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":"localhost: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"}]}}}],"meta":{},"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":"pi003.local:5000","type":"str"},{"name":"api","value":"1F891C5F4667474D8F893F1FBAA314A6","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"]]}]

Both data received and controlling the printer @bakman2 just like the one here https://discourse.nodered.org/t/node-red-to-octoprint-integration/38264/3?u=toniii

Thank you so much @Colin, I'll check up on this! Did you use Node-Red for this?

I don't understand what you mean. How could I develop node red subflows other than using node red?

1 Like

Just wanted to verify! Thank you! How did you do the connection of nodes? Sorry, newbie here!

I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Once you have watched all those then come back and ask again if you need further help.

2 Likes

Thank you so much @Colin! Big help!

Hello @Colin! This is HTTP interface and not MQTT right?

Yes, as I said earlier:

Thank you!

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