Introduction: How to Control a 3D Printer With a Telegram Bot

This instructable shows how to use a raspberry pi to remotely control a 3D printer using OctoPrint ad a telegram bot.


Disclaimer

This tutorial was developed as part of the Internet of Tricks project, co-financed by the Erasmus + program of the European Union. Project n°: 2021-1-SE02-KA220-YOU-000028971


The content of this publication does not reflect the official opinion of the European Union. Responsibility for the information and views expressed therein lies entirely with

The authors.


For more details contact info@horizonlab.eu

Supplies

  • A 3D printer
  • A Raspberry Pi 3B, 3B+, 4B or Zero 2
  • Internet connection

Step 1: Installing OctoPrint

The first step is the installation of OctoPrint on the RaspberryPI and connecting it to the 3D printer.

The easiest way is to install OctoPI, which is a Raspbian based Linux distribution that includes everything is needed to run OctoPrint properly. See this link for a video tutorial.



Refer also to the official website that has an amazing guide on how to install OctoPI through the RaspberryPI Imager.

Step 2:

Step 3: Configure OctoPrint

Once installed OctoPrint and the raspberry-pi boots up, it is necessary to proceed with the first setup in order to configure it properly according to the 3D printer you own.

Let's start by taking a detailed look into steps that should be taken in order to login and configure OctoPi.

Note that the Raspberry Pi and the device you are using to perform the login must be under the same network: it is recommend log into the interface of your router and check if both devices are in the list of connected devices. By default, the hostname of the Raspberry Pi should be octopi or raspberrypi.

  1. Type the device host name (usually octopi or raspberrypi) into the browser and navigate. It should appear the Setup Wizard that will guide you through the step necessary to complete the setup;
  2. Configure the Access Control. This is a mandatory step that allows you to setup a username and a password for the administrator account. The administrator has full access to both printer and OctoPrint's settings, therefore keep this information safe and protected.
  3. Set up your printer profile. This step allows you to specify general infos like printer name and some specific settings like print bed, build volume, axes speed/feedrate, extruders number and nozzle diameter.
  4. Finish. Congratulations! Your OctoPrint installation has been completed and now you are ready to go! Read all recommended advises shown in the last page in order to ensure your printer's safety.

At the end of the configuration the home page should appear.

Connect your printer by opening up the Connection panel on the left side. Set "Serial Port" and "Baudrate" options to “AUTO” and the "Printer Profle" to the profile name saved on step 4, then hit “Connect”. If this doesn’t work, try manually setting the serial port and baud rate until the connection is established. Don't forget to check the "Save connection settings" and "Auto connect on server startup", this allows you to not insert everytime this settings on every reboot.

Step 4: Getting OctoPrint Application Key

This step is mandatory for setting up Telegram Bot. It needs an Application Key in order to send commands to OctoPrint.

In order to generate and register an Application Key in OctoPrint you should click on the username on the right side of the Home page and then click on "User Settings". Insert the application name in the Application Identifier field and then click on "Generate".

Please take note of this key as it will be used in the following steps. You can always find it in the User Settings under the "Application Keys" tab. See this link for a video tutorial

Step 5: Create the Telegram Bot

In order to create a telegram bot you need to use BotFather.

The first step is to start a conversation with BotFather through telegram, sending the "/newbot" command.

Then you need to choose the name and username to give to the bot.

When finished, take note of the HTTP API access token. As the OctoPrint Application key, it will be used to set up the Bot code.

Step 6: Set Up the Bot Code

Once you have created the bot using BotFather you should give to it the proper intelligence in order to let it control the printer throw OctoPrint. To do so, you should execute the executable program that allows the bot to interact with OctoPrint.

Let's proceed with the installation process:

  1. Log in into the RaspberryPi
  2. Download and execute the script "install.sh". You can find it here

This script will install and satisfy all the necessery requirements for bot execution. More in detail, it asks for the Telegram Bot and OctoPrint API keys generated in the previous steps, it clones the code from the following repository, it starts the bot and set the auto start of the bot after every reboot of the RaspberryPi. See this link for a video tutorial

Step 7: Test the Bot

That's all falks! Here you can admire the final demonstration!