Printer MQTT Client

Printer class for handling MQTT communication with the printer

bambulabs_api.PrinterMQTTClient.auto_home(self) bool

Auto home the printer

Returns:

success of the auto home command

Return type:

bool

bambulabs_api.PrinterMQTTClient.calibration(self, bed_levelling: bool = True, motor_noise_cancellation: bool = True, vibration_compensation: bool = True) bool

Start the full calibration process

Returns:

success of starting the full calibration process

Return type:

bool

bambulabs_api.PrinterMQTTClient.connect(self) None

Connects to the MQTT server asynchronously

bambulabs_api.PrinterMQTTClient.current_layer_num(self) int

Get the number of layers of the current/last print

Returns:

number of layers

Return type:

int

bambulabs_api.PrinterMQTTClient.downgrade_firmware(self, firmware_version: str) bool

Downgrade the firmware to a given version. Requires firmware version to be listed in the firmware history.

Parameters:

firmware_version (str) – target firmware version to downgrade to. Firmware version must be in the version history.

Returns:

if the printer downgraded to the target firmware.

Return type:

bool

bambulabs_api.PrinterMQTTClient.dump(self) dict[Any, Any]

Dump the current state of the printer message

Returns:

The latest data recorded

Return type:

dict[Any, Any]

bambulabs_api.PrinterMQTTClient.firmware_version(self)

Get the firmware verions.

Returns:

firmware version

Return type:

str

bambulabs_api.PrinterMQTTClient.gcode_file(self) str

Get current gcode file (current print details)

Returns:

current gcode_file name

Return type:

str

bambulabs_api.PrinterMQTTClient.gcode_file_prepare_percentage(self) int

Get the gcode file preparation percentage

Returns:

percentage

Return type:

int

bambulabs_api.PrinterMQTTClient.get_access_code(self) str

Get local access code.

Returns:

list of firmware history.

Return type:

list[Any]

bambulabs_api.PrinterMQTTClient.get_aux_fan_speed(self)

Get auxiliary fan speed

Returns:

0-255 value representing auxiliary fan speed

Return type:

int

bambulabs_api.PrinterMQTTClient.get_bed_temperature(self) float

Get the bed temperature

Returns:

bed temperature

Return type:

float

bambulabs_api.PrinterMQTTClient.get_bed_temperature_target(self) float

Get the bed temperature target

Returns:

bed temperature target

Return type:

float

bambulabs_api.PrinterMQTTClient.get_chamber_fan_speed(self)

Get chamber fan speed

Returns:

0-255 value representing chamber fan speed

Return type:

int

bambulabs_api.PrinterMQTTClient.get_chamber_temperature(self) float

Get the chamber temperature

Returns:

chamber temperature

Return type:

float

bambulabs_api.PrinterMQTTClient.get_current_state(self) PrintStatus

Get the current printer state from stg_cur

Returns:

current_state

Return type:

PrintStatus

bambulabs_api.PrinterMQTTClient.get_fan_gear(self)

Get fan_gear

Returns:

consolidated fan value for part, aux and chamber fan speeds

Return type:

int

bambulabs_api.PrinterMQTTClient.get_file_name(self) str

Get the file name of the current/last print

Returns:

file name

Return type:

str

bambulabs_api.PrinterMQTTClient.get_firmware_history(self) list[Any]

Get list of history firmware versions.

Returns:

list of firmware history.

Return type:

list[Any]

bambulabs_api.PrinterMQTTClient.get_last_print_percentage(self) int | str | None

Get the last print percentage

Returns:

The last print percentage

Return type:

int | str | None

bambulabs_api.PrinterMQTTClient.get_light_state(self) str

Get the printer light state

Returns:

led_mode

Return type:

str

bambulabs_api.PrinterMQTTClient.get_nozzle_temperature(self) float

Get the nozzle temperature

Returns:

nozzle temperature

Return type:

float

bambulabs_api.PrinterMQTTClient.get_nozzle_temperature_target(self) float

Get the nozzle temperature target

Returns:

nozzle temperature target

Return type:

float

bambulabs_api.PrinterMQTTClient.get_part_fan_speed(self)

Get part fan speed

Returns:

0-255 value representing part fan speed

Return type:

int

bambulabs_api.PrinterMQTTClient.get_print_speed(self) int

Get the print speed

Returns:

print speed

Return type:

int

bambulabs_api.PrinterMQTTClient.get_printer_state(self) GcodeState

Get the printer state

Returns:

printer state

Return type:

GcodeState

bambulabs_api.PrinterMQTTClient.get_remaining_time(self) int | str | None

Get the remaining time for the print

Returns:

The remaining time for the print

Return type:

int | str | None

bambulabs_api.PrinterMQTTClient.get_sequence_id(self)

Get the current sequence ID

Returns:

Get the current sequence ID

Return type:

int

bambulabs_api.PrinterMQTTClient.get_skipped_objects(self) list[int]

