printer

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const BambuFTPSPort = 990

BambuFTPSPort is the default FTPS port for Bambu printers.

View Source
const BambuMQTTPort = 8883

BambuMQTTPort is the default MQTT port for Bambu printers.

Variables

This section is empty.

Functions

This section is empty.

Types

type BambuAMS

type BambuAMS struct {
	AMSExistBits  string      `json:"ams_exist_bits"`
	TrayExistBits string      `json:"tray_exist_bits"`
	TrayNow       string      `json:"tray_now"`
	TrayPre       string      `json:"tray_pre"`
	TrayTar       string      `json:"tray_tar"`
	Version       int         `json:"version"`
	Units         []BambuUnit `json:"ams,omitempty"`
}

BambuAMS represents AMS (Automatic Material System) status.

type BambuAMSCmd

type BambuAMSCmd struct {
	UseAMS         bool   `json:"use_ams"`
	PrintSpeed     string `json:"print_speed,omitempty"`
	LayerInspect   bool   `json:"layer_inspect,omitempty"`
	LabelVersion   string `json:"label_version,omitempty"`
	AMSMappingInfo []int  `json:"ams_mapping,omitempty"`
}

BambuAMSCmd represents AMS settings in a print command.

type BambuClient

type BambuClient struct {
	// contains filtered or unexported fields
}

BambuClient implements Client for Bambu Lab printers via LAN or Cloud MQTT. Bambu printers use MQTT over TLS on port 8883 for status and control. File uploads are done via FTPS on port 990 (LAN mode only).

func NewBambuClient

func NewBambuClient(printerID uuid.UUID, host string, accessCode string, serialNumber string) *BambuClient

