Octoprint-Filament-Reloaded
Octoprint-Filament-Reloaded copied to clipboard
added feature for sending GCODE only once.
Made some changes to address an issue that has been reported a few times here. I picked one of the issues (issue 22) as the name of the branch. This has been referred to as a "looping" problem in other posts. It basically allows the user to configure witch a checkbox if they want to old classic behaviour of resending the GCODE or if they want to send it only once. The way this is accomplished is by simply unhooking the callback when the filament is out and then rehooking it again when they resume.
Omg this it's really needed. I actually stopped using this pluggin because of this behavior. This bug forced me to learn how to find and configure a free pin in Marlin. Modify and upload firmware and then wire a endstop as a filament sensor. Harder but at least I know how now.
If you are interested, I can make the changes available to you (two files to replace in your octoprint deployment) so you can test it out. Let me know and I can make that happen.
@DrWatson Yes please. I still have one printer(Taz6) that I haven't hard wired a filament sensor to. I'd love to try it this weekend.
Please read this whole message. If anything in here is not at your comfort level, then I suggest you not proceed. If you do choose to proceed, you do this at your own risk, of course. I will help if I can...just post here.
You will need two files. The first is the _ _ init _ _.py which you can find here: https://github.com/DrWatson/Octoprint-Filament-Reloaded/tree/issue22/octoprint_filamentreload
The second file is the filamentreload_settings.jinja2 which you can find here: https://github.com/DrWatson/Octoprint-Filament-Reloaded/tree/issue22/octoprint_filamentreload/templates
Making some assumptions about your octoprint deployment, here, but you should back up both of these files. I will assume that you know how to ssh and get to the folders where these files are. Mine are located here: /home/pi/oprint/lib/python2.7/site-packages/octoprint_filamentreload/init.py and here /home/pi/oprint/lib/python2.7/site-packages/octoprint_filamentreload/templates/filamentreload_settings.jinja2
After you have backed up the original files and replaced them with the two above, you should restart octoprint by running:
sudo service octoprint restart
For me, I am using the reload filament command of M600 to help in the reloading process when I get a filament run out. To do this, I have set mine up using these steps:
-
Go into the settings for the plugin and change the GCODE entry to something like this: M600 X40 Y40 Z10 E2 L10
-
Place a check in "Pause print when out of filament".
-
Place a check in "Send GCODE only once when out of filament."
Remember that you need to have M600 enabled in your firmware. It's not on by default in Marlin 1.1.* Here is a video for how to do it: https://www.youtube.com/watch?v=CDz2IxxINBE
The process will now be that when the filament is out, the M600 command is called once and Octoprint pauses the print. The M600 command will lift the head, park it, and allow for refilling of filament. You control these steps from the LCD on the printer. (Yes M600 in marlin is only operational using the LCD panel.) Once the filament is loaded and you've finished the steps on the LCD, you go over to OctoPrint and resume the print. The head will go back to the position it left off at when the filament ran out and resume the print.
Let me know if you have any questions.
Thanks for the detailed instructions. I haven't touched my Taz6 for months. But I'll dust her off to try this, this weekend. Its clear you have a thorough understanding of Marlin from your write up. I shouldn't have any trouble getting your changes live with those excellent instructions. One change I'll make on my own because I dislike the behavior of after a filament change is complete having to hit "continue print" on lcd screen and then also having to hit "resume print" in Octoprint. So I leave pause print unchecked in the pluggin - That way print resumes right after I hit continue on lcd without having to also hit resume in Octoprint. Because I leave pause print unchecked in pluggin, as soon as M600 is complete, nozzle unparks and resumes. I also I have my custom park position defined in Marlin, so I dont define it in Octoprint pluggin - just a standard M600. Both are just my personal preference. The main thing is I hope this fixs the loop that currently happens.
Leaving the pause print unchecked won't be a solution for you, I fear. Let me explain.
The way the plugin works is that it registers for an event from the Pi GPIO interface. It gets a steady flow of events from this interface regardless of pin change. This is why in the logs you get a message a few times each second that reports "Filament detected!". This is the root cause of the looping behaviour in sending GCODE.
To fix this problem, when the new "Send GCODE only once when out of filament." configuration item is checked, I unregister the callback so the plugin doesn't get any events from the GPIO interface. When you resume the print, it reregisters the callback and the GPIO events begin to flow again.
So if you don't use the pause functionality of the plugin, you won't need to resume the print in Octoprint, however, you will no longer get the GPIO events. In this way, you will only get the out of filament handling once. If you run out of filament again subsequently in the same print, you will not get the event because it hasn't reregistered for the event because resume was never called.
Hope that makes sense.
I don't know if I can get an event into the plugin when the M600 is complete. If I do, then code could be added there to reregister for the GPIO event, but I didn't think of that at the time or writing. Perhaps that's something else for me to look at this weekend or next week.
Ok I'll test for the loop behavior fix anyway. And then report back either tonight or tomorrow.
As for hitting resume in Octoprint and continue in lcd, I understand your explanation. B4 I knew you could just uncheck pause print during filament change. I ran into a situation where I had completed the filament change with LCD, the printer unparked nozzle and returned to print location but then froze waiting for instructions from host(Octoprint). So that can lead to nozzle melting model until user hits resume button in Octoprint. Ofc the way around was to hit resume in Octoprint 1st, then continue print on LCD. I just liked dealing with LCD only by unchecking don't pause....but I won't now 😔
@DrWatson Got my Taz6 dusted off. Updated printers firmware, updated cura software, updated pi3, updated Octoprint and varies pluggins. Backed up: init.py filamentreload_settings.jinja2 Replaced with versions downloaded from the links above. Reloaded Octoprint, but then restarted whole pi3.
I dont see option to "Place a check in "Send GCODE only once when out of filament." in the plggin window
Your versions size init.py is 84,368 compared to old @ 5,292 Your versions size ............settings.jinja2 is 60,228 compared to old @ 2,894 all same file permissions
Couldnt test as I cant get it to install properly?? suggestions?
Those file sizes do not look close at all to what is in my repo. I have downloaded the files from the repo and included them here. Please use these files instead and see if you get different results.
Ok i used the files from the download above. When I do so, the Filament Sensor Reloaded (1.0.1) doesn't show up in the pluggins section on the right where all pluggins are listed and you can alter their parameters. 1st I did a restart of Octoprint. Then I did a complete reboot.
It does show up in the main plug in manager as being installed, however. Reverting to stock and rebooting fixes the issues of it not showing up on the left under pluggins, but then im stock cant test.
That's strange. Those are the exact files I am running. If the plug in fails to load, there will be an error in /home/pi/.octoprint/logs/octoprint.log . If you could put the files from the zip file back in place and restart octoprint again, then paste here what the log says after the restart.
I changed very little for this fix, so I'm surprised it's being difficult.
ok my logging level is set to debug:
13:50:47,401 - octoprint.startup - INFO - ******************************************************************************
2018-06-11 13:50:47,401 - octoprint.startup - INFO - Starting OctoPrint 1.3.8
2018-06-11 13:50:47,402 - octoprint.startup - INFO - ******************************************************************************
2018-06-11 13:50:47,467 - octoprint.util.connectivity_checker - INFO - Connectivity changed from offline to online
2018-06-11 13:50:48,091 - octoprint.startup - INFO - Blacklist processing done
2018-06-11 13:50:48,170 - octoprint.plugin.core - INFO - Loading plugins from /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins, /home/pi/.octoprint/plugins and installed plugin packages...
2018-06-11 13:50:51,501 - octoprint.plugin.core - INFO - Found 21 plugin(s) providing 21 mixin implementations, 13 hook handlers
2018-06-11 13:50:51,632 - octoprint.server.heartbeat - INFO - Starting server heartbeat, 900.0s interval
2018-06-11 13:50:51,677 - octoprint.server - INFO - Intermediary server started
2018-06-11 13:50:51,678 - octoprint.plugin.core - INFO - Loading plugins from /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins, /home/pi/.octoprint/plugins and installed plugin packages...
2018-06-11 13:50:51,974 - octoprint.plugin.core - INFO - Found 21 plugin(s) providing 21 mixin implementations, 13 hook handlers
2018-06-11 13:50:52,011 - octoprint.filemanager.storage - INFO - Initializing the file metadata for /home/pi/.octoprint/uploads...
2018-06-11 13:50:52,779 - octoprint.filemanager.storage - INFO - ... file metadata for /home/pi/.octoprint/uploads initialized successfully.
2018-06-11 13:50:52,811 - octoprint.plugins.filamentreload - INFO - Running RPi.GPIO version '0.6.3'
2018-06-11 13:50:53,007 - octoprint.plugins.softwareupdate - INFO - Loaded version cache from disk
2018-06-11 13:51:03,483 - octoprint.util.pip - INFO - Using "/home/pi/oprint/bin/python -m pip" as command to invoke pip
2018-06-11 13:51:05,864 - octoprint.util.pip - INFO - Version of pip is 9.0.1
2018-06-11 13:51:05,865 - octoprint.util.pip - INFO - pip installs to /home/pi/oprint/lib/python2.7/site-packages (writable -> yes), --user flag needed -> no, virtual env -> yes
2018-06-11 13:51:05,865 - octoprint.util.pip - INFO - ==> pip ok -> yes
2018-06-11 13:51:05,870 - octoprint.plugin.core - INFO - Initialized 21 plugin implementation(s)
2018-06-11 13:51:05,882 - octoprint.plugin.core - INFO - 21 plugin(s) registered with the system:
| Announcement Plugin (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/announcements
| Core Wizard (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/corewizard
| CuraEngine (<= 15.04) (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/cura
| Discovery (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/discovery
| DisplayZ (0.1.0) = /home/pi/oprint/local/lib/python2.7/site-packages/octoprint_displayz
| EEPROM Marlin Editor Plugin (1.2.1) = /home/pi/oprint/local/lib/python2.7/site-packages/octoprint_eeprom_marlin
| Filament Sensor Reloaded (1.0.1) = /home/pi/oprint/local/lib/python2.7/site-packages/octoprint_filamentreload
| Fullscreen Plugin (0.0.4) = /home/pi/oprint/local/lib/python2.7/site-packages/octoprint_fullscreen
| GcodeEditor (0.1.1) = /home/pi/oprint/local/lib/python2.7/site-packages/octoprint_GcodeEditor
| HeaterTimeout (0.0.1) = /home/pi/oprint/local/lib/python2.7/site-packages/octoprint_HeaterTimeout
| Logging (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/logging
| Navbar Temperature Plugin (0.9) = /home/pi/oprint/local/lib/python2.7/site-packages/octoprint_navbartemp
| OctoPi Support Plugin (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/octopi_support
| OctoPrint Anywhere (0.6.3) = /home/pi/oprint/local/lib/python2.7/site-packages/octoprint_anywhere
| Plugin Manager (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/pluginmanager
| Preheat Button (0.2.0) = /home/pi/oprint/local/lib/python2.7/site-packages/octoprint_preheat
| Printer Safety Check (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/printer_safety_check
| Pushbullet (0.1.9) = /home/pi/oprint/local/lib/python2.7/site-packages/octoprint_octobullet
| Software Update (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/softwareupdate
| Themeify (1.2.0) = /home/pi/oprint/local/lib/python2.7/site-packages/octoprint_themeify
| Virtual Printer (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/virtual_printer
2018-06-11 13:51:05,899 - octoprint.environment - INFO - Detected environment is Python 2.7.9 under Linux (linux2). Details:
| hardware:
| cores: 4
| freq: 1200.0
| ram: 918323200
| os:
| id: linux
| platform: linux2
| plugins:
| octopi_support:
| model: 3B
| revision: a02082
| version: 0.14.0
| python:
| pip: 9.0.1
| version: 2.7.9
| virtualenv: /home/pi/oprint
2018-06-11 13:51:05,911 - octoprint.server - INFO - Reset webasset folder /home/pi/.octoprint/generated/webassets...
2018-06-11 13:51:05,936 - octoprint.server - INFO - Reset webasset folder /home/pi/.octoprint/generated/.webassets-cache...
2018-06-11 13:51:05,947 - octoprint.server.util.flask.collect_plugin_assets - WARNING - Plugin GcodeEditor is referring to non existing css asset css/GcodeEditor.css
2018-06-11 13:51:06,200 - octoprint.server - INFO - Shutting down intermediary server...
2018-06-11 13:51:06,465 - octoprint.server - INFO - Intermediary server shut down
2018-06-11 13:51:06,467 - octoprint.events - INFO - Processing startup event, this is our first event
2018-06-11 13:51:06,468 - octoprint.events - INFO - Adding 1 events to queue that were held back before startup event
2018-06-11 13:51:06,475 - octoprint.filemanager - INFO - Adding backlog items from all storage types to analysis queue...
2018-06-11 13:51:06,503 - octoprint.plugins.pluginmanager - INFO - Loaded plugin repository data from disk, was still valid
2018-06-11 13:51:06,518 - octoprint.filemanager - INFO - Added 0 items from storage type "local" to analysis queue
2018-06-11 13:51:06,712 - octoprint.plugins.pluginmanager - INFO - Loaded notice data from disk, was still valid
2018-06-11 13:51:07,014 - octoprint.plugins.discovery - INFO - Registered OctoPrint instance "Taz 6" for _http._tcp
2018-06-11 13:51:07,024 - octoprint.plugins.discovery - INFO - Registered OctoPrint instance "Taz 6" for _octoprint._tcp
2018-06-11 13:51:07,028 - octoprint.plugins.discovery - INFO - Registered OctoPrint instance "Taz 6" for SSDP
2018-06-11 13:51:07,028 - octoprint.server - INFO - Listening on http://127.0.0.1:5000
2018-06-11 13:51:07,050 - octoprint.plugins.HeaterTimeout - INFO - Starting up...
2018-06-11 13:51:07,188 - octoprint.plugins.anywhere - WARNING - Not connected to server ws or connection lost
2018-06-11 13:51:07,197 - octoprint.plugins.filamentreload - INFO - Filament Sensor Reloaded started
2018-06-11 13:51:07,199 - octoprint.plugins.filamentreload - INFO - Setting up sensor.
2018-06-11 13:51:07,265 - octoprint.plugins.filamentreload - INFO - Using Board Mode
2018-06-11 13:51:07,266 - octoprint.plugins.filamentreload - INFO - Filament Sensor active on GPIO Pin [7]
2018-06-11 13:51:07,280 - octoprint.server.util.sockjs - INFO - New connection from client: 127.0.0.1
2018-06-11 13:51:07,285 - octoprint.plugins.anywhere - WARNING - Not connected to server ws or connection lost
2018-06-11 13:51:07,306 - octoprint.plugins.anywhere - WARNING - Not connected to server ws or connection lost
2018-06-11 13:51:08,506 - octoprint.server.util.sockjs - INFO - New connection from client: 192.168.1.181
2018-06-11 13:51:08,833 - octoprint.plugins.octobullet - INFO - Connected to PushBullet
2018-06-11 13:51:08,877 - octoprint.plugins.pluginmanager - INFO - Loaded plugin repository data from disk, was still valid
2018-06-11 13:51:08,970 - octoprint.plugins.pluginmanager - INFO - Loaded notice data from disk, was still valid
2018-06-11 13:51:08,985 - octoprint.server.preemptive_cache - INFO - Preemptively caching / (ui _default) for {'query_string': 'l10n=en', 'path': '/', 'base_url': 'http://192.168.1.7/'}
2018-06-11 13:51:20,513 - octoprint.server.preemptive_cache - INFO - ... done in 11.53s
2018-06-11 13:51:25,974 - octoprint.util.comm - INFO - Changing monitoring state from "Offline" to "Detecting serial port"
2018-06-11 13:51:26,076 - octoprint.util.comm - INFO - Changing monitoring state from "Detecting serial port" to "Opening serial port"
2018-06-11 13:51:26,079 - octoprint.util.comm - INFO - Changing monitoring state from "Opening serial port" to "Connecting"
2018-06-11 13:51:26,086 - octoprint.util.comm - INFO - M110 detected, setting current line number to 0
2018-06-11 13:51:35,277 - octoprint.util.comm - INFO - M110 detected, setting current line number to 0
2018-06-11 13:51:40,971 - octoprint.util.comm - INFO - Changing monitoring state from "Connecting" to "Operational"
2018-06-11 13:51:40,979 - octoprint.util.comm - INFO - M110 detected, setting current line number to 0
2018-06-11 13:51:41,051 - octoprint.util.comm - INFO - Printer reports firmware name "Marlin"
2018-06-11 13:51:41,062 - octoprint.util.comm - INFO - Firmware states that it supports temperature autoreporting
2018-06-11 13:51:41,124 - octoprint.util.comm - INFO - Firmware states that it supports temperature autoreporting
Deleted the pluggin. Reinstalled. renamed old upload new
Now I get pluggin showing up in master pluggin list and on left where I can edit parameters. However I dont see the new "only send once check box"
type:
cd /home/pi/oprint/lib/python2.7/site-packages
then type:
grep -r -i "send gcode" *
post the results here.
pi@octopi:~/oprint/lib/python2.7/site-packages $ grep -r -i "send gcode" * octoprint_filamentreload/templates/filamentreload_settings.jinja2: {{ _('Send GCODE only once when out of filament.') }}
Something still isn't right. There should be more files that contain that pattern. At least two:
- octoprint_filamentreload/templates/filamentreload_settings.jinja2
- octoprint_filamentreload/_ _ init _ _.py
Let's try this from scratch again...this time a little more thorough. (Sorry about this.)
Unzip the zip file in this message and place the filamentreload_settings.jinja2 file that it in the templates folder (octoprint_filamentreload/templates/filamentreload_settings.jinja2)
Place the _ _ init _ _.py in the folder one up from the templates folder (octoprint_filamentreload/).
In the octoprint_filamentreload/ folder, please delete the _ _ init _ _.pyc file. This is a compiled version of the file and will be rebuilt when needed. Perhaps something is being cached.
Reboot the Pi.
When you go to your web browser and navigate to the settings page for the filament reload configuration, press Shift+Reload (I will assume chrome, don't know what force reload would be in whatever browser you're using) to make sure you are not being served a cached copy of the page.
Ah oh ok. I never deleted the .pyc At work today, I'll try it tonight... Report back
I haven't had to delete the pyc before, but I'm thinking it's more likely a browser cache thing. The new files in the zip are the actual files I am running on my Pi (which are slightly different than the ones in the repo.) Just curious. Were you replacing the files in the two different directories? ie octoprint_filamentreload/templates/ and octoprint_filamentreload/_ _ init _ _.py? What is the whole path for the files you are replacing? Mine is in: /home/pi/oprint/lib/python2.7/site-packages/octoprint_filamentreload.
Yes my path was the same as yours. I renamed originals as ......old, in both folders. Then uploaded your versions.
Success - I can see the new "Send GCODE only once when out of filament" in the pluggin window. Deleted old versions and deleted the compiled pyc. Used the versions in 2.zip
I can now test filament changes for loop behavior, :)
Awesome! Let me know how the testing goes.
Did a little testing last night. At first I thought it didnt work. When I cut filament, printer kept on printing. Thought it was something on my end. So I double checked the pin assignment and the state of sensor, normally open, normally closed.
Then I decided to tail the output of log in real time...... From turning printer on and reboot of Octoprint. Did test again monitoring the log output. Cut filament. No trigger filament change, even in log. So since filament was already cut off from the spool at this point, I just pulled sensor pass cut end again, then it triggered. And it triggered only once, no looping behavior.
So from scratch again. Printer powered off. Octoprint restarted. No trigger 1st out of filament. 2nd out of filament detected. No loop.
Great, so this solution works for you? Call it a success?
No loop behavior for filament changes - success.
For me 1st filament outage undetected. Not good. This weekend I can test more.
Just re-read your messages again and realized I missed the part about it not working the first time. I don't know why that would be. Would be interesting to see if that happens with the plugin without my modifications. If so, then we can rule out the changes I made as being the culprit and tackle it differently. If you find that it misses the first out of filament trigger again and you determine it's not some kind of problem with the printer or detector somehow, then let me know and we can try and troubleshoot together.
@DrWatson I dont know if your around. But I should be available for the next 10 hours or so. I have troubleshooted as best I can. With your new code - no loop when changing filament ie printer doesn't initiate another filament change. However I cant get it to trigger the 1st filament outage, only 2 or 3 etc.....
Without your new code, stock filament reload pluggin - I change filament - printer gets stuck in a loop if you happen to trigger the runout sensor during a filament change - creating a loop. However stock pluggin is always able to trigger/catch a filament runout condition.
I followed suggestions here and deleted the .pyc and replaced everything. It worked once. Now anytime the sensor is triggered, I receive the following in a webpage and have to completely restart the Octoprint.
The OctoPrint server is currently not running If you just started up your Raspberry Pi, please wait a couple of seconds, then try to refresh this page.
If the issue persists, please log into your Raspberry Pi via SSH and check the following:
Verify that the process is running: ps -ef | grep -i octoprint | grep -i python should show a python process: pi@octopi:~ $ ps -ef | grep -i octoprint | grep -i python pi 1441 1 6 11:12 ? 00:00:15 /home/pi/oprint/bin/python /home/pi/oprint/bin/octoprint --host=127.0.0.1 --port=5000 If it isn't, the question is why. Take a look into ~/.octoprint/logs/octoprint.log, there might be an error logged in there that helps to determine what's wrong. You might also want to try if you can restart the server (if no obvious error is visible): sudo service octoprint restart. If all that doesn't help to trouble shoot the issue, you can seek support on the OctoPrint Mailinglist or in the OctoPrint G+ Community. Please provide your OctoPi and OctoPrint versions, your octoprint.log (in form of a pastebin link) and explain what you already tried and observed as detailed as possible.
The gcode I am using is as follows: M104 S0 ;turn extruder heater off G91 ;change the printer into relative movement mode G1 Z10 ;move the head up 10mm G90 ;put printer back in absolute movement mode
Also I have the "pause Print" and "Send GCode only once" checked.
Looks like octoprint is crashing. Can you remove the gcode you have entered in the text box and try again ? We need to narrow down what is causing the issue. Did any of this work prior to substituting the new files?
@mylife4aiurr
I will take a look this weekend as to why you don't get the first trigger.
It did work stock. I believe it works with just the pause print checked and no gcode but I will have to test it further and get back to you.