Why Connect a 3D Printer to an AI Agent?
Running a print farm or even a single printer 24/7 means constant babysitting – failed prints, thermal runaway, filament jams. Manually monitoring OctoPrint or Mainsail gets old fast. With ASI Biont, you can offload that to an AI agent that talks directly to your printers via MQTT or SSH.
ASI Biont connects to any device through Python code it writes on the fly. You just describe your setup in chat – printer firmware (Marlin or Klipper), broker IP, MQTT topics – and the AI generates the integration code. No dashboards, no plugins. Everything happens through conversation.
Connection Methods for 3D Printers
| Firmware | Recommended Method | Why |
|---|---|---|
| Marlin (via OctoPrint or ESP32) | MQTT (paho-mqtt) | OctoPrint plugin can publish temperature/status to MQTT; ESP32 can read serial from printer and publish. |
| Klipper (via Moonraker) | HTTP API (aiohttp) | Moonraker exposes REST endpoints for status, G-Code, and file management. |
| Direct serial (Arduino/RAMPS) | Hardware Bridge (bridge.py) | For bare Marlin boards without OctoPrint – bridge reads/writes COM port via WebSocket. |
| SSH to Raspberry Pi | paramiko | If you have an OctoPrint or Klipper host, AI can SSH in to run scripts, check logs, or restart services. |
Real-World Example: MQTT Bridge for Marlin via OctoPrint
Step 1 – Set Up OctoPrint MQTT Plugin
Install the OctoPrint-MQTT plugin and configure broker (e.g., Mosquitto on local Raspberry Pi). Topics used:
- printer/temperature – JSON with actual/extruder/bed temps
- printer/status – Printing, Paused, Operational
- printer/command – subscribe to send G-Code
Step 2 – Connect ASI Biont to MQTT Broker
In the chat with ASI Biont, type:
Connect my 3D printer running OctoPrint with MQTT plugin. Broker at 192.168.1.100:1883, no auth. Subscribe to printer/temperature and printer/status. I want to send G-Code via printer/command.
ASI Biont will generate and run this Python script in its sandbox (using execute_python):
import paho.mqtt.client as mqtt
import json
import time
BROKER = "192.168.1.100"
PORT = 1883
TOPIC_TEMP = "printer/temperature"
TOPIC_STATUS = "printer/status"
TOPIC_CMD = "printer/command"
def on_message(client, userdata, msg):
data = json.loads(msg.payload)
if msg.topic == TOPIC_TEMP:
print(f"Temp: extruder={data['extruder']}°C, bed={data['bed']}°C")
elif msg.topic == TOPIC_STATUS:
print(f"Status: {data['state']}")
client = mqtt.Client()
client.on_message = on_message
client.connect(BROKER, PORT, 60)
client.subscribe([(TOPIC_TEMP, 0), (TOPIC_STATUS, 0)])
client.loop_start()
# Example: send G-Code for emergency stop
client.publish(TOPIC_CMD, "M112")
time.sleep(2)
# Read current status
client.publish(TOPIC_CMD, "M105") # request temperature
client.loop_stop()
client.disconnect()
The AI doesn't run this script continuously – it runs it on demand when you ask questions like "What's the current temperature on printer 1?" or "Pause all prints if bed temp drops below 50°C."
Step 3 – Automate Monitoring via Telegram
Tell ASI Biont:
Monitor my printer. If extruder temp exceeds 260°C or bed temp drops below 50°C during a print, send a Telegram alert and pause the print.
The AI will write a script that subscribes to MQTT, checks thresholds, and uses the Telegram API (via requests) to send messages. Example snippet:
import paho.mqtt.client as mqtt
import requests
TELEGRAM_BOT_TOKEN = "your_bot_token"
TELEGRAM_CHAT_ID = "your_chat_id"
def check_and_alert(temperature_data):
if temperature_data['extruder'] > 260:
msg = f"ALERT: Extruder {temperature_data['extruder']}°C - pausing print"
requests.post(f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage",
json={"chat_id": TELEGRAM_CHAT_ID, "text": msg})
client.publish("printer/command", "M25") # Pause SD print
Klipper + Moonraker HTTP API Example
For Klipper users, Moonraker provides a clean REST API. Tell ASI Biont:
Connect to Klipper at 192.168.1.200:7125. Get current status and filament used.
The AI generates:
import aiohttp
import asyncio
async def get_klipper_status(ip, port):
url = f"http://{ip}:{port}/printer/objects/query"
params = {"objects": {"print_stats": None, "extruder": None, "heater_bed": None}}
async with aiohttp.ClientSession() as session:
async with session.get(url, params=params) as resp:
data = await resp.json()
print("Status:", data['result']['status']['print_stats']['state'])
print("Filament used:", data['result']['status']['print_stats']['filament_used'], "mm")
print("Extruder temp:", data['result']['status']['extruder']['temperature'])
asyncio.run(get_klipper_status("192.168.1.200", 7125))
You can then ask: "Home all axes, then set bed to 60°C" – AI will send:
async def send_gcode(ip, port, gcode):
async with aiohttp.ClientSession() as session:
await session.post(f"http://{ip}:{port}/printer/gcode/script",
json={"script": gcode})
await send_gcode("192.168.1.200", 7125, "G28")
await send_gcode("192.168.1.200", 7125, "M140 S60")
Full Print Farm Automation Scenario
Imagine you have 3 printers – 2 Marlin (via OctoPrint MQTT) and 1 Klipper. You tell ASI Biont:
Monitor all 3 printers. If any print finishes, start the next file from a queue. If any printer has a thermal runaway, shut it down and notify me via Telegram.
ASI Biont will write a single script that:
- Connects to MQTT (for Marlin printers) and Moonraker HTTP (for Klipper)
- Checks status every 30 seconds
- On Operational state, sends next G-Code file via M23 filename.gcode (Marlin) or Moonraker upload API
- On thermal runaway (detected via rapid temp drop or M112 response), publishes M112 and sends Telegram message
This runs in the sandbox (max 30 seconds per execution), so you set up a cron job (or ask AI to create a script that loops with delays) – but for continuous monitoring, ASI Biont can re-run the script every minute via a scheduled task you describe in chat.
Pitfalls to Avoid
- MQTT topic naming: OctoPrint-MQTT plugin uses
printer/prefix by default. If you change it, update your description to AI. - Authentication: If your MQTT broker requires login, include
usernameandpasswordin your chat description – AI will add them to the client. - G-Code confirmation: Some Marlin builds require
M110(line number reset) before accepting commands. Mention it in chat if you get "Line number mismatch" errors. - Sandbox timeout: Scripts in execute_python run for max 30 seconds. For long-running monitoring, ask AI to write a script that polls once and returns results, then set up a recurring task via chat (e.g., "run this every 5 minutes").
Why This Changes Everything
You don't need to write a single line of code. You don't need to wait for a plugin update. Just describe your printer setup and what you want to automate – ASI Biont writes the Python integration on the fly using paho-mqtt, aiohttp, or paramiko. It can orchestrate an entire print farm from one chat conversation.
Ready to let AI run your print farm? Try it now at asibiont.com – connect your 3D printer and start controlling it via Telegram today.
Comments