How to integrate a 3d printer in my Home Automation.


My daughter and I have bought a good 3D printer, a Creality Ender 3 since a couple of weeks. The setup and first print tests have taken the first week, producing a good level of satisfaction but, having passed the “how to make it work“, I went to the stage” find out what we can do more (than normal)“.

In this first article I want to explain how I thought of integrating the printer into a larger system (we are talking about IoT), so that you can remotely control, during printing process, the parameters that determine the correct operation.

What we want to do?

It’s amazing: a 3D printer of the most common (among the economic ones) is not born to be a connected object. In today’s world it is a “soliton”.

Probably to keep the costs down (and they are are not so low: a cheap printer, produced in China and assembled by the customer, costs around 200–250 euros) and make them affordable to the most.

The printer has an LCD panel, with a knob, which allows you to read the conditions of its components (print bed, nozzle, fan, etc) and to change the parameters to best fit the printing material used (for now, we use only PLA). It has a micro SD card reader, to allow you to insert a card with the “gcode” file that defines “what to print and how”. It also has a USB port to connect a PC (better an Apple Mac) and directly control the printer through a “slicing” program. We use Ultimaker Cura.

But, there is no Ethernet port nor WiFi!

What I want to achieve is an integration that allows, via WiFi, to transmit in real time the data relating to the conditions of the printer and the progress of the printing process:

  • heated print bed temperature
  • nozzle temperature
  • percentage of progress of the print job

along with other events (print started, finished, etc …). It also allows you to send commands to the printer itself.

The above parameters are important: the two temperatures must be maintained at fixed values, specific to the material (eg: 200° C for the nozzle and 60° C for the bed) to guarantee a good quality of the printed object.

The USB port is the key to the solution.

Architecture of the solution

The idea that I have had is to explore on the net if there was a solution, based on a Raspberry PI, allowing to interface the printer and to send the data and events above defined through a messaging protocol such as MQTT.

I quickly discovered that such a solution exists and is: Octoprint.

Octoprint is a system, built in Python and Javascript, that allows USB integration to a large set of supported printers, including my Creality Ender3. Octoprint provides a Web application that allows you to monitor the parameters of the printer, the printing process and to change the parameters via a browser. It allows the browser to upload the “gcode” file and to launch the print process. In addition, it allows you to integrate a WebCam and observe, remotely, in real time the print (cool).

There is already an Octoprint distribution for Raspberry: Octopi. So the process of installation and configuration of Octoprint on a Raspberry PI 3 is quite simple and straightforward (for details I suggest you to visit the site at the link above).

But the most important thing is that there is a plug-in for Octoprint that enables you to send messages and events to an MQTT broker: bingo!

Installing the plug-in is very simple. The configuration is done through the Octoprint Web UI and in a few minutes messages, in JSON format, are sent to the MQTT broker with the requested information.

High level architecture

As IoT Gateway I used an Intel mini-computer with Ubuntu 18, on which I installed Eclipse Kura (see my articles about it on The MQTT broker is integrated into Kura.

On the gateway are also installed:

  • MySQL
  • Grafana
  • NodeRED (for a local dashboard)
Architecture: relationship between software components

OSGi plug-ins developed for Eclipse Kura (including the plug-in that saves messages in MySQL DB ) and NodeRED subscribe to MQTT topics and receive, in real time, MQTT messages from Octoprint.

Data from the 3D printer

The MQTT plug-in allows customizations. You need only to write Python code based on Eclipse Paho.

In the prototype version now in development, I decided to keep the default JSON format of MQTT messages.

Messages produced by Octoprint and sent via MQTT provide:

  • the temperatures of the printing bed and the nozzle; It is possible to define a threshold and messages are sent only if the variation exceeds the threshold:
{"_timestamp": 1517190629, "actual": 42.1, "target": 65.0}

Messages are sent to two different topics, but they conform to the pattern: octoprint/temperature/+

  • The messages relating to events are of the type:
{"_timestamp": 1517190629, "_event": "PrintStarted", "origin": "local", "file":"/home/pi/.octoprint/uploads/case_bp_3.6.v1.0.gco", "filename": "case_bp_3.6.v1.0.gco"}
  • The messages relating to printing progress have the following format:
{"_timestamp": 1517190629, "progress": 23,   "location": "local", "path":   "test.gco"}

A first prototype.

I have tested the integration made and it works. The development of a first version of the dashboard using NodeRED is quite simple and allowed me to graph both the trend of the temperatures (I must say very constant after the initial warm up) and the printing progress, almost linear over time.

To integrate with Eclipse Kura I just had to add new message formats to represent messages from Octoprint.

3D printer with the RPI connected through USB
Data from the 3D printer (printing process has started few minutes ago)

Next step

The next steps:

  • transform the NodeRED dashboard into a complete dashboard for the management and control of the printing process, remotely;
  • complete the integration with the Assett Monitoring application in Oracle IoT Cloud Service;

All in the next article.