# How to Integrate with Bambu Labs Printers Using Text-to-CAD: A Complete LAN Workflow Guide

> Integrate with Bambu Labs printers using text-to-CAD. This guide details the complete LAN workflow for seamless 3D printing control via JSON, TLS, FTPS, and MQTT.

- Repository: [earthtojake/text-to-cad](https://github.com/earthtojake/text-to-cad)
- Tags: how-to-guide
- Published: 2026-07-23

---

**The text-to-cad repository provides a self-contained Python helper that implements the full Bambu Labs LAN workflow through JSON configuration management, TLS serial discovery, FTPS file upload, and MQTT command publishing.**

The `earthtojake/text-to-cad` project ships with a comprehensive integration for Bambu Labs 3D printers, enabling direct G-code transfer and print control over your local network. Located in [`skills/bambu-labs/scripts/bambu_lan_print.py`](https://github.com/earthtojake/text-to-cad/blob/main/skills/bambu-labs/scripts/bambu_lan_print.py), this utility eliminates the need for cloud services by leveraging the printer's native LAN mode protocols. Whether you are automating batch prints or building a custom pipeline, this guide covers the complete technical implementation for integrating with Bambu Labs printers.

## Understanding the Bambu Labs LAN Architecture

The integration operates through four core mechanisms that work sequentially to move files from your workstation to the printer bed. First, **printer configuration** persists connection details and cached serial numbers in a local JSON file. Second, **TLS certificate parsing** extracts the device serial number directly from the printer's secure socket layer. Third, **implicit FTPS** handles file transfers over TLS-encrypted FTP connections. Finally, **MQTT messaging** dispatches print commands and monitors job status through the printer's internal message broker.

This architecture supports both plain `.gcode` files and advanced `.gcode.3mf` packages created with the optional Bambox CLI tool.

## Step 1: Configure Your Bambu Labs Printer

### Managing Printer Configuration with JSON

Before sending files, you must register your printer in the [`bambu-printers.json`](https://github.com/earthtojake/text-to-cad/blob/main/bambu-printers.json) configuration file. The `config_set_main` function in [`bambu_lan_print.py`](https://github.com/earthtojake/text-to-cad/blob/main/bambu_lan_print.py) handles creation and updates through the `load_config` and `save_config` utilities located at lines 58-74.

Run the following command to store your printer's network credentials:

```bash
python -m skills.bambu-labs.scripts.bambu_lan_print \
  config set \
  --printer my-printer \
  --host 192.168.1.42 \
  --access-code 12345678 \
  --model P1S \
  --fetch-serial

```

The `--fetch-serial` flag triggers `discover_printer_serial` (lines 68-88), which opens a TLS socket to the printer, extracts the certificate, and parses the Common Name field to cache the serial number for subsequent operations.

## Step 2: Discover the Printer Serial Number via TLS

### Certificate-Based Serial Extraction

Bambu Labs printers embed their serial numbers within their TLS certificates. The `discover_printer_serial` function establishes a secure connection to the printer's IP address and parses the certificate's CN field to retrieve this identifier. This value is then stored in your local configuration via `apply_printer_config`, ensuring that MQTT commands target the correct device.

If the serial is already cached in [`bambu-printers.json`](https://github.com/earthtojake/text-to-cad/blob/main/bambu-printers.json), the `ensure_printer_serial` helper retrieves it without requiring a new TLS handshake, improving script execution speed for repeated operations.

## Step 3: Upload G-code Files via FTPS

### Implicit FTPS Upload Logic

The `upload_ftps` function (lines 338-360) implements an implicit FTPS client using Python's `ImplicitFTP_TLS` class. This method creates a TLS context, connects to the printer's FTP server using your access code as the password, and uploads files to the `/cache/` directory with timeout tolerance and automatic remote directory creation.

For a standard G-code upload, the system calls `build_plain_send_plan`, which constructs a remote path like `cache/model.gcode` and prepares the FTPS transfer parameters. The upload occurs before any MQTT commands are issued, ensuring the file resides on the printer's SD card before printing begins.

## Step 4: Control Prints and Monitor Status via MQTT

### Publishing Commands and Collecting Reports

After successful upload, the `publish_mqtt` function (lines 411-475) constructs CONNECT packets and publishes JSON payloads to the `device/<serial>/request` topic. Supported commands include `gcode_file`, `project_file`, `start`, and `stop`, formatted with sequence IDs for tracking.

To monitor print progress, the script can subscribe to `device/<serial>/report` and wait for PUBACK confirmations or status messages. The `status` subcommand leverages this functionality through `ensure_printer_serial` to query real-time printer conditions:

```bash
python -m skills.bambu-labs.scripts.bambu_lan_print \
  status \
  --printer my-printer \
  --wait-seconds 5

```

This collects up to the specified number of report messages and outputs a JSON summary of current temperatures, print progress, and hardware state.

## Optional: Package Files with Bambox for Advanced Workflows

### Creating Bambu Box 3MF Packages

For printers requiring structured project files, the integration supports the Bambox CLI through `build_bambox_pack_command` (lines 342-366). This wraps plain G-code into a `.gcode.3mf` container with machine profiles and filament settings.

Execute a Bambox-packaged print with:

```bash
python -m skills.bambu-labs.scripts.bambu_lan_print \
  send \
  --printer my-printer \
  --gcode /path/to/model.gcode \
  --handoff bambox-project \
  --bambox-profile p1s-0.4 \
  --filament PLA \
  --action upload-start \
  --confirm-start-print \
  --execute

```

The `run_checked_command` utility executes the Bambox CLI, then `inspect_sliced_3mf` extracts plate information for the MQTT `project_file` payload, enabling multi-plate project management directly from the command line.

## Complete Workflow Examples

### Upload and Start a Print Immediately

The `build_send_plan` function (lines 270-276) orchestrates the entire workflow by stitching together configuration, remote paths, and MQTT payloads. For a complete upload-and-print sequence:

```bash
python -m skills.bambu-labs.scripts.bambu_lan_print \
  send \
  --printer my-printer \
  --gcode /path/to/model.gcode \
  --action upload-start \
  --confirm-start-print \
  --execute

```

This resolves printer info via `apply_printer_config`, uploads via `upload_ftps`, and publishes the start command via `publish_mqtt` with the `gcode_file` parameter.

### Query Real-Time Printer Status

To verify connectivity and current job state without initiating a print:

```bash
python -m skills.bambu-labs.scripts.bambu_lan_print \
  status \
  --printer my-printer \
  --wait-seconds 5

```

The implementation at lines 822-844 handles MQTT subscription to the report topic and aggregates messages into a readable format.

## Summary

- **Configuration Management**: Store printer details in [`bambu-printers.json`](https://github.com/earthtojake/text-to-cad/blob/main/bambu-printers.json) using `config_set_main`, with automatic serial discovery via TLS certificate parsing.
- **File Transfer**: Upload G-code securely using `upload_ftps` with implicit TLS encryption and timeout handling.
- **Command Control**: Dispatch print jobs through `publish_mqtt` to the `device/<serial>/request` topic, with optional status monitoring on the report topic.
- **Advanced Packaging**: Convert plain G-code to structured 3MF projects using the Bambox CLI integration via `build_bambox_pack_command`.
- **Modular Architecture**: Each workflow step is exposed through the [`bambu_lan_print.py`](https://github.com/earthtojake/text-to-cad/blob/main/bambu_lan_print.py) CLI, allowing both interactive use and programmatic import as a Python module.

## Frequently Asked Questions

### What network protocols does the Bambu Labs integration use?

The implementation uses three primary protocols: TLS for secure serial number discovery and certificate validation, implicit FTPS (FTP over TLS) for file transfers to the printer's cache directory, and MQTT for command dispatch and status reporting. All communication occurs over your local area network without requiring cloud connectivity.

### How does the script handle the printer serial number?

The `discover_printer_serial` function extracts the serial from the printer's TLS certificate Common Name field during initial configuration. This value is cached in [`bambu-printers.json`](https://github.com/earthtojake/text-to-cad/blob/main/bambu-printers.json) via `save_config` and retrieved on subsequent runs through `ensure_printer_serial`, eliminating the need for repeated TLS handshakes during normal operation.

### Can I use this integration with any Bambu Labs printer model?

Yes, the [`bambu_lan_print.py`](https://github.com/earthtojake/text-to-cad/blob/main/bambu_lan_print.py) script supports all Bambu Labs printers that implement the standard LAN mode protocol, including the X1 Carbon, P1P, and P1S models. The `--model` parameter in the configuration command allows you to specify your exact hardware for reference purposes, while the underlying protocols remain consistent across the product line.

### Is Bambox packaging required for all print jobs?

No, Bambox packaging is optional. You can upload plain `.gcode` files directly using the `upload-start` action. Bambox packaging (triggered with `--handoff bambox-project`) is only necessary when you need to create structured `.gcode.3mf` project files that include specific plate arrangements, filament profiles, or nozzle diameter specifications for complex multi-part jobs.