Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
908173214f | |||
df4bd6cf44 | |||
bcb1e0f649 | |||
f37eadf3ea | |||
48027f6008 | |||
616fdf7a82 | |||
c110fa140a | |||
3889efa67a | |||
cb4b345aa7 | |||
3d0cc26147 | |||
ff58636e41 | |||
f54ab5c29f | |||
7a4439c53e | |||
9eb8b0da65 | |||
ef969d3d3b | |||
3d92d73879 |
14
README.md
14
README.md
@ -1,17 +1,11 @@
|
|||||||
# OctoPrint-BambuPrinter
|
# OctoPrint-BambuPrinter
|
||||||
|
|
||||||
**TODO:** Describe what your plugin does.
|
## System Requirements
|
||||||
|
|
||||||
|
* Python 3.9 or higher (OctoPi 1.0.0)
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
Install via the bundled [Plugin Manager](https://docs.octoprint.org/en/master/bundledplugins/pluginmanager.html)
|
Install manually using this URL:
|
||||||
or manually using this URL:
|
|
||||||
|
|
||||||
https://github.com/jneilliii/OctoPrint-BambuPrinter/archive/master.zip
|
https://github.com/jneilliii/OctoPrint-BambuPrinter/archive/master.zip
|
||||||
|
|
||||||
**TODO:** Describe how to install your plugin, if more needs to be done than just installing it via pip or through
|
|
||||||
the plugin manager.
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
**TODO:** Describe your plugin's configuration options (if any).
|
|
||||||
|
@ -5,16 +5,22 @@ import threading
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import octoprint.plugin
|
import octoprint.plugin
|
||||||
|
from octoprint.events import Events
|
||||||
|
|
||||||
from .ftpsclient import IoTFTPSClient
|
from .ftpsclient import IoTFTPSClient
|
||||||
|
|
||||||
|
|
||||||
class BambuPrintPlugin(
|
class BambuPrintPlugin(octoprint.plugin.SettingsPlugin,
|
||||||
octoprint.plugin.SettingsPlugin, octoprint.plugin.TemplatePlugin
|
octoprint.plugin.TemplatePlugin,
|
||||||
):
|
octoprint.plugin.AssetPlugin,
|
||||||
|
octoprint.plugin.EventHandlerPlugin,
|
||||||
|
octoprint.plugin.SimpleApiPlugin):
|
||||||
|
|
||||||
|
|
||||||
|
def get_assets(self):
|
||||||
|
return {'js': ["js/bambu_printer.js"]}
|
||||||
def get_template_configs(self):
|
def get_template_configs(self):
|
||||||
return [{"type": "settings", "custom_bindings": False}]
|
return [{"type": "settings", "custom_bindings": True}] #, {"type": "generic", "custom_bindings": True, "template": "bambu_printer.jinja2"}]
|
||||||
|
|
||||||
def get_settings_defaults(self):
|
def get_settings_defaults(self):
|
||||||
return {"device_type": "X1C",
|
return {"device_type": "X1C",
|
||||||
@ -31,8 +37,27 @@ class BambuPrintPlugin(
|
|||||||
"local_mqtt": True,
|
"local_mqtt": True,
|
||||||
"region": "",
|
"region": "",
|
||||||
"email": "",
|
"email": "",
|
||||||
"auth_token": ""}
|
"auth_token": "",
|
||||||
|
"always_use_default_options": False
|
||||||
|
}
|
||||||
|
|
||||||
|
def is_api_adminonly(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_api_commands(self):
|
||||||
|
return {"register": ["email", "password", "region", "auth_token"]}
|
||||||
|
def on_api_command(self, command, data):
|
||||||
|
import flask
|
||||||
|
if command == "register":
|
||||||
|
if "email" in data and "password" in data and "region" in data and "auth_token" in data:
|
||||||
|
self._logger.info(f"Registering user {data['email']}")
|
||||||
|
from pybambu import BambuCloud
|
||||||
|
bambu_cloud = BambuCloud(data["region"], data["email"], data["password"], data["auth_token"])
|
||||||
|
bambu_cloud.login(data["region"], data["email"], data["password"])
|
||||||
|
return flask.jsonify({"auth_token": bambu_cloud.auth_token, "username": bambu_cloud.username})
|
||||||
|
def on_event(self, event, payload):
|
||||||
|
if event == Events.TRANSFER_DONE:
|
||||||
|
self._printer.commands("M20 L T", force=True)
|
||||||
def support_3mf_files(self):
|
def support_3mf_files(self):
|
||||||
return {'machinecode': {'3mf': ["3mf"]}}
|
return {'machinecode': {'3mf': ["3mf"]}}
|
||||||
|
|
||||||
@ -50,7 +75,7 @@ class BambuPrintPlugin(
|
|||||||
elapsed = time.monotonic() - elapsed
|
elapsed = time.monotonic() - elapsed
|
||||||
sd_upload_succeeded(filename, filename, elapsed)
|
sd_upload_succeeded(filename, filename, elapsed)
|
||||||
# remove local file after successful upload to Bambu
|
# remove local file after successful upload to Bambu
|
||||||
self._file_manager.remove_file("local", filename)
|
# self._file_manager.remove_file("local", filename)
|
||||||
else:
|
else:
|
||||||
raise Exception("upload failed")
|
raise Exception("upload failed")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -64,6 +89,9 @@ class BambuPrintPlugin(
|
|||||||
|
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
def get_template_vars(self):
|
||||||
|
return {"plugin_version": self._plugin_version}
|
||||||
|
|
||||||
def virtual_printer_factory(self, comm_instance, port, baudrate, read_timeout):
|
def virtual_printer_factory(self, comm_instance, port, baudrate, read_timeout):
|
||||||
if not port == "BAMBU":
|
if not port == "BAMBU":
|
||||||
return None
|
return None
|
||||||
|
@ -125,7 +125,7 @@ class IoTFTPSClient:
|
|||||||
with open(dest, "wb") as file:
|
with open(dest, "wb") as file:
|
||||||
self.ftps_session.retrbinary(f"RETR {source}", file.write)
|
self.ftps_session.retrbinary(f"RETR {source}", file.write)
|
||||||
|
|
||||||
def upload_file(self, source: str, dest: str, callback=None):
|
def upload_file(self, source: str, dest: str, callback=None) -> bool:
|
||||||
"""upload a file to a path inside the FTPS server"""
|
"""upload a file to a path inside the FTPS server"""
|
||||||
|
|
||||||
file_size = os.path.getsize(source)
|
file_size = os.path.getsize(source)
|
||||||
@ -133,43 +133,50 @@ class IoTFTPSClient:
|
|||||||
block_size = max(file_size // 100, 8192)
|
block_size = max(file_size // 100, 8192)
|
||||||
rest = None
|
rest = None
|
||||||
|
|
||||||
# Taken from ftplib.storbinary but with custom ssl handling
|
try:
|
||||||
# due to the shitty bambu p1p ftps server TODO fix properly.
|
# Taken from ftplib.storbinary but with custom ssl handling
|
||||||
with open(source, "rb") as fp:
|
# due to the shitty bambu p1p ftps server TODO fix properly.
|
||||||
self.ftps_session.voidcmd('TYPE I')
|
with open(source, "rb") as fp:
|
||||||
|
self.ftps_session.voidcmd('TYPE I')
|
||||||
|
|
||||||
with self.ftps_session.transfercmd(f"STOR {dest}", rest) as conn:
|
with self.ftps_session.transfercmd(f"STOR {dest}", rest) as conn:
|
||||||
while 1:
|
while 1:
|
||||||
buf = fp.read(block_size)
|
buf = fp.read(block_size)
|
||||||
|
|
||||||
if not buf:
|
if not buf:
|
||||||
break
|
break
|
||||||
|
|
||||||
conn.sendall(buf)
|
conn.sendall(buf)
|
||||||
|
|
||||||
if callback:
|
if callback:
|
||||||
callback(buf)
|
callback(buf)
|
||||||
|
|
||||||
# shutdown ssl layer
|
# shutdown ssl layer
|
||||||
if ftplib._SSLSocket is not None and isinstance(conn, ftplib._SSLSocket):
|
if ftplib._SSLSocket is not None and isinstance(conn, ftplib._SSLSocket):
|
||||||
# Yeah this is suposed to be conn.unwrap
|
# Yeah this is suposed to be conn.unwrap
|
||||||
# But since we operate in prot p mode
|
# But since we operate in prot p mode
|
||||||
# we can close the connection always.
|
# we can close the connection always.
|
||||||
# This is cursed but it works.
|
# This is cursed but it works.
|
||||||
if "vsFTPd" in self.welcome:
|
if "vsFTPd" in self.welcome:
|
||||||
conn.unwrap()
|
conn.unwrap()
|
||||||
else:
|
else:
|
||||||
conn.shutdown(socket.SHUT_RDWR)
|
conn.shutdown(socket.SHUT_RDWR)
|
||||||
|
|
||||||
return self.ftps_session.voidresp()
|
return True
|
||||||
|
except Exception as ex:
|
||||||
|
print(f"unexpected exception occurred: {ex}")
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
# Old api call.
|
def delete_file(self, path: str) -> bool:
|
||||||
# self.ftps_session.storbinary(
|
|
||||||
# f"STOR {dest}", file, blocksize=block_size, callback=callback)
|
|
||||||
|
|
||||||
def delete_file(self, path: str):
|
|
||||||
"""delete a file from under a path inside the FTPS server"""
|
"""delete a file from under a path inside the FTPS server"""
|
||||||
self.ftps_session.delete(path)
|
try:
|
||||||
|
self.ftps_session.delete(path)
|
||||||
|
return True
|
||||||
|
except Exception as ex:
|
||||||
|
print(f"unexpected exception occurred: {ex}")
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
def move_file(self, source: str, dest: str):
|
def move_file(self, source: str, dest: str):
|
||||||
"""move a file inside the FTPS server to another path inside the FTPS server"""
|
"""move a file inside the FTPS server to another path inside the FTPS server"""
|
||||||
|
@ -4,26 +4,89 @@
|
|||||||
* Author: jneilliii
|
* Author: jneilliii
|
||||||
* License: AGPLv3
|
* License: AGPLv3
|
||||||
*/
|
*/
|
||||||
$(function() {
|
|
||||||
|
$(function () {
|
||||||
function Bambu_printerViewModel(parameters) {
|
function Bambu_printerViewModel(parameters) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// assign the injected parameters, e.g.:
|
self.settingsViewModel = parameters[0];
|
||||||
// self.loginStateViewModel = parameters[0];
|
self.filesViewModel = parameters[1];
|
||||||
// self.settingsViewModel = parameters[1];
|
|
||||||
|
|
||||||
// TODO: Implement your plugin's view model here.
|
self.getAuthToken = function (data) {
|
||||||
|
self.settingsViewModel.settings.plugins.bambu_printer.auth_token("");
|
||||||
|
OctoPrint.simpleApiCommand("bambu_printer", "register", {
|
||||||
|
"email": self.settingsViewModel.settings.plugins.bambu_printer.email(),
|
||||||
|
"password": $("#bambu_cloud_password").val(),
|
||||||
|
"region": self.settingsViewModel.settings.plugins.bambu_printer.region(),
|
||||||
|
"auth_token": self.settingsViewModel.settings.plugins.bambu_printer.auth_token()
|
||||||
|
})
|
||||||
|
.done(function (response) {
|
||||||
|
console.log(response);
|
||||||
|
self.settingsViewModel.settings.plugins.bambu_printer.auth_token(response.auth_token);
|
||||||
|
self.settingsViewModel.settings.plugins.bambu_printer.username(response.username);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*$('#files div.upload-buttons > span.fileinput-button:first, #files div.folder-button').remove();
|
||||||
|
$('#files div.upload-buttons > span.fileinput-button:first').removeClass('span6').addClass('input-block-level');
|
||||||
|
|
||||||
|
self.onBeforePrintStart = function(start_print_command) {
|
||||||
|
let confirmation_html = '' +
|
||||||
|
' <div class="row-fluid form-vertical">\n' +
|
||||||
|
' <div class="control-group">\n' +
|
||||||
|
' <label class="control-label">' + gettext("Plate Number") + '</label>\n' +
|
||||||
|
' <div class="controls">\n' +
|
||||||
|
' <input type="number" min="1" value="1" id="bambu_printer_plate_number" class="input-mini">\n' +
|
||||||
|
' </div>\n' +
|
||||||
|
' </div>\n' +
|
||||||
|
' </div>';
|
||||||
|
|
||||||
|
if(!self.settingsViewModel.settings.plugins.bambu_printer.always_use_default_options()){
|
||||||
|
confirmation_html += '\n' +
|
||||||
|
' <div class="row-fluid">\n' +
|
||||||
|
' <div class="span6">\n' +
|
||||||
|
' <label class="checkbox"><input id="bambu_printer_timelapse" type="checkbox"' + ((self.settingsViewModel.settings.plugins.bambu_printer.timelapse()) ? ' checked' : '') + '> ' + gettext("Enable timelapse") + '</label>\n' +
|
||||||
|
' <label class="checkbox"><input id="bambu_printer_bed_leveling" type="checkbox"' + ((self.settingsViewModel.settings.plugins.bambu_printer.bed_leveling()) ? ' checked' : '') + '> ' + gettext("Enable bed leveling") + '</label>\n' +
|
||||||
|
' <label class="checkbox"><input id="bambu_printer_flow_cali" type="checkbox"' + ((self.settingsViewModel.settings.plugins.bambu_printer.flow_cali()) ? ' checked' : '') + '> ' + gettext("Enable flow calibration") + '</label>\n' +
|
||||||
|
' </div>\n' +
|
||||||
|
' <div class="span6">\n' +
|
||||||
|
' <label class="checkbox"><input id="bambu_printer_vibration_cali" type="checkbox"' + ((self.settingsViewModel.settings.plugins.bambu_printer.vibration_cali()) ? ' checked' : '') + '> ' + gettext("Enable vibration calibration") + '</label>\n' +
|
||||||
|
' <label class="checkbox"><input id="bambu_printer_layer_inspect" type="checkbox"' + ((self.settingsViewModel.settings.plugins.bambu_printer.layer_inspect()) ? ' checked' : '') + '> ' + gettext("Enable first layer inspection") + '</label>\n' +
|
||||||
|
' <label class="checkbox"><input id="bambu_printer_use_ams" type="checkbox"' + ((self.settingsViewModel.settings.plugins.bambu_printer.use_ams()) ? ' checked' : '') + '> ' + gettext("Use AMS") + '</label>\n' +
|
||||||
|
' </div>\n' +
|
||||||
|
' </div>\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
showConfirmationDialog({
|
||||||
|
title: "Bambu Print Options",
|
||||||
|
html: confirmation_html,
|
||||||
|
cancel: gettext("Cancel"),
|
||||||
|
proceed: [gettext("Print"), gettext("Always")],
|
||||||
|
onproceed: function (idx) {
|
||||||
|
if(idx === 1){
|
||||||
|
self.settingsViewModel.settings.plugins.bambu_printer.timelapse($('#bambu_printer_timelapse').is(':checked'));
|
||||||
|
self.settingsViewModel.settings.plugins.bambu_printer.bed_leveling($('#bambu_printer_bed_leveling').is(':checked'));
|
||||||
|
self.settingsViewModel.settings.plugins.bambu_printer.flow_cali($('#bambu_printer_flow_cali').is(':checked'));
|
||||||
|
self.settingsViewModel.settings.plugins.bambu_printer.vibration_cali($('#bambu_printer_vibration_cali').is(':checked'));
|
||||||
|
self.settingsViewModel.settings.plugins.bambu_printer.layer_inspect($('#bambu_printer_layer_inspect').is(':checked'));
|
||||||
|
self.settingsViewModel.settings.plugins.bambu_printer.use_ams($('#bambu_printer_use_ams').is(':checked'));
|
||||||
|
self.settingsViewModel.settings.plugins.bambu_printer.always_use_default_options(true);
|
||||||
|
self.settingsViewModel.saveData();
|
||||||
|
}
|
||||||
|
// replace this with our own print command API call?
|
||||||
|
start_print_command();
|
||||||
|
},
|
||||||
|
nofade: true
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
};*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/* view model class, parameters for constructor, container to bind to
|
|
||||||
* Please see http://docs.octoprint.org/en/master/plugins/viewmodels.html#registering-custom-viewmodels for more details
|
|
||||||
* and a full list of the available options.
|
|
||||||
*/
|
|
||||||
OCTOPRINT_VIEWMODELS.push({
|
OCTOPRINT_VIEWMODELS.push({
|
||||||
construct: Bambu_printerViewModel,
|
construct: Bambu_printerViewModel,
|
||||||
// ViewModels your plugin depends on, e.g. loginStateViewModel, settingsViewModel, ...
|
// ViewModels your plugin depends on, e.g. loginStateViewModel, settingsViewModel, ...
|
||||||
dependencies: [ /* "loginStateViewModel", "settingsViewModel" */ ],
|
dependencies: ["settingsViewModel", "filesViewModel"],
|
||||||
// Elements to bind to, e.g. #settings_plugin_bambu_printer, #tab_plugin_bambu_printer, ...
|
// Elements to bind to, e.g. #settings_plugin_bambu_printer, #tab_plugin_bambu_printer, ...
|
||||||
elements: [ /* ... */ ]
|
elements: ["#bambu_printer_print_options", "#settings_plugin_bambu_printer"]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,40 +1,78 @@
|
|||||||
<h3>Virtual Printer</h3>
|
<h3>Bambu Printer Settings <small>{{ _('Version') }} {{ plugin_bambu_printer_plugin_version }}</small></h3>
|
||||||
|
|
||||||
<form class="form-horizontal" onsubmit="return false;">
|
<form class="form-horizontal" onsubmit="return false;">
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">{{ _('Device Type') }}</label>
|
<label class="control-label">{{ _('Device Type') }}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<select class="input-block-level" data-bind="options: ['A1', 'A1MINI', 'P1P', 'P1S', 'X1', 'X1C'], value: settings.plugins.bambu_printer.device_type, allowUnset: true">
|
<select class="input-block-level" data-bind="options: ['A1', 'A1MINI', 'P1P', 'P1S', 'X1', 'X1C'], value: settingsViewModel.settings.plugins.bambu_printer.device_type, allowUnset: true">
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">{{ _('IP Address') }}</label>
|
<label class="control-label">{{ _('IP Address') }}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<input type="text" class="input-block-level" data-bind="value: settings.plugins.bambu_printer.host" placeholder="192.168.0.2" title="{{ _('IP address or hostname of the printer') }}"></input>
|
<input type="text" class="input-block-level" data-bind="value: settingsViewModel.settings.plugins.bambu_printer.host" placeholder="192.168.0.2" title="{{ _('IP address or hostname of the printer') }}"></input>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">{{ _('Serial Number') }}</label>
|
<label class="control-label">{{ _('Serial Number') }}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<input type="text" class="input-block-level" data-bind="value: settings.plugins.bambu_printer.serial" title="{{ _('Serial number of printer') }}"></input>
|
<input type="text" class="input-block-level" data-bind="value: settingsViewModel.settings.plugins.bambu_printer.serial" title="{{ _('Serial number of printer') }}"></input>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">{{ _('Access Code') }}</label>
|
<label class="control-label">{{ _('Access Code') }}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<input type="text" class="input-block-level" data-bind="value: settings.plugins.bambu_printer.access_code" title="{{ _('Access code of printer') }}"></input>
|
<input type="text" class="input-block-level" data-bind="value: settingsViewModel.settings.plugins.bambu_printer.access_code" title="{{ _('Access code of printer') }}"></input>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<div class="controls">
|
||||||
|
<label class="checkbox"><input type="checkbox" data-bind="checked: settingsViewModel.settings.plugins.bambu_printer.local_mqtt"> {{ _('Use Local Access, disable for cloud connection') }}</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group" data-bind="visible: !settingsViewModel.settings.plugins.bambu_printer.local_mqtt()">
|
||||||
|
<label class="control-label">{{ _('Region') }}</label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="text" class="input-block-level" data-bind="value: settingsViewModel.settings.plugins.bambu_printer.region" title="{{ _('Region used to connect, ie China, US') }}"></input>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group" data-bind="visible: !settingsViewModel.settings.plugins.bambu_printer.local_mqtt()">
|
||||||
|
<label class="control-label">{{ _('Email') }}</label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="text" class="input-block-level" data-bind="value: settingsViewModel.settings.plugins.bambu_printer.email" title="{{ _('Registered email address') }}"></input>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group" data-bind="visible: !settingsViewModel.settings.plugins.bambu_printer.local_mqtt()">
|
||||||
|
<label class="control-label">{{ _('Password') }}</label>
|
||||||
|
<div class="controls">
|
||||||
|
<div class="input-block-level input-append">
|
||||||
|
<input id="bambu_cloud_password" type="password" class="input-text input-block-level" title="{{ _('Password to generate Auth Token') }}"></input>
|
||||||
|
<span class="btn btn-primary add-on" data-bind="click: getAuthToken">{{ _('Login') }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group" data-bind="visible: !settingsViewModel.settings.plugins.bambu_printer.local_mqtt()">
|
||||||
|
<label class="control-label">{{ _('Auth Token') }}</label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="text" class="input-block-level" data-bind="value: settingsViewModel.settings.plugins.bambu_printer.auth_token" title="{{ _('Auth Token') }}"></input>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">{{ _('Print Options') }}</label>
|
<label class="control-label">{{ _('Default Print Options') }}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<label class="checkbox"><input type="checkbox" data-bind="checked: settings.plugins.bambu_printer.timelapse"> {{ _('Enable timelapse') }}</label>
|
<label class="checkbox"><input type="checkbox" data-bind="checked: settingsViewModel.settings.plugins.bambu_printer.timelapse"> {{ _('Enable timelapse') }}</label>
|
||||||
<label class="checkbox"><input type="checkbox" data-bind="checked: settings.plugins.bambu_printer.bed_leveling"> {{ _('Enable bed leveling') }}</label>
|
<label class="checkbox"><input type="checkbox" data-bind="checked: settingsViewModel.settings.plugins.bambu_printer.bed_leveling"> {{ _('Enable bed leveling') }}</label>
|
||||||
<label class="checkbox"><input type="checkbox" data-bind="checked: settings.plugins.bambu_printer.flow_cali"> {{ _('Enable flow calibration') }}</label>
|
<label class="checkbox"><input type="checkbox" data-bind="checked: settingsViewModel.settings.plugins.bambu_printer.flow_cali"> {{ _('Enable flow calibration') }}</label>
|
||||||
<label class="checkbox"><input type="checkbox" data-bind="checked: settings.plugins.bambu_printer.vibration_cali"> {{ _('Enable vibration calibration') }}</label>
|
<label class="checkbox"><input type="checkbox" data-bind="checked: settingsViewModel.settings.plugins.bambu_printer.vibration_cali"> {{ _('Enable vibration calibration') }}</label>
|
||||||
<label class="checkbox"><input type="checkbox" data-bind="checked: settings.plugins.bambu_printer.layer_inspect"> {{ _('Enable first layer inspection') }}</label>
|
<label class="checkbox"><input type="checkbox" data-bind="checked: settingsViewModel.settings.plugins.bambu_printer.layer_inspect"> {{ _('Enable first layer inspection') }}</label>
|
||||||
<label class="checkbox"><input type="checkbox" data-bind="checked: settings.plugins.bambu_printer.use_ams"> {{ _('Use AMS') }}</label>
|
<label class="checkbox"><input type="checkbox" data-bind="checked: settingsViewModel.settings.plugins.bambu_printer.use_ams"> {{ _('Use AMS') }}</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{#<div class="control-group">
|
||||||
|
<label class="control-label">{{ _('Always Use Default') }}</label>
|
||||||
|
<div class="controls">
|
||||||
|
<label class="checkbox"><input type="checkbox" data-bind="checked: settings.plugins.bambu_printer.always_use_default_options"> </label>
|
||||||
|
</div>
|
||||||
|
</div>#}
|
||||||
</form>
|
</form>
|
||||||
|
@ -68,8 +68,10 @@ class BambuPrinter:
|
|||||||
self._sdCardReady = True
|
self._sdCardReady = True
|
||||||
self._sdPrinter = None
|
self._sdPrinter = None
|
||||||
self._sdPrinting = False
|
self._sdPrinting = False
|
||||||
|
self._sdPrintStarting = False
|
||||||
self._sdPrintingSemaphore = threading.Event()
|
self._sdPrintingSemaphore = threading.Event()
|
||||||
self._sdPrintingPausedSemaphore = threading.Event()
|
self._sdPrintingPausedSemaphore = threading.Event()
|
||||||
|
self._sdFileListCache = {}
|
||||||
self._selectedSdFile = None
|
self._selectedSdFile = None
|
||||||
self._selectedSdFileSize = 0
|
self._selectedSdFileSize = 0
|
||||||
self._selectedSdFilePos = 0
|
self._selectedSdFilePos = 0
|
||||||
@ -78,6 +80,7 @@ class BambuPrinter:
|
|||||||
self._busy_loop = None
|
self._busy_loop = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
self._logger = logging.getLogger(
|
self._logger = logging.getLogger(
|
||||||
@ -157,20 +160,28 @@ class BambuPrinter:
|
|||||||
fans = device_data.fans.__dict__
|
fans = device_data.fans.__dict__
|
||||||
speed = device_data.speed.__dict__
|
speed = device_data.speed.__dict__
|
||||||
|
|
||||||
|
# self._logger.debug(device_data)
|
||||||
|
|
||||||
self.temp[0] = temperatures.get("nozzle_temp", 0.0)
|
self.temp[0] = temperatures.get("nozzle_temp", 0.0)
|
||||||
self.targetTemp[0] = temperatures.get("target_nozzle_temp", 0.0)
|
self.targetTemp[0] = temperatures.get("target_nozzle_temp", 0.0)
|
||||||
self.bedTemp = temperatures.get("bed_temp", 0.0)
|
self.bedTemp = temperatures.get("bed_temp", 0.0)
|
||||||
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 print_job.get("gcode_state") == "RUNNING":
|
if print_job.get("gcode_state") == "RUNNING" or print_job.get("gcode_state") == "PREPARE":
|
||||||
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()
|
||||||
|
self._sdPrintStarting = False
|
||||||
if not self._sdPrinting:
|
if not self._sdPrinting:
|
||||||
filename = print_job.get("subtask_name")
|
filename = print_job.get("subtask_name")
|
||||||
# TODO: swap this out to use 8 dot 3 name based on long name/path
|
if not self._sdFileListCache.get(filename.lower()):
|
||||||
|
if self._sdFileListCache.get(f"{filename.lower()}.3mf"):
|
||||||
|
filename = f"{filename.lower()}.3mf"
|
||||||
|
elif self._sdFileListCache.get(f"{filename.lower()}.gcode.3mf"):
|
||||||
|
filename = f"{filename.lower()}.gcode.3mf"
|
||||||
|
|
||||||
self._selectSdFile(filename)
|
self._selectSdFile(filename)
|
||||||
self._startSdPrint(from_printer=True)
|
self._startSdPrint(from_printer=True)
|
||||||
|
|
||||||
@ -185,9 +196,12 @@ class BambuPrinter:
|
|||||||
self._send("// action:paused")
|
self._send("// action:paused")
|
||||||
self._sendPaused()
|
self._sendPaused()
|
||||||
|
|
||||||
if print_job.get("gcode_state") == "FINISH" and self._sdPrintingSemaphore.is_set():
|
if print_job.get("gcode_state") == "FINISH" or print_job.get("gcode_state") == "FAILED":
|
||||||
self._selectedSdFilePos = self._selectedSdFileSize
|
if self._sdPrintStarting is False:
|
||||||
self._finishSdPrint()
|
self._sdPrinting = False
|
||||||
|
if self._sdPrintingSemaphore.is_set():
|
||||||
|
self._selectedSdFilePos = self._selectedSdFileSize
|
||||||
|
self._finishSdPrint()
|
||||||
def _create_connection(self):
|
def _create_connection(self):
|
||||||
if (self._settings.get(["device_type"]) != "" and
|
if (self._settings.get(["device_type"]) != "" and
|
||||||
self._settings.get(["serial"]) != "" and
|
self._settings.get(["serial"]) != "" and
|
||||||
@ -197,24 +211,26 @@ class BambuPrinter:
|
|||||||
):
|
):
|
||||||
asyncio.run(self._create_connection_async())
|
asyncio.run(self._create_connection_async())
|
||||||
|
|
||||||
|
def on_disconnect(self, on_disconnect):
|
||||||
|
self._logger.debug(f"on disconnect called")
|
||||||
|
return on_disconnect
|
||||||
|
|
||||||
async def _create_connection_async(self):
|
async def _create_connection_async(self):
|
||||||
|
self._logger.debug(f"connecting via local mqtt: {self._settings.get_boolean(['local_mqtt'])}")
|
||||||
self.bambu = BambuClient(device_type=self._settings.get(["device_type"]),
|
self.bambu = BambuClient(device_type=self._settings.get(["device_type"]),
|
||||||
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="bblp" if self._settings.get_boolean(["local_mqtt"]) else 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"]),
|
local_mqtt=self._settings.get_boolean(["local_mqtt"]),
|
||||||
region=self._settings.get(["region"]),
|
region=self._settings.get(["region"]),
|
||||||
email=self._settings.get(["email"]),
|
email=self._settings.get(["email"]),
|
||||||
auth_token=self._settings.get(["auth_token"])
|
auth_token=self._settings.get(["auth_token"])
|
||||||
)
|
)
|
||||||
|
self.bambu.on_disconnect = self.on_disconnect(self.bambu.on_disconnect)
|
||||||
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:
|
|
||||||
# await asyncio.sleep(self.tick_rate)
|
|
||||||
# self._processTemperatureQuery()
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "BAMBU(read_timeout={read_timeout},write_timeout={write_timeout},options={options})".format(
|
return "BAMBU(read_timeout={read_timeout},write_timeout={write_timeout},options={options})".format(
|
||||||
@ -241,6 +257,7 @@ class BambuPrinter:
|
|||||||
|
|
||||||
self._sdCardReady = True
|
self._sdCardReady = True
|
||||||
self._sdPrinting = False
|
self._sdPrinting = False
|
||||||
|
self._sdPrintStarting = False
|
||||||
if self._sdPrinter:
|
if self._sdPrinter:
|
||||||
self._sdPrinting = False
|
self._sdPrinting = False
|
||||||
self._sdPrintingSemaphore.clear()
|
self._sdPrintingSemaphore.clear()
|
||||||
@ -429,6 +446,14 @@ class BambuPrinter:
|
|||||||
else:
|
else:
|
||||||
self._sendOk()
|
self._sendOk()
|
||||||
|
|
||||||
|
if self.bambu.connected:
|
||||||
|
GCODE_COMMAND = commands.SEND_GCODE_TEMPLATE
|
||||||
|
GCODE_COMMAND['print']['param'] = data + "\n"
|
||||||
|
if self.bambu.publish(GCODE_COMMAND):
|
||||||
|
self._logger.info("command sent successfully")
|
||||||
|
self._sendOk()
|
||||||
|
continue
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
self._logger.debug(f"{data}")
|
self._logger.debug(f"{data}")
|
||||||
|
|
||||||
@ -474,13 +499,18 @@ class BambuPrinter:
|
|||||||
|
|
||||||
def _gcode_M524(self, data: str) -> bool:
|
def _gcode_M524(self, data: str) -> bool:
|
||||||
if self._sdCardReady:
|
if self._sdCardReady:
|
||||||
self._cancelSdPrint()
|
return self._cancelSdPrint()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _gcode_M26(self, data: str) -> bool:
|
def _gcode_M26(self, data: str) -> bool:
|
||||||
self._logger.debug("ignoring M26 command.")
|
if data == "M26 S0":
|
||||||
self._send("M26 disabled for Bambu")
|
if self._sdCardReady:
|
||||||
return True
|
return self._cancelSdPrint()
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
self._logger.debug("ignoring M26 command.")
|
||||||
|
self._send("M26 disabled for Bambu")
|
||||||
|
return True
|
||||||
|
|
||||||
def _gcode_M27(self, data: str) -> bool:
|
def _gcode_M27(self, data: str) -> bool:
|
||||||
def report():
|
def report():
|
||||||
@ -509,8 +539,8 @@ class BambuPrinter:
|
|||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
def _gcode_M29(self, data: str) -> bool:
|
def _gcode_M29(self, data: str) -> bool:
|
||||||
self._logger.debug("ignoring M28 command.")
|
self._logger.debug("ignoring M29 command.")
|
||||||
self._send("M28 disabled for Bambu")
|
self._send("M29 disabled for Bambu")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _gcode_M30(self, data: str) -> bool:
|
def _gcode_M30(self, data: str) -> bool:
|
||||||
@ -625,7 +655,7 @@ class BambuPrinter:
|
|||||||
access_code = self._settings.get(["access_code"])
|
access_code = self._settings.get(["access_code"])
|
||||||
|
|
||||||
ftp = IoTFTPSClient(f"{host}", 990, "bblp", f"{access_code}", ssl_implicit=True)
|
ftp = IoTFTPSClient(f"{host}", 990, "bblp", f"{access_code}", ssl_implicit=True)
|
||||||
filelist = ftp.list_files("", ".3mf")
|
filelist = ftp.list_files("", ".3mf") or []
|
||||||
|
|
||||||
for entry in filelist:
|
for entry in filelist:
|
||||||
if entry.startswith("/"):
|
if entry.startswith("/"):
|
||||||
@ -643,30 +673,57 @@ class BambuPrinter:
|
|||||||
"size": filesize,
|
"size": filesize,
|
||||||
"timestamp": unix_timestamp_to_m20_timestamp(int(filedate))
|
"timestamp": unix_timestamp_to_m20_timestamp(int(filedate))
|
||||||
}
|
}
|
||||||
result[filename.lower()] = data
|
|
||||||
result[dosname.lower()] = filename.lower()
|
result[dosname.lower()] = filename.lower()
|
||||||
|
result[filename.lower()] = data
|
||||||
|
|
||||||
|
filelistcache = ftp.list_files("cache/", ".3mf") or []
|
||||||
|
|
||||||
|
for entry in filelistcache:
|
||||||
|
if entry.startswith("/"):
|
||||||
|
filename = entry[1:].replace("cache/", "")
|
||||||
|
else:
|
||||||
|
filename = entry.replace("cache/", "")
|
||||||
|
filesize = ftp.ftps_session.size(f"cache/{filename}")
|
||||||
|
date_str = ftp.ftps_session.sendcmd(f"MDTM cache/{filename}").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()
|
||||||
|
data = {
|
||||||
|
"dosname": dosname,
|
||||||
|
"name": filename,
|
||||||
|
"path": "cache/"+filename,
|
||||||
|
"size": filesize,
|
||||||
|
"timestamp": unix_timestamp_to_m20_timestamp(int(filedate))
|
||||||
|
}
|
||||||
|
result[dosname.lower()] = filename.lower()
|
||||||
|
result[filename.lower()] = data
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _getSdFileData(self, filename: str) -> Optional[Dict[str, Any]]:
|
def _getSdFileData(self, filename: str) -> Optional[Dict[str, Any]]:
|
||||||
files = self._mappedSdList()
|
self._logger.debug(f"_getSdFileData: {filename}")
|
||||||
data = files.get(filename.lower())
|
data = self._sdFileListCache.get(filename.lower())
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
data = files.get(data.lower())
|
data = self._sdFileListCache.get(data.lower())
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _getSdFiles(self) -> List[Dict[str, Any]]:
|
def _getSdFiles(self) -> List[Dict[str, Any]]:
|
||||||
files = self._mappedSdList()
|
self._sdFileListCache = self._mappedSdList()
|
||||||
return [x for x in files.values() if isinstance(x, dict)]
|
self._logger.debug(f"_getSdFiles return: {self._sdFileListCache}")
|
||||||
|
return [x for x in self._sdFileListCache.values() if isinstance(x, dict)]
|
||||||
|
|
||||||
def _selectSdFile(self, filename: str, check_already_open: bool = False) -> None:
|
def _selectSdFile(self, filename: str, check_already_open: bool = False) -> None:
|
||||||
|
self._logger.debug(f"_selectSdFile: {filename}, check_already_open={check_already_open}")
|
||||||
if filename.startswith("/"):
|
if filename.startswith("/"):
|
||||||
filename = filename[1:]
|
filename = filename[1:]
|
||||||
|
|
||||||
file = self._getSdFileData(filename)
|
file = self._getSdFileData(filename)
|
||||||
if file is None:
|
if file is None:
|
||||||
self._send(f"{filename} open failed")
|
self._listSd(incl_long=True, incl_timestamp=True)
|
||||||
return
|
self._sendOk()
|
||||||
|
file = self._getSdFileData(filename)
|
||||||
|
if file is None:
|
||||||
|
self._send(f"{filename} open failed")
|
||||||
|
return
|
||||||
|
|
||||||
if self._selectedSdFile == file["path"] and check_already_open:
|
if self._selectedSdFile == file["path"] and check_already_open:
|
||||||
return
|
return
|
||||||
@ -677,9 +734,11 @@ class BambuPrinter:
|
|||||||
self._send("File selected")
|
self._send("File selected")
|
||||||
|
|
||||||
def _startSdPrint(self, from_printer: bool = False) -> None:
|
def _startSdPrint(self, from_printer: bool = False) -> None:
|
||||||
|
self._logger.debug(f"_startSdPrint: from_printer={from_printer}")
|
||||||
if self._selectedSdFile is not None:
|
if self._selectedSdFile is not None:
|
||||||
if self._sdPrinter is None:
|
if self._sdPrinter is None:
|
||||||
self._sdPrinting = True
|
self._sdPrinting = True
|
||||||
|
self._sdPrintStarting = True
|
||||||
self._sdPrinter = threading.Thread(target=self._sdPrintingWorker, kwargs={"from_printer": from_printer})
|
self._sdPrinter = threading.Thread(target=self._sdPrintingWorker, kwargs={"from_printer": from_printer})
|
||||||
self._sdPrinter.start()
|
self._sdPrinter.start()
|
||||||
# self._sdPrintingSemaphore.set()
|
# self._sdPrintingSemaphore.set()
|
||||||
@ -699,18 +758,21 @@ class BambuPrinter:
|
|||||||
else:
|
else:
|
||||||
self._logger.info("print pause failed")
|
self._logger.info("print pause failed")
|
||||||
|
|
||||||
def _cancelSdPrint(self):
|
def _cancelSdPrint(self) -> bool:
|
||||||
if self.bambu.connected:
|
if self.bambu.connected:
|
||||||
if self.bambu.publish(commands.STOP):
|
if self.bambu.publish(commands.STOP):
|
||||||
self._logger.info("print cancelled")
|
self._logger.info("print cancelled")
|
||||||
|
self._finishSdPrint()
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
self._logger.info("print cancel failed")
|
self._logger.info("print cancel failed")
|
||||||
|
return False
|
||||||
|
|
||||||
def _setSdPos(self, pos):
|
def _setSdPos(self, pos):
|
||||||
self._newSdFilePos = pos
|
self._newSdFilePos = pos
|
||||||
|
|
||||||
def _reportSdStatus(self):
|
def _reportSdStatus(self):
|
||||||
if self._sdPrinter is not None and (self._sdPrintingSemaphore.is_set() or self._sdPrintingPausedSemaphore.is_set()):
|
if ( self._sdPrinter is not None or self._sdPrintStarting is True ) and self._selectedSdFileSize > 0:
|
||||||
self._send(f"SD printing byte {self._selectedSdFilePos}/{self._selectedSdFileSize}")
|
self._send(f"SD printing byte {self._selectedSdFilePos}/{self._selectedSdFileSize}")
|
||||||
else:
|
else:
|
||||||
self._send("Not SD printing")
|
self._send("Not SD printing")
|
||||||
@ -764,7 +826,13 @@ class BambuPrinter:
|
|||||||
print_command = {"print": {"sequence_id": 0,
|
print_command = {"print": {"sequence_id": 0,
|
||||||
"command": "project_file",
|
"command": "project_file",
|
||||||
"param": "Metadata/plate_1.gcode",
|
"param": "Metadata/plate_1.gcode",
|
||||||
|
"md5": "",
|
||||||
|
"profile_id": "0",
|
||||||
|
"project_id": "0",
|
||||||
|
"subtask_id": "0",
|
||||||
|
"task_id": "0",
|
||||||
"subtask_name": f"{self._selectedSdFile}",
|
"subtask_name": f"{self._selectedSdFile}",
|
||||||
|
"file": f"{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}",
|
"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"]),
|
||||||
@ -799,6 +867,7 @@ class BambuPrinter:
|
|||||||
self._selectedSdFilePos = 0
|
self._selectedSdFilePos = 0
|
||||||
self._selectedSdFileSize = 0
|
self._selectedSdFileSize = 0
|
||||||
self._sdPrinting = False
|
self._sdPrinting = False
|
||||||
|
self._sdPrintStarting = False
|
||||||
self._sdPrinter = None
|
self._sdPrinter = None
|
||||||
|
|
||||||
def _deleteSdFile(self, filename: str) -> None:
|
def _deleteSdFile(self, filename: str) -> None:
|
||||||
@ -811,7 +880,7 @@ class BambuPrinter:
|
|||||||
if file is not None:
|
if file is not None:
|
||||||
ftp = IoTFTPSClient(f"{host}", 990, "bblp", f"{access_code}", ssl_implicit=True)
|
ftp = IoTFTPSClient(f"{host}", 990, "bblp", f"{access_code}", ssl_implicit=True)
|
||||||
try:
|
try:
|
||||||
if ftp.delete_file(filename):
|
if ftp.delete_file(file["path"]):
|
||||||
self._logger.debug(f"{filename} deleted")
|
self._logger.debug(f"{filename} deleted")
|
||||||
else:
|
else:
|
||||||
raise Exception("delete failed")
|
raise Exception("delete failed")
|
||||||
|
2
setup.py
2
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.7"
|
plugin_version = "0.0.18"
|
||||||
|
|
||||||
# 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
|
||||||
|
Reference in New Issue
Block a user