# MQTT 3D Printer Management with Node-Red and OctoPrint

**URL:** <https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889>\
**Category:** General\
**Tags:** node-red-dashboard, mqtt\
**Created:** [29 December 2022 12:53 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889 "2022-12-29T12:53:20Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![toniii](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toniii/32/73429_2.png) [@toniii](https://discourse.nodered.org/u/toniii)\
**Post date:** [29 December 2022 12:53 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/1 "2022-12-29T12:53:20Z")

</div>

Hello, does anyone know how @nicedevil did the dashboard in this thread [(thread link here)](https://discourse.nodered.org/t/node-red-to-octoprint-integration/38264/3) using MQTT with 3D printer data, controls and uploading of STL from the dashboard to the 3D printer to start printing?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [29 December 2022 15:13 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/2 "2022-12-29T15:13:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![toniii](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toniii/32/73429_2.png) [@toniii](https://discourse.nodered.org/u/toniii)\
**Post date:** [29 December 2022 15:30 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/3 "2022-12-29T15:30:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 December 2022 15:55 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/4 "2022-12-29T15:55:20Z")

</div>

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](https://www.hivemq.com/mqtt-essentials/)

---

<div class="post-metadata">

**Author:** ![toniii](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toniii/32/73429_2.png) [@toniii](https://discourse.nodered.org/u/toniii)\
**Post date:** [29 December 2022 16:25 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/5 "2022-12-29T16:25:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [29 December 2022 16:37 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/6 "2022-12-29T16:37:51Z")

</div>

> 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 ?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 December 2022 16:55 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/7 "2022-12-29T16:55:36Z")

</div>

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.

```auto
[{"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"]]}]

```

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![toniii](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toniii/32/73429_2.png) [@toniii](https://discourse.nodered.org/u/toniii)\
**Post date:** [30 December 2022 03:09 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/8 "2022-12-30T03:09:31Z")

</div>

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](https://discourse.nodered.org/t/node-red-to-octoprint-integration/38264/3)

---

<div class="post-metadata">

**Author:** ![toniii](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toniii/32/73429_2.png) [@toniii](https://discourse.nodered.org/u/toniii)\
**Post date:** [30 December 2022 03:10 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/9 "2022-12-30T03:10:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 December 2022 07:38 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/10 "2022-12-30T07:38:31Z")

</div>

> [@toniii](#):
>
> 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?

---

<div class="post-metadata">

**Author:** ![toniii](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toniii/32/73429_2.png) [@toniii](https://discourse.nodered.org/u/toniii)\
**Post date:** [30 December 2022 08:07 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/11 "2022-12-30T08:07:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 December 2022 08:25 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/12 "2022-12-30T08:25:55Z")

</div>

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). 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.

---

<div class="post-metadata">

**Author:** ![toniii](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toniii/32/73429_2.png) [@toniii](https://discourse.nodered.org/u/toniii)\
**Post date:** [30 December 2022 10:58 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/13 "2022-12-30T10:58:55Z")

</div>

Thank you so much @Colin! Big help!

---

<div class="post-metadata">

**Author:** ![toniii](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toniii/32/73429_2.png) [@toniii](https://discourse.nodered.org/u/toniii)\
**Post date:** [6 January 2023 08:41 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/14 "2023-01-06T08:41:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 January 2023 09:19 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/15 "2023-01-06T09:19:35Z")

</div>

> [@toniii](#):
>
> This is HTTP interface and not MQTT right?

Yes, as I said earlier:

> [@Colin](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![toniii](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toniii/32/73429_2.png) [@toniii](https://discourse.nodered.org/u/toniii)\
**Post date:** [9 January 2023 10:51 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/16 "2023-01-09T10:51:48Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 March 2023 10:52 UTC](https://discourse.nodered.org/t/mqtt-3d-printer-management-with-node-red-and-octoprint/72889/17 "2023-03-10T10:52:29Z")

</div>

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