NewBambuClient creates a new Bambu LAN client. The host should be the IP address or hostname of the printer. If host is a full URI (http://IP:PORT), the hostname is extracted. The accessCode is the LAN access code from the printer's settings. The serialNumber is needed for MQTT topic subscription.

func NewBambuCloudClient

func NewBambuCloudClient(printerID uuid.UUID, serial, mqttUsername, authToken string) *BambuClient

NewBambuCloudClient creates a Bambu client that connects via the cloud MQTT broker. mqttUsername is "u_{uid}" from the Bambu account preferences. authToken is the access token from Bambu Cloud login (used as MQTT password).

func (*BambuClient) CancelJob

func (c *BambuClient) CancelJob() error

CancelJob cancels the current print via MQTT command.

func (*BambuClient) Connect

func (c *BambuClient) Connect() error

Connect establishes MQTT connection to Bambu printer. Connection pattern follows the bambulabs_api community SDK.

func (*BambuClient) Disconnect

func (c *BambuClient) Disconnect() error

Disconnect closes the MQTT connection.

func (*BambuClient) GetAMSStatus

func (c *BambuClient) GetAMSStatus() (*BambuAMS, error)

GetAMSStatus returns the current AMS filament information.

func (*BambuClient) GetLiveView

func (c *BambuClient) GetLiveView() (io.ReadCloser, error)

GetLiveView returns a reader for the printer's live camera feed. Bambu cameras stream on port 6000 (RTSP) or via snapshot URL.

func (*BambuClient) GetStatus

func (c *BambuClient) GetStatus() (*model.PrinterState, error)

GetStatus retrieves current printer status.

func (*BambuClient) PauseJob

func (c *BambuClient) PauseJob() error

PauseJob pauses the current print via MQTT command.

func (*BambuClient) ResumeJob

func (c *BambuClient) ResumeJob() error

ResumeJob resumes a paused print via MQTT command.

func (*BambuClient) SetLEDMode

func (c *BambuClient) SetLEDMode(mode string) error

SetLEDMode sets the LED light mode on the printer.

func (*BambuClient) SetPrintSpeed

func (c *BambuClient) SetPrintSpeed(level int) error

SetPrintSpeed sets the print speed profile. Levels: 1=silent, 2=standard, 3=sport, 4=ludicrous

func (*BambuClient) SetSerialNumber

func (c *BambuClient) SetSerialNumber(serial string)

SetSerialNumber sets the printer's serial number for MQTT topics.

func (*BambuClient) SetStatusCallback

func (c *BambuClient) SetStatusCallback(cb func(*model.PrinterState))

SetStatusCallback sets the callback for status updates.

func (*BambuClient) StartJob

func (c *BambuClient) StartJob(filename string, filepath string) error

StartJob sends a print job to the Bambu printer. The file is uploaded via FTPS, then a print command is sent via MQTT.

type BambuCommand

type BambuCommand struct {
	Print   *BambuPrintCmd   `json:"print,omitempty"`
	System  *BambuSystemCmd  `json:"system,omitempty"`
	Pushing *BambuPushingCmd `json:"pushing,omitempty"`
}

BambuCommand represents a command to send to the printer.

type BambuHMS

type BambuHMS struct {
	Attr     int `json:"attr"`
	Code     int `json:"code"`
	Module   int `json:"module"`
	Severity int `json:"severity"`
}

BambuHMS represents a Health Management System error.

type BambuInfo

type BambuInfo struct {
	Sequence string `json:"sequence_id"`
	Command  string `json:"command"`
	Module   []struct {
		Name    string `json:"name"`
		Project string `json:"project_name"`
		SWVer   string `json:"sw_ver"`
		HWVer   string `json:"hw_ver"`
		SerNo   string `json:"sn"`
	} `json:"module,omitempty"`
}

BambuInfo contains printer information.

type BambuLight

type BambuLight struct {
	Node string `json:"node"`
	Mode string `json:"mode"`
}

BambuLight represents a light status report.

type BambuMessage

type BambuMessage struct {
	Print   *BambuPrintStatus `json:"print,omitempty"`
	Info    *BambuInfo        `json:"info,omitempty"`
	System  *BambuSystem      `json:"system,omitempty"`
	Pushing *BambuPushing     `json:"pushing,omitempty"`
}

BambuMessage represents the top-level structure of Bambu MQTT messages.

type BambuOnline

type BambuOnline struct {
	Ahb     bool `json:"ahb"`
	Rfid    bool `json:"rfid"`
	Version int  `json:"version"`
}

BambuOnline represents online status information.

type BambuPrintCmd

type BambuPrintCmd struct {
	Sequence    string       `json:"sequence_id"`
	Command     string       `json:"command"`
	Param       string       `json:"param,omitempty"`
	ProjectID   string       `json:"project_id,omitempty"`
	ProfileID   string       `json:"profile_id,omitempty"`
	TaskID      string       `json:"task_id,omitempty"`
	Subtask     string       `json:"subtask_id,omitempty"`
	SubtaskName string       `json:"subtask_name,omitempty"`
	URL         string       `json:"url,omitempty"`
	Filename    string       `json:"filename,omitempty"`
	Timelapse   bool         `json:"timelapse,omitempty"`
	BedLeveling bool         `json:"bed_leveling,omitempty"`
	FlowCali    bool         `json:"flow_cali,omitempty"`
	Vibration   bool         `json:"vibration_cali,omitempty"`
	AMS         *BambuAMSCmd `json:"ams,omitempty"`
}

BambuPrintCmd represents a print control command.

type BambuPrintStatus

type BambuPrintStatus struct {
	// Print state
	GcodeState  string `json:"gcode_state"`
	StgCur      int    `json:"stg_cur"`
	PrintError  int    `json:"print_error"`
	PrintType   string `json:"print_type"`
	SubtaskName string `json:"subtask_name"`
	GcodeFile   string `json:"gcode_file"`
	SubtaskID   string `json:"subtask_id"`
	TaskID      string `json:"task_id"`

	// Progress
	MCPercent       int `json:"mc_percent"`
	MCRemainingTime int `json:"mc_remaining_time"`
	LayerNum        int `json:"layer_num"`
	TotalLayerNum   int `json:"total_layer_num"`

	// Temperatures
	BedTemper          float64 `json:"bed_temper"`
	BedTargetTemper    float64 `json:"bed_target_temper"`
	NozzleTemper       float64 `json:"nozzle_temper"`
	NozzleTargetTemper float64 `json:"nozzle_target_temper"`
	ChamberTemper      float64 `json:"chamber_temper"`
	NozzleDiameter     string  `json:"nozzle_diameter"`
	NozzleType         string  `json:"nozzle_type"`

	// Fan speeds (0-15 scale typically)
	CoolingFanSpeed   int `json:"cooling_fan_speed"`
	BigFan1Speed      int `json:"big_fan1_speed"`
	BigFan2Speed      int `json:"big_fan2_speed"`
	HeatbreakFanSpeed int `json:"heatbreak_fan_speed"`

	// Speeds and flow
	SpeedMag       int `json:"spd_mag"`
	SpeedLevel     int `json:"spd_lvl"`
	PrintRealSpeed int `json:"print_real_speed"`
	FeedRateMag    int `json:"feed_rate_mag"`

	// AMS (Automatic Material System)
	AMSStatus int          `json:"ams_status"`
	AMS       *BambuAMS    `json:"ams,omitempty"`
	VTTray    *BambuVTTray `json:"vt_tray,omitempty"`

	// Lights and misc
	LightsReport []BambuLight `json:"lights_report,omitempty"`
	WiFiSignal   string       `json:"wifi_signal"`
	Online       *BambuOnline `json:"online,omitempty"`

	// HMS (Health Management System) errors
	HMS []BambuHMS `json:"hms,omitempty"`

	// Lifecycle
	LifecycleRelayID  string `json:"lifecycle"`
	PrintStartTime    string `json:"gcode_start_time"`
	PrintFinishAction string `json:"print_finish_action"`
	HomeFlag          int    `json:"home_flag"`
	HWSwitch          int    `json:"hw_switch_state"`
}

BambuPrintStatus contains print job status information.

type BambuPushing

type BambuPushing struct {
	Sequence   string `json:"sequence_id"`
	Command    string `json:"command"`
	PushTarget int    `json:"push_target,omitempty"`
	Version    int    `json:"version,omitempty"`
}

BambuPushing contains push notification info.

type BambuPushingCmd

type BambuPushingCmd struct {
	Sequence   string `json:"sequence_id"`
	Command    string `json:"command"`
	Version    int    `json:"version,omitempty"`
	PushTarget int    `json:"push_target,omitempty"`
}

BambuPushingCmd represents a push command.

type BambuSystem

type BambuSystem struct {
	Sequence  string `json:"sequence_id"`
	Command   string `json:"command"`
	Result    string `json:"result"`
	Reason    string `json:"reason,omitempty"`
	LedMode   string `json:"led_mode,omitempty"`
	LedOnTime string `json:"led_on_time,omitempty"`
}

BambuSystem contains system information.

type BambuSystemCmd

type BambuSystemCmd struct {
	Sequence  string `json:"sequence_id"`
	Command   string `json:"command"`
	LedMode   string `json:"led_mode,omitempty"`
	LedOnTime string `json:"led_on_time,omitempty"`
}

BambuSystemCmd represents a system command.

type BambuTray

type BambuTray struct {
	ID            string   `json:"id"`
	TrayIDName    string   `json:"tray_id_name"`
	TrayType      string   `json:"tray_type"`
	TraySubBrands string   `json:"tray_sub_brands"`
	TrayColor     string   `json:"tray_color"`
	TrayWeight    string   `json:"tray_weight"`
	TrayDiameter  string   `json:"tray_diameter"`
	TrayTemp      string   `json:"tray_temp"`
	TrayTime      string   `json:"tray_time"`
	BedTempType   string   `json:"bed_temp_type"`
	BedTemp       string   `json:"bed_temp"`
	NozzleTempMax string   `json:"nozzle_temp_max"`
	NozzleTempMin string   `json:"nozzle_temp_min"`
	Remain        int      `json:"remain"`
	TagUID        string   `json:"tag_uid"`
	TrayUUID      string   `json:"tray_uuid"`
	TrayInfoIdx   string   `json:"tray_info_idx"`
	Cols          []string `json:"cols,omitempty"`
}

BambuTray represents a tray/slot in an AMS unit.

type BambuUnit

type BambuUnit struct {
	ID       string      `json:"id"`
	Humidity string      `json:"humidity"`
	Temp     string      `json:"temp"`
	Trays    []BambuTray `json:"tray"`
}

BambuUnit represents a single AMS unit.

type BambuVTTray

type BambuVTTray struct {
	ID            string `json:"id"`
	TrayIDName    string `json:"tray_id_name"`
	TrayType      string `json:"tray_type"`
	TraySubBrands string `json:"tray_sub_brands"`
	TrayColor     string `json:"tray_color"`
	TrayWeight    string `json:"tray_weight"`
	TrayDiameter  string `json:"tray_diameter"`
	TrayTemp      string `json:"tray_temp"`
	TrayTime      string `json:"tray_time"`
	BedTempType   string `json:"bed_temp_type"`
	BedTemp       string `json:"bed_temp"`
	NozzleTempMax string `json:"nozzle_temp_max"`
	NozzleTempMin string `json:"nozzle_temp_min"`
	Remain        int    `json:"remain"`
}

BambuVTTray represents the external spool holder (virtual tray).

type Client

type Client interface {
	// Connect establishes connection to the printer.
	Connect() error
	// Disconnect closes the connection.
	Disconnect() error
	// GetStatus retrieves current printer status.
	GetStatus() (*model.PrinterState, error)
	// StartJob sends a file to print.
	StartJob(filename string, filepath string) error
	// PauseJob pauses the current print.
	PauseJob() error
	// ResumeJob resumes a paused print.
	ResumeJob() error
	// CancelJob cancels the current print.
	CancelJob() error
	// SetStatusCallback sets callback for status updates.
	SetStatusCallback(func(*model.PrinterState))
}

Client defines the interface for printer communication.

type DiscoveredPrinter

type DiscoveredPrinter struct {
	ID           string               `json:"id"`
	Name         string               `json:"name"`
	Host         string               `json:"host"`
	Port         int                  `json:"port"`
	Type         model.ConnectionType `json:"type"`
	Model        string               `json:"model,omitempty"`
	Manufacturer string               `json:"manufacturer,omitempty"`
	Version      string               `json:"version,omitempty"`
	SerialNumber string               `json:"serial_number,omitempty"`
	AlreadyAdded bool                 `json:"already_added"`
}

DiscoveredPrinter represents a printer found on the network.

type Discovery

type Discovery struct {
	// contains filtered or unexported fields
}

Discovery handles automatic printer discovery on the local network.

func NewDiscovery

func NewDiscovery() *Discovery

NewDiscovery creates a new printer discovery instance.

func (*Discovery) QuickScan

func (d *Discovery) QuickScan(ctx context.Context) ([]DiscoveredPrinter, error)

QuickScan does a fast scan of only the most common ports. Note: UDP-based discovery (SSDP, Bambu UDP) is disabled as it interferes with HTTP responses.

func (*Discovery) ScanBambuUDP

func (d *Discovery) ScanBambuUDP(ctx context.Context) ([]DiscoveredPrinter, error)

ScanBambuUDP uses Bambu's native UDP discovery protocol on port 2021.

func (*Discovery) ScanNetwork

func (d *Discovery) ScanNetwork(ctx context.Context) ([]DiscoveredPrinter, error)

ScanNetwork discovers printers on the local network. Uses sequential scanning to avoid file descriptor exhaustion.

func (*Discovery) ScanSSDPBambu

func (d *Discovery) ScanSSDPBambu(ctx context.Context) ([]DiscoveredPrinter, error)

ScanSSDPBambu performs SSDP discovery specifically for Bambu printers. Bambu printers advertise via SSDP with specific device types.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages connections to multiple printers.

func NewManager

func NewManager() *Manager

NewManager creates a new printer manager.

func (*Manager) CancelJob

func (m *Manager) CancelJob(printerID uuid.UUID) error

CancelJob cancels the current print on a printer.

func (*Manager) Connect

func (m *Manager) Connect(p *model.Printer) error

Connect establishes connection to a printer.

func (*Manager) Disconnect

func (m *Manager) Disconnect(id uuid.UUID)

Disconnect closes connection to a printer.

func (*Manager) DisconnectAll

func (m *Manager) DisconnectAll()

DisconnectAll closes all printer connections. Used during graceful shutdown.

func (*Manager) GetAllStates

func (m *Manager) GetAllStates() map[uuid.UUID]*model.PrinterState

GetAllStates retrieves current state for all printers.

func (*Manager) GetState

func (m *Manager) GetState(id uuid.UUID) (*model.PrinterState, error)

GetState retrieves current state for a printer.

func (*Manager) OnStatusChange

func (m *Manager) OnStatusChange(cb StatusChangeCallback)

OnStatusChange registers a callback for printer status changes. This allows services to react to printer state transitions (e.g., detect failures).

func (*Manager) PauseJob

func (m *Manager) PauseJob(printerID uuid.UUID) error

PauseJob pauses the current print on a printer.

func (*Manager) ResumeJob

func (m *Manager) ResumeJob(printerID uuid.UUID) error

ResumeJob resumes a paused print on a printer.

func (*Manager) SetBroadcaster

func (m *Manager) SetBroadcaster(b model.Broadcaster)

SetBroadcaster sets the broadcaster for real-time updates.

func (*Manager) StartJob

func (m *Manager) StartJob(printerID uuid.UUID, filename string, filepath string) error

StartJob sends a print job to a printer.

type MoonrakerClient

type MoonrakerClient struct {
	// contains filtered or unexported fields
}

MoonrakerClient implements Client for Moonraker API (Klipper).

func NewMoonrakerClient

func NewMoonrakerClient(printerID uuid.UUID, baseURL string) *MoonrakerClient

NewMoonrakerClient creates a new Moonraker client.

func (*MoonrakerClient) CancelJob

func (c *MoonrakerClient) CancelJob() error

CancelJob cancels the current print.

func (*MoonrakerClient) Connect

func (c *MoonrakerClient) Connect() error

Connect establishes connection and starts status polling.

func (*MoonrakerClient) Disconnect

func (c *MoonrakerClient) Disconnect() error

Disconnect stops polling.

func (*MoonrakerClient) GetStatus

func (c *MoonrakerClient) GetStatus() (*model.PrinterState, error)

GetStatus retrieves current printer status.

func (*MoonrakerClient) PauseJob

func (c *MoonrakerClient) PauseJob() error

PauseJob pauses the current print.

func (*MoonrakerClient) ResumeJob

func (c *MoonrakerClient) ResumeJob() error

ResumeJob resumes a paused print.

func (*MoonrakerClient) SetStatusCallback

func (c *MoonrakerClient) SetStatusCallback(cb func(*model.PrinterState))

SetStatusCallback sets the callback for status updates.

func (*MoonrakerClient) StartJob

func (c *MoonrakerClient) StartJob(filename string, filePath string) error

StartJob uploads and starts printing a file.

type OctoPrintClient

type OctoPrintClient struct {
	// contains filtered or unexported fields
}

OctoPrintClient implements Client for OctoPrint API.

func NewOctoPrintClient

func NewOctoPrintClient(printerID uuid.UUID, baseURL string, apiKey string) *OctoPrintClient

NewOctoPrintClient creates a new OctoPrint client.

func (*OctoPrintClient) CancelJob

func (c *OctoPrintClient) CancelJob() error

CancelJob cancels the current print.

func (*OctoPrintClient) Connect

func (c *OctoPrintClient) Connect() error

Connect establishes connection and starts status polling.

func (*OctoPrintClient) Disconnect

func (c *OctoPrintClient) Disconnect() error

Disconnect stops polling and closes connection.

func (*OctoPrintClient) GetStatus

func (c *OctoPrintClient) GetStatus() (*model.PrinterState, error)

GetStatus retrieves current printer status.

func (*OctoPrintClient) PauseJob

func (c *OctoPrintClient) PauseJob() error

PauseJob pauses the current print.

func (*OctoPrintClient) ResumeJob

func (c *OctoPrintClient) ResumeJob() error

ResumeJob resumes a paused print.

func (*OctoPrintClient) SetStatusCallback

func (c *OctoPrintClient) SetStatusCallback(cb func(*model.PrinterState))

SetStatusCallback sets the callback for status updates.

func (*OctoPrintClient) StartJob

func (c *OctoPrintClient) StartJob(filename string, filepath string) error

StartJob uploads and starts printing a file.

type StatusChangeCallback

type StatusChangeCallback func(newState *model.PrinterState, oldState *model.PrinterState)

StatusChangeCallback is called when a printer's status changes. Receives the new state and the previous state (nil if first update).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL