Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
f910a6b03e | |||
d94c76b96e | |||
8d8005d10e | |||
2799c23b0b |
@ -27,7 +27,11 @@ class BambuPrintPlugin(
|
|||||||
"flow_cali": False,
|
"flow_cali": False,
|
||||||
"vibration_cali": True,
|
"vibration_cali": True,
|
||||||
"layer_inspect": True,
|
"layer_inspect": True,
|
||||||
"use_ams": False}
|
"use_ams": False,
|
||||||
|
"local_mqtt": True,
|
||||||
|
"region": "",
|
||||||
|
"email": "",
|
||||||
|
"auth_token": ""}
|
||||||
|
|
||||||
def support_3mf_files(self):
|
def support_3mf_files(self):
|
||||||
return {'machinecode': {'3mf': ["3mf"]}}
|
return {'machinecode': {'3mf': ["3mf"]}}
|
||||||
|
@ -3,6 +3,7 @@ __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agp
|
|||||||
|
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
import datetime
|
||||||
import os
|
import os
|
||||||
import queue
|
import queue
|
||||||
import re
|
import re
|
||||||
@ -14,6 +15,7 @@ from pybambu import BambuClient, commands
|
|||||||
|
|
||||||
from serial import SerialTimeoutException
|
from serial import SerialTimeoutException
|
||||||
from octoprint.util import RepeatedTimer, to_bytes, to_unicode, get_dos_filename
|
from octoprint.util import RepeatedTimer, to_bytes, to_unicode, get_dos_filename
|
||||||
|
from octoprint.util.files import unix_timestamp_to_m20_timestamp
|
||||||
|
|
||||||
from .ftpsclient import IoTFTPSClient
|
from .ftpsclient import IoTFTPSClient
|
||||||
|
|
||||||
@ -45,10 +47,11 @@ class BambuPrinter:
|
|||||||
}
|
}
|
||||||
self._sendBusy = False
|
self._sendBusy = False
|
||||||
self._ambient_temperature = 21.3
|
self._ambient_temperature = 21.3
|
||||||
self.temp = [self._ambient_temperature ]
|
self.temp = [self._ambient_temperature]
|
||||||
self.targetTemp = [0.0]
|
self.targetTemp = [0.0]
|
||||||
self.bedTemp = self._ambient_temperature
|
self.bedTemp = self._ambient_temperature
|
||||||
self.bedTargetTemp = 0.0
|
self.bedTargetTemp = 0.0
|
||||||
|
self._hasChamber = printer_profile_manager.get_current().get("heatedChamber")
|
||||||
self.chamberTemp = self._ambient_temperature
|
self.chamberTemp = self._ambient_temperature
|
||||||
self.chamberTargetTemp = 0.0
|
self.chamberTargetTemp = 0.0
|
||||||
self.lastTempAt = time.monotonic()
|
self.lastTempAt = time.monotonic()
|
||||||
@ -128,6 +131,7 @@ class BambuPrinter:
|
|||||||
# )
|
# )
|
||||||
# bufferThread.start()
|
# bufferThread.start()
|
||||||
|
|
||||||
|
# Move this into M110 command response?
|
||||||
connectionThread = threading.Thread(
|
connectionThread = threading.Thread(
|
||||||
target=self._create_connection,
|
target=self._create_connection,
|
||||||
name="octoprint.plugins.bambu_printer.connection_thread",
|
name="octoprint.plugins.bambu_printer.connection_thread",
|
||||||
@ -147,7 +151,7 @@ class BambuPrinter:
|
|||||||
elif event_type == "event_printer_data_update":
|
elif event_type == "event_printer_data_update":
|
||||||
device_data = self.bambu.get_device()
|
device_data = self.bambu.get_device()
|
||||||
ams = device_data.ams.__dict__
|
ams = device_data.ams.__dict__
|
||||||
info = device_data.info.__dict__
|
print_job = device_data.print_job.__dict__
|
||||||
temperatures = device_data.temperature.__dict__
|
temperatures = device_data.temperature.__dict__
|
||||||
lights = device_data.lights.__dict__
|
lights = device_data.lights.__dict__
|
||||||
fans = device_data.fans.__dict__
|
fans = device_data.fans.__dict__
|
||||||
@ -159,20 +163,21 @@ class BambuPrinter:
|
|||||||
self.bedTargetTemp = temperatures.get("target_bed_temp", 0.0)
|
self.bedTargetTemp = temperatures.get("target_bed_temp", 0.0)
|
||||||
self.chamberTemp = temperatures.get("chamber_temp", 0.0)
|
self.chamberTemp = temperatures.get("chamber_temp", 0.0)
|
||||||
|
|
||||||
if info.get("gcode_state") == "RUNNING":
|
if print_job.get("gcode_state") == "RUNNING":
|
||||||
if not self._sdPrintingSemaphore.is_set():
|
if not self._sdPrintingSemaphore.is_set():
|
||||||
self._sdPrintingSemaphore.set()
|
self._sdPrintingSemaphore.set()
|
||||||
if self._sdPrintingPausedSemaphore.is_set():
|
if self._sdPrintingPausedSemaphore.is_set():
|
||||||
self._sdPrintingPausedSemaphore.clear()
|
self._sdPrintingPausedSemaphore.clear()
|
||||||
if not self._sdPrinting:
|
if not self._sdPrinting:
|
||||||
filename = info.get("subtask_name")
|
filename = print_job.get("subtask_name")
|
||||||
|
# TODO: swap this out to use 8 dot 3 name based on long name/path
|
||||||
self._selectSdFile(filename)
|
self._selectSdFile(filename)
|
||||||
self._startSdPrint(from_printer=True)
|
self._startSdPrint(from_printer=True)
|
||||||
|
|
||||||
# fuzzy math here to get print percentage to match BambuStudio
|
# fuzzy math here to get print percentage to match BambuStudio
|
||||||
self._selectedSdFilePos = int(self._selectedSdFileSize * ((info.get("print_percentage") + 1)/100))
|
self._selectedSdFilePos = int(self._selectedSdFileSize * ((print_job.get("print_percentage") + 1)/100))
|
||||||
|
|
||||||
if info.get("gcode_state") == "PAUSE":
|
if print_job.get("gcode_state") == "PAUSE":
|
||||||
if not self._sdPrintingPausedSemaphore.is_set():
|
if not self._sdPrintingPausedSemaphore.is_set():
|
||||||
self._sdPrintingPausedSemaphore.set()
|
self._sdPrintingPausedSemaphore.set()
|
||||||
if self._sdPrintingSemaphore.is_set():
|
if self._sdPrintingSemaphore.is_set():
|
||||||
@ -180,7 +185,7 @@ class BambuPrinter:
|
|||||||
self._send("// action:paused")
|
self._send("// action:paused")
|
||||||
self._sendPaused()
|
self._sendPaused()
|
||||||
|
|
||||||
if info.get("gcode_state") == "FINISH" and self._sdPrintingSemaphore.is_set():
|
if print_job.get("gcode_state") == "FINISH" and self._sdPrintingSemaphore.is_set():
|
||||||
self._selectedSdFilePos = self._selectedSdFileSize
|
self._selectedSdFilePos = self._selectedSdFileSize
|
||||||
self._finishSdPrint()
|
self._finishSdPrint()
|
||||||
def _create_connection(self):
|
def _create_connection(self):
|
||||||
@ -197,10 +202,14 @@ class BambuPrinter:
|
|||||||
serial=self._settings.get(["serial"]),
|
serial=self._settings.get(["serial"]),
|
||||||
host=self._settings.get(["host"]),
|
host=self._settings.get(["host"]),
|
||||||
username=self._settings.get(["username"]),
|
username=self._settings.get(["username"]),
|
||||||
access_code=self._settings.get(["access_code"])
|
access_code=self._settings.get(["access_code"]),
|
||||||
|
local_mqtt=self._settings.get_boolean(["local_mqtt"]),
|
||||||
|
region=self._settings.get(["region"]),
|
||||||
|
email=self._settings.get(["email"]),
|
||||||
|
auth_token=self._settings.get(["auth_token"])
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.bambu.connect(callback=self.new_update)
|
self.bambu.connect(callback=self.new_update)
|
||||||
self._logger.info(f"bambu connection status: {self.bambu.connected}")
|
self._logger.info(f"bambu connection status: {self.bambu.connected}")
|
||||||
self._sendOk()
|
self._sendOk()
|
||||||
# while True:
|
# while True:
|
||||||
@ -463,6 +472,11 @@ class BambuPrinter:
|
|||||||
self._pauseSdPrint()
|
self._pauseSdPrint()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _gcode_M524(self, data: str) -> bool:
|
||||||
|
if self._sdCardReady:
|
||||||
|
self._cancelSdPrint()
|
||||||
|
return False
|
||||||
|
|
||||||
def _gcode_M26(self, data: str) -> bool:
|
def _gcode_M26(self, data: str) -> bool:
|
||||||
self._logger.debug("ignoring M26 command.")
|
self._logger.debug("ignoring M26 command.")
|
||||||
self._send("M26 disabled for Bambu")
|
self._send("M26 disabled for Bambu")
|
||||||
@ -598,7 +612,7 @@ class BambuPrinter:
|
|||||||
request_resend()
|
request_resend()
|
||||||
|
|
||||||
def _listSd(self, incl_long=False, incl_timestamp=False):
|
def _listSd(self, incl_long=False, incl_timestamp=False):
|
||||||
line = "{name} {size} \"{name}\""
|
line = "{dosname} {size} {timestamp} \"{name}\""
|
||||||
|
|
||||||
self._send("Begin file list")
|
self._send("Begin file list")
|
||||||
for item in map(lambda x: line.format(**x), self._getSdFiles()):
|
for item in map(lambda x: line.format(**x), self._getSdFiles()):
|
||||||
@ -619,15 +633,18 @@ class BambuPrinter:
|
|||||||
else:
|
else:
|
||||||
filename = entry
|
filename = entry
|
||||||
filesize = ftp.ftps_session.size(entry)
|
filesize = ftp.ftps_session.size(entry)
|
||||||
|
date_str = ftp.ftps_session.sendcmd(f"MDTM {entry}").replace("213 ", "")
|
||||||
|
filedate = datetime.datetime.strptime(date_str, "%Y%m%d%H%M%S").replace(tzinfo=datetime.timezone.utc).timestamp()
|
||||||
dosname = get_dos_filename(filename, existing_filenames=list(result.keys())).lower()
|
dosname = get_dos_filename(filename, existing_filenames=list(result.keys())).lower()
|
||||||
data = {
|
data = {
|
||||||
"dosname": dosname,
|
"dosname": dosname,
|
||||||
"name": filename,
|
"name": filename,
|
||||||
"path": filename,
|
"path": filename,
|
||||||
"size": filesize,
|
"size": filesize,
|
||||||
|
"timestamp": unix_timestamp_to_m20_timestamp(int(filedate))
|
||||||
}
|
}
|
||||||
result[filename.lower()] = data
|
result[filename.lower()] = data
|
||||||
# result[dosname.lower()] = filename.lower()
|
result[dosname.lower()] = filename.lower()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -682,6 +699,13 @@ class BambuPrinter:
|
|||||||
else:
|
else:
|
||||||
self._logger.info("print pause failed")
|
self._logger.info("print pause failed")
|
||||||
|
|
||||||
|
def _cancelSdPrint(self):
|
||||||
|
if self.bambu.connected:
|
||||||
|
if self.bambu.publish(commands.STOP):
|
||||||
|
self._logger.info("print cancelled")
|
||||||
|
else:
|
||||||
|
self._logger.info("print cancel failed")
|
||||||
|
|
||||||
def _setSdPos(self, pos):
|
def _setSdPos(self, pos):
|
||||||
self._newSdFilePos = pos
|
self._newSdFilePos = pos
|
||||||
|
|
||||||
@ -694,10 +718,10 @@ class BambuPrinter:
|
|||||||
def _generateTemperatureOutput(self) -> str:
|
def _generateTemperatureOutput(self) -> str:
|
||||||
template = "{heater}:{actual:.2f}/ {target:.2f}"
|
template = "{heater}:{actual:.2f}/ {target:.2f}"
|
||||||
temps = collections.OrderedDict()
|
temps = collections.OrderedDict()
|
||||||
heater = "T"
|
temps["T"] = (self.temp[0], self.targetTemp[0])
|
||||||
temps[heater] = (self.temp[0], self.targetTemp[0])
|
|
||||||
temps["B"] = (self.bedTemp, self.bedTargetTemp)
|
temps["B"] = (self.bedTemp, self.bedTargetTemp)
|
||||||
temps["C"] = (self.chamberTemp, self.chamberTargetTemp)
|
if self._hasChamber:
|
||||||
|
temps["C"] = (self.chamberTemp, self.chamberTargetTemp)
|
||||||
|
|
||||||
output = " ".join(
|
output = " ".join(
|
||||||
map(
|
map(
|
||||||
@ -741,7 +765,7 @@ class BambuPrinter:
|
|||||||
"command": "project_file",
|
"command": "project_file",
|
||||||
"param": "Metadata/plate_1.gcode",
|
"param": "Metadata/plate_1.gcode",
|
||||||
"subtask_name": f"{self._selectedSdFile}",
|
"subtask_name": f"{self._selectedSdFile}",
|
||||||
"url": f"file:///mnt/sdcard/{self._selectedSdFile}",
|
"url": f"file:///mnt/sdcard/{self._selectedSdFile}" if self._settings.get_boolean(["device_type"]) in ["X1", "X1C"] else f"file:///sdcard/{self._selectedSdFile}",
|
||||||
"timelapse": self._settings.get_boolean(["timelapse"]),
|
"timelapse": self._settings.get_boolean(["timelapse"]),
|
||||||
"bed_leveling": self._settings.get_boolean(["bed_leveling"]),
|
"bed_leveling": self._settings.get_boolean(["bed_leveling"]),
|
||||||
"flow_cali": self._settings.get_boolean(["flow_cali"]),
|
"flow_cali": self._settings.get_boolean(["flow_cali"]),
|
||||||
|
6
setup.py
6
setup.py
@ -14,7 +14,7 @@ plugin_package = "octoprint_bambu_printer"
|
|||||||
plugin_name = "OctoPrint-BambuPrinter"
|
plugin_name = "OctoPrint-BambuPrinter"
|
||||||
|
|
||||||
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
||||||
plugin_version = "0.0.1"
|
plugin_version = "0.0.5"
|
||||||
|
|
||||||
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
|
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
|
||||||
# module
|
# module
|
||||||
@ -33,7 +33,7 @@ plugin_url = "https://github.com/jneilliii/OctoPrint-BambuPrinter"
|
|||||||
plugin_license = "AGPLv3"
|
plugin_license = "AGPLv3"
|
||||||
|
|
||||||
# Any additional requirements besides OctoPrint should be listed here
|
# Any additional requirements besides OctoPrint should be listed here
|
||||||
plugin_requires = ["paho-mqtt", "pybambu>=1.0.0"]
|
plugin_requires = ["paho-mqtt", "python-dateutil", "pybambu>=1.0.1"]
|
||||||
|
|
||||||
### --------------------------------------------------------------------------------------------------------------------
|
### --------------------------------------------------------------------------------------------------------------------
|
||||||
### More advanced options that you usually shouldn't have to touch follow after this point
|
### More advanced options that you usually shouldn't have to touch follow after this point
|
||||||
@ -61,7 +61,7 @@ plugin_ignored_packages = []
|
|||||||
# additional_setup_parameters = {"dependency_links": ["https://github.com/someUser/someRepo/archive/master.zip#egg=someDependency-dev"]}
|
# additional_setup_parameters = {"dependency_links": ["https://github.com/someUser/someRepo/archive/master.zip#egg=someDependency-dev"]}
|
||||||
# "python_requires": ">=3,<4" blocks installation on Python 2 systems, to prevent confused users and provide a helpful error.
|
# "python_requires": ">=3,<4" blocks installation on Python 2 systems, to prevent confused users and provide a helpful error.
|
||||||
# Remove it if you would like to support Python 2 as well as 3 (not recommended).
|
# Remove it if you would like to support Python 2 as well as 3 (not recommended).
|
||||||
additional_setup_parameters = {"python_requires": ">=3,<4"}
|
additional_setup_parameters = {"python_requires": ">=3.9,<4"}
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user