bambuprinter
BambuPrinter
BambuPrinter is the main class within bambu-printer-manager for interacting with and
managing your Bambu Lab 3d printer. It provides an object oriented abstraction layer
between your project and the mqtt and ftps based mechanisms in place for communicating
with your printer.
__init__(config=None)
Sets up all internal storage attributes for BambuPrinter and bootstraps the
logging engine.
Parameters
- config : Optional[BambuConfig] = None
Attributes
- _mqtt_client_thread:
PRIVATEThread handle for the mqtt client thread - _watchdog_thread:
PRIVATEThread handle for the watchdog thread - _internalExcepton:
READ ONLYReturns the underlyingExceptionobject if a failure occurred. - _lastMessageTime:
READ ONLYEpoch timestamp (in seconds) for the last time an update was received from the printer. - _recent_update:
READ ONLYIndicates that a message from the printer has been recently processed. - _config:
READ/WRITEbambuconfig.BambuConfigConfiguration object associated with this instance. - _state:
READ/WRITEbambutools.PrinterStateenum reports on health / status of the connection to the printer. - _client:
READ ONLYProvides access to the underlyingpaho.mqtt.clientlibrary. - _on_update:
READ/WRITECallback used for pushing updates. Includes a self reference toBambuPrinteras an argument. - _bed_temp:
READ ONLYThe current printer bed temperature. - _bed_temp_target:
READ/WRITEThe target bed temperature for the printer. - _bed_temp_target_time:
READ ONLYEpoch timetamp for when target bed temperature was last set. - _tool_temp:
READ ONLYThe current printer tool temperature. - _tool_temp_target:
READ/WRITEThe target tool temperature for the printer. - _tool_temp_target_time:
READ ONLYEpoch timetamp for when target tool temperature was last set. - _chamber_temp
READ/WRITENot currently integrated but can be used as a stub for external chambers. - _chamber_temp_target
READ/WRITENot currently integrated but can be used as a stub for external chambers. - _chamber_temp_target_time:
READ ONLYEpoch timetamp for when target chamber temperature was last set. - _fan_gear
READ ONLYCombined fan(s) reporting value. Can be bit shifted for individual speeds. - _heat_break_fan_speed
READ_ONLYThe heatbreak (heater block) fan speed in percent. - _fan_speed
READ ONLYThe parts cooling fan speed in percent. - _fan_speed_target
READ/WRITEThe parts cooling fan target speed in percent. - _fan_speed_target_time:
READ ONLYEpoch timetamp for when target fan speed was last set. - _light_state
READ/WRITEBoolean value indicating the state of the work light. - _wifi_signal
READ ONLYThe current Wi-Fi signal strength of the printer. - _speed_level
READ/WRITESystem Print Speed (1=Quiet, 2=Standard, 3=Sport, 4=Ludicrous). - _gcode_state
READ ONLYState reported for job status (FAILED/RUNNING/PAUSE/IDLE/FINISH). - _gcode_file
READ ONLYThe name of the current or last printed gcode file. - _3mf_file
READ ONLYThe name of the 3mf file currently being printed. - _plate_num
READ ONLYThe selected plate # for the current 3mf file. - _subtask_name
READ ONLYThe name of the active subtask. - _print_type
READ ONLYNot entirely sure. Reports "idle" when no job is active. - _percent_complete
READ ONLYPercentage complete for the current active job. - _time_remaining
READ ONLYThe number of estimated minutes remaining for the active job. - _start_time
READ ONLYThe start time of the last (or current) active job in epoch minutes. - _elapsed_time
READ ONLYThe number of elapsed minutes for the last (or current) active job. - _layer_count
READ ONLYThe total number of layers for the current active job. - _current_layer
READ ONLYThe current layer being printed for the current active job. - _current_stage
READ ONLYMaps tobambutools.parseStage. - _current_stage_text
READ ONLYParsedcurrent_stagevalue. - _spools
READ ONLYA Tuple of all loaded spools. Can contain up to 5BambuSpoolobjects. - _target_spool
READ_ONLYThe spool # the printer is transitioning to (0-3=AMS,254=External,255=None). - _active_spool
READ_ONLYThe spool # the printer is using right now (0-3=AMS,254=External,255=None). - _spool_state
READ ONLYIndicates whether the spool is Loaded, Loading, Unloaded, or Unloading. - _ams_status
READ ONLYBitwise encoded status of the AMS (not currently used). - _ams_exists
READ ONLYBoolean value represents the detected presense of an AMS. - _ams_rfid_status
READ ONLYBitwise encoded status of the AMS RFID reader (not currently used). - _sdcard_contents
READ ONLYdict(json) value of all files on the SDCard (requiresget_sdcard_contentsbe called first). - _sdcard_3mf_files
READ ONLYdict(json) value of all.3mffiles on the SDCard (requiresget_sdcard_3mf_filesbe called first). - _hms_data
READ ONLYdict(json) value of any active hms codes with descriptions attached if they are known codes. - _hms_message
READ ONLYall hms_datadescfields concatinated into a single string for ease of use. - _print_type
READ ONLYcan becloudorlocal - _skipped_objects
READ ONLYarray of objects that have been skipped / cancelled - _nozzle_type
READ/WRITEthe type of nozzle loaded into the printer - _nozzle_diameter `READ/WRITE the diameter of the nozzle loaded into the printer
The attributes (where appropriate) are included whenever the class is serialized
using its toJson() method.
When accessing the class level attributes, use their associated properties as the class level attributes are marked private.
delete_sdcard_file(file)
Delete the specified file on the printer's SDCard and returns an updated dict of all files on the printer
Parameters
- file : str - the full path filename to be deleted
download_sdcard_file(src, dest)
Downloads a file from the printer
Parameters
- src : str - the full path filename on the printer to be downloaded to the host
- dest : str - the full path filename on the host to store the downloaded file
get_sdcard_3mf_files()
Returns a dict (json document) of all .3mf files on the printer's SD card.
The private class level _sdcard_3mf_files attribute is also populated.
Usage
The return value of this method is very useful for binding to things like a clientside TreeView
get_sdcard_contents()
Returns a dict (json document) of ALL files on the printer's SD card.
The private class level _sdcard_contents attribute is also populated.
Usage
The return value of this method is very useful for binding to things like a clientside TreeView
jsonSerializer(obj)
Helper method used by toJson() to serialize this object.
load_filament(slot)
Requests the printer to load filament into the extruder using the requested spool (slot #)
Parameters
slot : int
0- AMS Spool #11- AMS Spool #22- AMS Spool #33- AMS Spool #4254- External Spool
make_sdcard_directory(dir)
Creates the specified directory on the printer and returns an updated dict of all files on the printer
Parameters
- dir : str - the full path directory name to be created
pause_printing()
Pauses the current print job if one is running.
pause_session()
Pauses the BambuPrinter session is it is active. Under the covers this
method unsubscribes from the /report topic, essentially disabling all
printer data refreshes.
print_3mf_file(name, plate, bed, use_ams, ams_mapping='', bedlevel=True, flow=True, timelapse=False)
Submits a request to execute the name 3mf file on the printer's SDCard.
Parameters
- name : str - path, filename, and extension to execute
- plate : int - the plate # from your slicer to use (usually 1)
- bed : PlateType - the bambutools.PlateType to use
- use_ams : bool - Use the AMS for this print
- ams_mapping : Optional[str] - an
AMS Mappingthat specifies which AMS spools to use (external spool is used if blank) - bedlevel : Optional[bool] = True - boolean value indicates whether or not the printer should auto-level the bed
- flow : Optional[bool] = True - boolean value indicates if the printer should perform an extrusion flow calibration
- timelapse : Optional[bool] = False - boolean value indicates if printer should take timelapse photos during the job
Example
print_3mf_file("/jobs/my_project.3mf", 1, PlateType.HOT_PLATE, False, "")- Print the my_project.3mf file in the SDCard /jobs directory using the external spool with bed leveling and extrusion flow calibration enabled and timelapse disabledprint_3mf_file("/jobs/my_project.gcode.3mf", 1, PlateType.HOT_PLATE, True, "[-1,-1,2,-1]")- Same as above but use AMS spool #3
AMS Mapping
[0,-1,-1,-1]- use AMS spool #1 only[-1,1,-1,-1]- use AMS spool #2 only[0,-1,-1,3]- use AMS spools #1 and #4[0,1,2,3]- use all 4 AMS spools
quit()
Shuts down all threads. Your BambuPrinter instance should probably be
considered dead after making this call although you may be able to restart a
session with start_session().
refresh()
Triggers a full data refresh from the printer (if it is connected). You should use this method sparingly as resorting to it indicates something is not working properly.
rename_sdcard_file(src, dest)
Renames the specified file on the printer and returns an updated dict of all files on the printer
Parameters
- src : str - the full path name to be renamed
- dest : str - the full path name to be renamed to
resume_printing()
Resumes the current print job if one is paused.
resume_session()
Resumes a previously paused session by re-subscribing to the /report topic.
sdcard_file_exists(path)
Checks to see if a file exists on the printer at the path specified
Parameters
- path : str - the full path name to check
send_ams_control_command(ams_control_cmd)
Send an AMS Control Command - will pause, resume, or reset the AMS.
send_gcode(gcode)
Submit one, or more, gcode commands to the printer. To submit multiple gcode commands, separate them with a newline (\n) character.
Parameters
gcode : str
Examples
send_gcode("G91\nG0 X0\nG0 X50")- queues 3 gcode commands on the printer for processingsend_gcode("G28")- queues 1 gcode command on the printer for processing
set_ams_user_setting(setting, enabled, ams_id=0)
Enable or disable one of the AMSUserSetting options
set_buildplate_marker_detector(enabled)
Enables or disables the buildplate_marker_detector
set_print_option(option, enabled)
Enable or disable one of the PrintOption options
set_spool_details(tray_id, tray_info_idx, tray_id_name='', tray_type='', tray_color='', nozzle_temp_min=-1, nozzle_temp_max=-1)
Sets spool / tray details such as filament type, color, and nozzle min/max temperature.
For the external tray (254), send no_filament as the tray_info_idx value to empty the tray.
set_spool_k_factor(tray_id, k_value, n_coef=1.399999976158142, nozzle_temp=-1, bed_temp=-1, max_volumetric_speed=-1)
Sets the linear advance k factor for a specific spool / tray
skip_objects(objects)
skip a list of objects extracted from the 3mf's plate_x.json file
Parameters
objects : list
start_session()
Initiates a connection to the Bambu Lab printer and provides a stateful
session, with built-in recovery in the event BambuPrinter
becomes disconnected from the machine.
This method is required to be called before any commands or data collection / callbacks can take place with the machine.
stop_printing()
Requests the printer to stop printing if a job is currently running.
toJson()
Returns a dict (json document) representing this object's private class
level attributes that are serializable (most are).
unload_filament()
Requests the printer to unload whatever filament / spool may be currently loaded.
upload_sdcard_file(src, dest)
Uploads the local filesystem file to the printer and returns an updated dict of all files on the printer
Parameters
- src : str - the full path filename on the host to be uploaded to the printer
- dest : str - the full path filename on the printer to upload to