Get skipped Objects.

Args:

Returns:

if publish command is successful

Return type:

bool

bambulabs_api.PrinterMQTTClient.info_get_version(self) bool

Request the printer for hardware and firmware info.

Returns:

success state of the get info command

Return type:

bool

bambulabs_api.PrinterMQTTClient.is_connected(self)

Check if the mqtt client is connected

Returns:

If the mqtt client is connected

Return type:

bool

bambulabs_api.PrinterMQTTClient.load_filament_spool(self) bool

Load the filament into the printer

Returns:

success of loading the filament

Return type:

bool

bambulabs_api.PrinterMQTTClient.loop_forever(self)

Loop client forever (synchonous, blocking call)

Returns:

error code of loop start

Return type:

MQTTErrorCode

bambulabs_api.PrinterMQTTClient.new_printer_firmware(self) str | None

Get if a new firmware version is available.

Returns:

newest firmware version if available else None.

Return type:

str | None

bambulabs_api.PrinterMQTTClient.nozzle_diameter(self) float

Get the nozzle diameter currently registered to printer

Returns:

nozzle diameter

Return type:

float

bambulabs_api.PrinterMQTTClient.nozzle_type(self) NozzleType

Get the nozzle type currently registered to printer

Returns:

nozzle diameter

Return type:

NozzleType

bambulabs_api.PrinterMQTTClient.pause_print(self) bool

Pause the print

Returns:

print_status

Return type:

str

bambulabs_api.PrinterMQTTClient.print_error_code(self) int

Get current gcode file (current print details)

Returns:

error code (0 if normal)

Return type:

int

bambulabs_api.PrinterMQTTClient.print_type(self) str

Get what type of print the current printing file is from (cloud, local)

Returns:

print type

Return type:

str

bambulabs_api.PrinterMQTTClient.process_ams(self)

Get the filament information from the AMS system

bambulabs_api.PrinterMQTTClient.pushall(self) bool

Force the printer to send a full update of the current state Warning: Pushall should be used sparingly - large numbers of updates can result in the printer lagging.

Returns:

success state of the pushall command

Return type:

bool

bambulabs_api.PrinterMQTTClient.request_access_code(self)

Request the printer for access code.

Returns:

success of the auto home command

Return type:

bool

bambulabs_api.PrinterMQTTClient.request_firmware_history(self)

Request firmware history for printer.

Returns:

success state of the get info command

Return type:

bool

bambulabs_api.PrinterMQTTClient.resume_filament_action(self) bool

Resume the current filament action

Returns:

success of resuming the filament action

Return type:

bool

bambulabs_api.PrinterMQTTClient.resume_print(self) bool

Resume the print

Returns:

print_status

Return type:

str

bambulabs_api.PrinterMQTTClient.send_gcode(self, gcode_command: str | list[str], gcode_check: bool = True) bool

Send a G-code line command to the printer

Parameters:
  • gcode_command (str | list[str]) – G-code command(s) to send to the printer

  • gcode_check – (bool): whether to check gcode validity. Default to True.

bambulabs_api.PrinterMQTTClient.set_auto_step_recovery(self, auto_step_recovery: bool = True) bool

Set whether or not to set auto step recovery

Parameters:

auto_step_recovery (bool) – flag to set auto step recovery. Default True.

Returns:

success of the auto step recovery command command

Return type:

bool

bambulabs_api.PrinterMQTTClient.set_aux_fan_speed(self, speed: int | float) bool

Set the fan speed of the aux part fan

Parameters:

speed (int | float) – The speed to set the part fan

Returns:

success of setting the fan speed

Return type:

bool

bambulabs_api.PrinterMQTTClient.set_bed_height(self, height: int) bool

Set the absolute height of the bed (Z-axis). 0 is the bed at the nozzle tip and 256 is the bed at the bottom of the printer.

Parameters:

height (int) – height to set the bed to

Returns:

success of the bed height setting

Return type:

bool

bambulabs_api.PrinterMQTTClient.set_bed_temperature(self, temperature: int, override: bool = False) bool

Set the bed temperature. Note P1 firmware version above 01.06 does not support M140. M190 is used instead (set and wait for temperature). To prevent long wait times, if temperature is set to below 40 deg cel, no temperature is set, override flag is provided to circumvent this.

Parameters:
  • temperature (int) – The temperature to set the bed to

  • override (bool) – Whether to override guards. Default to False

Returns:

success of setting the bed temperature

Return type:

bool

bambulabs_api.PrinterMQTTClient.set_chamber_fan_speed(self, speed: int | float) bool

Set the fan speed of the chamber fan

Parameters:

speed (int | float) – The speed to set the part fan

Returns:

success of setting the fan speed

Return type:

bool

bambulabs_api.PrinterMQTTClient.set_nozzle_info(self, nozzle_type: NozzleType, nozzle_diameter: float = 0.4) bool

