Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Print doesn't automatically start after printer turns on #207

Closed
chriscla opened this issue Sep 2, 2020 · 12 comments · Fixed by #220
Closed

[BUG]: Print doesn't automatically start after printer turns on #207

chriscla opened this issue Sep 2, 2020 · 12 comments · Fixed by #220
Labels
bug Something isn't working solved workaround documented or fix applied
Milestone

Comments

@chriscla
Copy link

chriscla commented Sep 2, 2020

I'm expecting this plugin to turn on the Printer and then start a print when uploading from PrusaSlicer. The printer will turn on using this plugin but the print won't automatically start.

To Reproduce
Steps to reproduce the behavior:
0. Printer is off.

  1. In PrusaSlicer, press the Send to Printer button and select "Start printing after upload"
  2. Printer turns on but doesn't start printing

Expected behavior
The printer turns on, waits the Auto-Connect duration and then starts printing.

Screenshots
Sending my config:

image

image

Desktop (please complete the following information):

  • OS: windows
  • Browser chrome
  • OctoPrint Version 1.4.2
  • Plugin Version 0.9.24

Additional context
This may be how it's expected to work or I messed up the config. Thanks for creating this plugin!

@jneilliii
Copy link
Owner

Your settings do look correct, and your assumption is correct that is how it is intended to work. It does work that way for me, so to debug your issue I'll need you to enable debug logging, restart octoprint and put the plug into a powered off state, therefore turning your printer off. Then send the file from PrusaSlicer with that option enabled to auto start the print and the printer should power on, octoprint should then auto connect, and once the connection is established the file should be automatically selected and start printing. If it doesn't then I'll need to get your plugin_tplinksmartplug_debug.log file from OctoPrint's logging section.

@jneilliii
Copy link
Owner

One clarification, when you say OS: windows, do you mean that's what octoprint is installed on or the machine that you're accessing octoprint from?

@chriscla
Copy link
Author

chriscla commented Sep 2, 2020

Octoprint is running on a Raspberry Pi 4 using the Octopi setup. I set this up a few days ago. Attached are the logs. I'm new at deciphering this but I think that it's timing out trying to negotiate the serial connection.

plugin_tplinksmartplug_debug (2).log
octoprint (1).log

@jneilliii
Copy link
Owner

Try manually setting your port and baud rate with the option save settings and connect to octoprint while it's powered on instead of using Auto. That way when the power on occurs and it tries to connect it will know what port to send the connect command. You may consider increasing the autoconnect delay too just in case the printer is not fully on after 20 seconds.

@chriscla
Copy link
Author

chriscla commented Sep 2, 2020

Yep, that helped. I disabled "automatically connect to printer on startup" and ensured the baud rate was correct. So now, the printer turns on and it becomes operational. It still doesn't start printing.
Updated logs:
octoprint (3).log
plugin_tplinksmartplug_debug (4).log

The file does appear in the upload queue

@chriscla
Copy link
Author

chriscla commented Sep 2, 2020

I think I figured it out (I have it working now by modifying the plugin source):

After turning on the plug, the plugin starts a timer for connection

if plug["autoConnect"] and self._printer.is_closed_or_error():
c = threading.Timer(int(plug["autoConnectDelay"]), self._printer.connect)
c.daemon = True
c.start()

This method returns with whether the plugged turned on. There is then a sleep that sleeps for the autoConnectDelay + 1. It then checks if the printer is ready before kicking off the print:

time.sleep(int(plug.get("autoConnectDelay", "0")) + 1)
if self._printer.is_ready() != False:
self._tplinksmartplug_logger.debug(
"printer connected starting print of %s" % (payload.get("path", "")))
self._printer.select_file(payload.get("path"), False, printAfterSelect=True)

I think it's failing because the connect method hasn't completed and the printer is not yet ready. I hacked this by adding 10 seconds to the sleep. I'm new to Octoprint so not sure the best way to fix this. I could see:

  1. Adding a configurable connecting sleep.
  2. Checking the state_id and seeing if the state is "connecting"
  3. Add a signal so that the timer can signal to the main thread that the connect happened.

edited: updated formatting

@jneilliii
Copy link
Owner

Yeah, it would make sense to increase that sleep value, or potentially switched the logic to something like the below. I'll do some additional testing on this approach.

While True:
    if not self._printer.is_ready():
        return True
    self._printer.select_file(payload.get("path"), False, printAfterSelect=True)

@jneilliii jneilliii added the bug Something isn't working label Sep 3, 2020
@jneilliii
Copy link
Owner

So I've changed the logic to how the auto start happens and moved it to the connected event in the above commit, This way we're not clogging up anything in a busy while loop. Will be included as part of the next release. If you want to test it out for me you can copy/paste the URL below into plugin manager > get more> ...from URL and click Install. The version will still show 0.9.24 as I tend to keep that at current release version until I'm done with additional fixes.

https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/archive/0.9.25.zip

@jneilliii jneilliii added the solved workaround documented or fix applied label Sep 3, 2020
@jneilliii jneilliii added this to the 0.9.25 milestone Sep 3, 2020
@chriscla
Copy link
Author

chriscla commented Sep 8, 2020

Just installed the new version and uploading from Prusaslicer started it and the print started automatically after the machine turned on. I'll do some more testing and report back if there are issues but "no news is good news". Thanks for working on this and making the plugin :)

@chriscla
Copy link
Author

Hey, I need to do more testing but I think that if I turn the printer on using the "lightning bolt" in Octopi, then it will start printing the last print that was uploaded. I'll do some more testing.

@jneilliii
Copy link
Owner

So with that latest dev version linked above I wonder if you just increase your automatic connect time to 30 seconds if it makes a difference or not here? Sorry haven't had a chance to really dig into this yet.

@narfotic
Copy link

Yes, it works! Thanks

@jneilliii jneilliii mentioned this issue Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working solved workaround documented or fix applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants