I was trying to write a script that sends the M119 command to the 3d printer terminal and polls so as not to: filament: open, otherwise it pauses printing with the M0 or M25 command.
And I almost succeeded. My script is located in the Ubuntu root folder, but when I run it, the M119 command is output to the terminal, but when it tries to poll the port, "garbage" characters are output to it and communication with the serial port is interrupted on my local website.
What did you already try to solve it?
I tried changing the bitrate and do it manually.
Additional information about your setup
OctoPrint version, OctoPi version, printer, firmware, browser, operating system, ... as much data as possible
I am using octoprint deploy and the latest version of octoprint itself. My server is running on an orange pi zero 2w. Operating system: Ubuntu. My 3d printer is creality ender 3 S1. I can't use klipper because it has a laser module that only works on the original or professional printer firmware.
You really won't be able to share the serial port with OctoPrint. Seems to me that the right way to do this is in a PlugIn.
Is your script a stand alone script that runs outside the context of OctoPrint or is it a PlugIn.
Can you update your firmware to have HOST_ACTION_COMMANDS enabled? This would solve your problem and you would not need to have a polling script.
You could also connect your filament sensor to an IO point on your pi and use a plugin to monitor that. There are a few out there that are setup for that.
this would be the best way to go because that's the point of filament sensor being connected to the printer's main board in the first place.
100% agree and could be done in a single file plugin that implements a RepeatedTimer on print start event using EventHandler mixin and octoprint.comm.protocol.gcode.received hook to process M119 responses. Might not even need the event handler/sending of command if you just add the command to layer change gcode of the slicer, or possibly just use the bundled event manager plugin to send the command with ZChange event.
If you're referring to mriscoc professional firmware, pretty sure it has host_action_commands enabled, but I think you need to make sure that you've set OctoPrint's settings properly for things to work right.
I went ahead and threw this together and it pauses the print in OctoPrint when the line filament: TRIGGERED is detected coming from the printer. Using this in addition to the event manager setting mentioned earlier should in theory achieve what you are after I suspect. You can install directly in plugin manager by copying/pasting the URL into Plugin Manager > Get More > ...from URL and clicking install
I would still look into the mriscoc in-built host_action_commands and try to figure out why they aren't working, because it is listed as a feature, specifically for filament runout support as described here.
I can confirm that the MRISCOC host action commands work with a filament sensor (I'm using a BTT smart filament sensor). After enabling the filament sensor it you have to figure out if you have to set it to high, low or the third which I don't remember off the top of my head.