Set the nozzle info.

Parameters:
  • nozzle_type (NozzleType) – nozzle type to set.

  • nozzle_diameter (Optional[float]) – diameter of nozzle. Defaults to 0.4.

Returns:

if publish command is successful.

Return type:

bool

bambulabs_api.PrinterMQTTClient.set_nozzle_temperature(self, temperature: int, override: bool = False) bool

Set the nozzle temperature. Note P1 firmware version above 01.06 does not support M104. M109 is used instead (set and wait for temperature). To prevent long wait times, if temperature is set to below 40 deg cel, no temperature is set, override flag is provided to circumvent this.

Parameters:
  • temperature (int) – The temperature to set the bed to

  • override (bool) – Whether to override guards. Default to False

  • temperature – temperature to set the nozzle to

Returns:

success of setting the nozzle temperature

Return type:

bool

bambulabs_api.PrinterMQTTClient.set_onboard_printer_timelapse(self, enable: bool = True)

Enable/disable the printer’s onboard timelapse/video functionality.

Parameters:

enable (bool) – object list to skip objects. Defaults to True.

Returns:

if publish command is successful.

Return type:

bool

bambulabs_api.PrinterMQTTClient.set_part_fan_speed(self, speed: int | float) bool

Set the fan speed of the part fan

Parameters:

speed (int | float) – The speed to set the part fan

Returns:

success of setting the fan speed

Return type:

bool

bambulabs_api.PrinterMQTTClient.set_print_speed_lvl(self, speed_lvl: int = 1) bool

Set the print speed

Parameters:

speed_lvl (int, optional) – Set the speed level of printer. Defaults to 1.

Returns:

success of setting the print speed

Return type:

bool

bambulabs_api.PrinterMQTTClient.set_printer_filament(self, filament_material: AMSFilamentSettings, colour: str, ams_id: int = 255, tray_id: int = 254) bool

Set the printer filament manually fed into the printer

Parameters:
  • filament_material (Filament) – filament material to set.

  • colour (str) – colour of the filament.

  • ams_id (int) – ams id. Default to external filament spool: 255.

  • tray_id (int) – tray id. Default to external filament spool: 254.

Returns:

success of setting the printer filament

Return type:

bool

bambulabs_api.PrinterMQTTClient.skip_objects(self, obj_list: list[int]) bool

Skip Objects during printing.

Parameters:

obj_list (list[int]) – object list to skip objects.

Returns:

if publish command is successful

Return type:

bool

bambulabs_api.PrinterMQTTClient.start(self)

Starts the MQTT client

Returns:

error code of loop start

Return type:

MQTTErrorCode

bambulabs_api.PrinterMQTTClient.start_print_3mf(self, filename: str, plate_number: int | str, use_ams: bool = True, ams_mapping: list[int] = [0], skip_objects: list[int] | None = None, flow_calibration: bool = True) bool

Start the print

Parameters:
  • filename (str) – The name of the file to print

  • plate_number (int) – The plate number to print to

  • use_ams (bool, optional) – Use the AMS system. Defaults to True.

  • ams_mapping (list[int], optional) – The AMS mapping. Defaults to [0].

  • skip_objects (list[int] | None, optional) – List of gcode objects to skip. Defaults to [].

Returns:

print_status

Return type:

str

bambulabs_api.PrinterMQTTClient.stop(self)

Stops the MQTT client

bambulabs_api.PrinterMQTTClient.stop_print(self) bool

Stop the print

Returns:

print_status

Return type:

str

bambulabs_api.PrinterMQTTClient.subtask_name(self) str

Get current subtask name (current print details)

Returns:

current subtask name

Return type:

str

bambulabs_api.PrinterMQTTClient.total_layer_num(self) int

Get the total number of layers of the current/last print

Returns:

number of layers

Return type:

int

bambulabs_api.PrinterMQTTClient.turn_light_off(self) bool

Turn off the printer light

bambulabs_api.PrinterMQTTClient.turn_light_on(self) bool

Turn on the printer light

bambulabs_api.PrinterMQTTClient.unload_filament_spool(self) bool

Unload the filament from the printer

Returns:

success of unloading the filament

Return type:

bool

bambulabs_api.PrinterMQTTClient.upgrade_firmware(self, override: bool = False) bool

Upgrade to latest firmware. Logs warning is firmware version may cause api to fail.

Parameters:

override (bool) – nozzle type to set. Default to False.

Returns:

if the printer upgraded to the latest firmware.

Returns false if firmware is causes api to break and override is not provided.

Return type:

bool

bambulabs_api.PrinterMQTTClient.vt_tray(self) FilamentTray

Get Filament Tray of the external spool.

Returns:

External Spool Filament Tray

Return type:

FilamentTray

bambulabs_api.PrinterMQTTClient.wifi_signal(self) str

Get Wifi signal in dBm

Returns:

Wifi signal

Return type:

str