hi,
I want to write a plugin to mimic sd card functions for prusa printers via prusaLink. The prusaLink part isn't hard.
I already have code to catch e.g. M20 (via queuing hook). What's missing for my first results is how to put my results in the received queue.
For me and the Bambu plugin I'm able to do it through the serial factory I've added to the plugin to handle all serial communication back and forth. If you're not doing it all and just intercepting the M20 command you would have to call the internal comm layer received command I suspect. Something that uses the comm_instance parameter of the gcode queing callback, which is an instance of the MachineCom class. Seems like it might be difficult to do.
The other option, which I don't know if Prusa supports, is the use of M118 command, which basically tells the printer to send me back this line. So your hook captures queuing, grabs the file list, and then expands the command being sent to include a bunch of M118 commands with the file data lines appended.
M118 seams to work. nice idea! I want to replace the other not/not well supported SD commands.
I see I can control octoprint with that: "M118 A1 action:cancel" fancy
I looked already in the comm module and also find it hard to use for my purpose.
Cool, so yeah that should work. In your gcode queueing hook, instead of returning line, you would return a list of M118 commands. Simple example (untested)...
def prusa_list(self, comm_instance, phase, cmd, cmd_type, gcode, subcode=None, tags=None *args, **kwargs):
if gcode != "M20":
return
# code to get list of files and generate return data, ie dosname, date, size, unix timestamp, long filename
file_list_commands = ["Begin file list"]
for file in files:
# dosname size timestamp "filename"
file_list_commands .append(f"M118 {dosname } {size} {timestamp} \"{filename}\"")
file_list_commands.append("End file list")
return file_list_commands
__plugin_hooks__ = {
"octoprint.comm.protocol.gcode.queuing": prusa_list
}
you may also have to use the received phase gcode hook to manipulate how the printer sends the information (ie, remove "echo: " from the string possibly)
a meta-comment just to say "thanks". I'm not in this topic, but want to say in general that the world is a better place because of folks who help each other. I think you know that, and I don't think you are doing this just so that you get these "thanks", But it is important, so : kudos....
That is all
Hi, @jneilliii thx for the answer. Main difference as I understand is that you have a complete printer plugin and I only a plugin that tries to modify the standard printer behaviour throug hooks and tricks.
This is my first plugin in octoprint and I'm feeling not ready for making a complete new printer class, albeit it might be better in the end.
My plugin shows files on sd card with long filenames and times (currently not the size of a file). I can load the file (with no analyze of the file) and delete a file. Also sd upload is possible.
I wasn't able to set capabilities, because i can't hook in the capability readout (with complete printer plugin as yours this is easy).
Currently I work on starting the print from sd card.
Any clue how I can hook in the analyze stuff so I can provide more informations of the file?
For the record, when the 1.11.0 release candidate phase is not keeping me busy, I'm currently working on finally getting rid of the tech debt that is having the SD card stuff not be its own storage, and implementing that properly. Which also means capability flags on the storage interface whether files can also be read vs just written, which in turn should enable gcode analysis and the gcode viewer if talking to a printer that actually has a proper file management interface vs just a write-only storage (which basically is what the standard SD card related GCODEs boil down to).
That will be in 1.12.0, and my currently hope is that I'll be able to push this out faster than the past minor releases. But that all depends on the other stuff that comes up.
I was fighting some OctoPrint serial print issues on my MK4 without any success. Whenever I print via OctoPrint it does weird things, but works totally fine on USB Stick and currently using PrusaLink and was thinking the whole time about "why not just connect it via OctoPrint".
Looking forward to this, would help me tremendously <3
Would love to contribute / test whenever I have some free time.
Any chance to have this on a public repo already?
Next week I can publish the code - but this is more like a concept rather than a daily driver. Anyway I use it daily and it has it's limitations currently, but this is great to check why this plugin is a useful idea.
Currently I wait for octo 1.12 because I need changes in SD card stuff so I can simulate this without so much quirks.
you should see your files on printers usb stick and you can start the print - as long the printer accepts the gcode without warning (nozzle size/filament type)
when you upload a file to octo it is uploaded to the printers memory too.
will give some more infos in some days ...
and remember, this code is just a hacky proof of concept!
the prusa buddy github has lots of outstanding features regarding serial support+sd card. From time to (long) time they add missing gcode commands. so I hope for movement on prusa side - this would make this plugin much easier. Perhaps you should upvote&comment those issues, if you havn't already
you don't have to set this in init.py, you can just add it to config.yaml either via octoprint CLI commands or manually with nano. I'm not sure how the plugin_identifier is extracted when not defined, but typically that is handled in the setup.py that seems to be missing from your repo.
plugins:
<plugin_identifier>:
host="your host ip",
username="your user name",
password="your password"
I see you started a settings jinja template that has settings.plugins.prusalink.url, which doesn't match up to any of your default settings and you're probably getting binding errors on initial page load, but you can add those same blocks for these settings if you want, although you should probably encode the password in some way so it's not stored in plain text. Same as above, you need to replace <plugin_identiier>.