emtrax-ltd / Cura2MoonrakerPlugin

Ultimaker Cura 2 Mooraker Upload Plugin
GNU General Public License v3.0
289 stars 25 forks source link

Uploading fails if klipper not running #81

Closed wollew closed 4 months ago

wollew commented 9 months ago

Uploading files to moonraker fails if the printer/klipper is not connected: 2023-12-25 12:14:48,961 - DEBUG - [MainThread] UM.TaskManagement.HttpRequestManager._onRequestError [369]: request[31c2ee3f][get][PyQt6.QtCore.QUrl('http://192.168.1.22:7125/printer/info')][timeout=None][no-data] got an QNetworkReplyError Error transferring http://192.168.1.22:7125/printer/info - server replied: Klippy Host not connected. The server returned: b'{"error": {"code": 503, "message": "Klippy Host not connected", "traceback": "Traceback (most recent call last):\\n\\n File \\"/home/pi/moonraker/moonraker/app.py\\", line 641, in _process_http_request\\n result = await self.api_defintion.request(\\n\\n File \\"/home/pi/moonraker/moonraker/klippy_connection.py\\", line 558, in request\\n raise ServerError(\\"Klippy Host not connected\\", 503)\\n\\nmoonraker.utils.ServerError: Klippy Host not connected\\n\\n\\nThe above exception was the direct cause of the following exception:\\n\\n\\nTraceback (most recent call last):\\n\\n File \\"/home/pi/moonraker-env/lib/python3.9/site-packages/tornado/web.py\\", line 1713, in _execute\\n result = await result\\n\\n File \\"/home/pi/moonraker/moonraker/app.py\\", line 624, in get\\n await self._process_http_request(RequestType.GET)\\n\\n File \\"/home/pi/moonraker/moonraker/app.py\\", line 645, in _process_http_request\\n raise tornado.web.HTTPError(\\n\\ntornado.web.HTTPError: HTTP 503: Klippy Host not connected\\n"}}'

My printer is not usually turned on all the time but I would still like to be able to slice and upload files to moonraker. This works through the Mainsail/moonraker web frontend, but the Cura plugin fails because it requests /printer/info which (correctly) responds with 503 because printing would not be possible. I know I could configure moonraker's power device in the plugin which then fixes things but I don't really see why my printer needs to be turned on just to upload files.

scabana commented 9 months ago

I got the same kind of problem. I believe those lines of code https://github.com/emtrax-ltd/Cura2MoonrakerPlugin/blob/8faac6255e49c50646f1b8b3eb1d9f6547719a73/MoonrakerConnection/MoonrakerOutputDevice.py#L262-L266 are the issue. I have setup:

[file_manager]
queue_gcode_uploads: True

[job_queue]
load_on_startup: True

in moonraker.conf + on_when_job_queued: True on a power device. I believe that if the current status check would be removed, the printer would power up. After having issues, I re-configured in the extension here the power devices, but I'd rather disable the check in the plugin and let klipper's config do the power on of the printer and not have the power on config in 2 places. I guess a checkbox of some kind near the power devices option to disable the check would be the right thing to do.

emtrax-ltd commented 8 months ago

If the printer is off, deselect the "Start print job" option in the upload dialog. Job queuing is not yet supported by the plugin.

wollew commented 8 months ago

I am almost 100% positive that I hadn't selected "Start print job" but uploading did not work anyway. Currently the printer is on (and printing), I'll try again once it's done and turned off.

scabana commented 8 months ago

@emtrax-ltd , it's not as simple as I said (remove the check) because of how the code is laid out. I'm far from a python pro but I did clone the repo and pointed the plugin to it and with those two changes:

image

and

image

(remember, big hack to get the code invoked ;))

The plugin did trigger the print with the printer being offline. The gcode file was queued and my power devices (setup in moonraker) did turn on and the print did start.

@wollew, reading your description again, I think it's not the exact same scenario as the one I explained.

wollew commented 8 months ago

Ok, I tried again, "Start print job" was definitely not selected, this was the result: screencapture_20240105-090755

(don't get confused by the "octoprint" host name, no octoprint running there.)

emtrax-ltd commented 8 months ago

Try this branch: https://github.com/emtrax-ltd/Cura2MoonrakerPlugin/tree/pwrdevfix - there are many changes in MoonrakerOutputDevice.py now.

scabana commented 8 months ago

Tried it and got

2024-01-05 11:49:59,835 - DEBUG - [MainThread] MoonrakerConnection.MoonrakerOutputDevice._onUploadFilenameAccepted [238]: FileName set to CE3PRO_(Unsaved).ufp.
2024-01-05 11:49:59,836 - DEBUG - [MainThread] MoonrakerConnection.MoonrakerOutputDevice._onUploadFilenameAccepted [250]: StartPrint set to False.
2024-01-05 11:49:59,836 - INFO - [MainThread] MoonrakerConnection.MoonrakerOutputDevice._onUploadFilenameAccepted [254]: Connecting to Moonraker at http://raspberrypi/.
2024-01-05 11:50:00,088 - DEBUG - [MainThread] cura.Machines.Models.IntentSelectionModel._update [74]: Updating IntentSelectionModel.
2024-01-05 11:50:00,089 - DEBUG - [MainThread] cura.Machines.Models.IntentSelectionModel._update [74]: Updating IntentSelectionModel.
2024-01-05 11:50:00,092 - DEBUG - [MainThread] cura.Machines.Models.IntentSelectionModel._update [74]: Updating IntentSelectionModel.
2024-01-05 11:50:00,192 - DEBUG - [MainThread] cura.Machines.Models.CustomQualityProfilesDropDownMenuModel._update [33]: Updating CustomQualityProfilesDropDownMenuModel.
2024-01-05 11:50:00,857 - INFO - [MainThread] SliceInfoPlugin.SliceInfo._onRequestFinished [315]: SliceInfo sent successfully
2024-01-05 11:50:14,265 - DEBUG - [MainThread] UM.TaskManagement.HttpRequestManager._onRequestError [369]: request[48138c8b][get][PyQt6.QtCore.QUrl('http://raspberrypi/printer/info')][timeout=None][no-data] got an QNetworkReplyError Connection refused. The server returned: b''
2024-01-05 11:50:22,945 - DEBUG - [MainThread] UM.TaskManagement.HttpRequestManager._onRequestError [369]: request[56c45194][get][PyQt6.QtCore.QUrl('http://raspberrypi/printer/info')][timeout=None][no-data] got an QNetworkReplyError Connection refused. The server returned: b''
2024-01-05 11:50:35,208 - DEBUG - [MainThread] UM.TaskManagement.HttpRequestManager._onRequestError [369]: request[b8d73a8e][get][PyQt6.QtCore.QUrl('http://raspberrypi/printer/info')][timeout=None][no-data] got an QNetworkReplyError Connection refused. The server returned: b''
2024-01-05 11:50:43,950 - DEBUG - [MainThread] UM.TaskManagement.HttpRequestManager._onRequestError [369]: request[54355a73][get][PyQt6.QtCore.QUrl('http://raspberrypi/printer/info')][timeout=None][no-data] got an QNetworkReplyError Connection refused. The server returned: b''

Without automatic print job

And

2024-01-05 11:51:10,645 - INFO - [MainThread] MoonrakerConnection.MoonrakerOutputDevice._onUploadFilenameAccepted [254]: Connecting to Moonraker at http://raspberrypi/.
2024-01-05 11:51:11,679 - INFO - [MainThread] SliceInfoPlugin.SliceInfo._onRequestFinished [315]: SliceInfo sent successfully
2024-01-05 11:51:15,990 - DEBUG - [MainThread] cura.AutoSave._onTimeout [64]: Autosaving preferences, instances and profiles took 0.015272140502929688 seconds
2024-01-05 11:51:21,340 - ERROR - [MainThread] MoonrakerConnection.MoonrakerOutputDevice._onError [444]: 'The status of the printer is \'shutdown\'.\n\nLost communication with MCU \'mcu\'\nOnce the underlying issue is corrected, use the\n"FIRMWARE_RESTART" command to reset the firmware, reload the\nconfig, and restart the host software.\nPrinter is shutdown'
2024-01-05 11:51:21,341 - DEBUG - [MainThread] MoonrakerConnection.MoonrakerOutputDevice._resetState [201]: Reset state of device.

With automatic print job.

In both cases it doesn't seem to work. I'm unavailable for the next week but when I'm back, I'll try to open a PR with something that fixes both cases.

scabana commented 8 months ago

Wait, upload without print did work.

emtrax-ltd commented 8 months ago

Wait, upload without print did work.

Important: the “Start print job” option in the upload dialog requires either an active printer or a named power device that activates the printer. In your configuration it only works without "Start print job" because no power device has been named - the Moonraker option "queue_gcode_uploads: True" ensures that a print job is created and, if desired, the option "on_when_job_queued: True" for the power device ensures that the printer is activated by creating the job.

wollew commented 8 months ago

I tried the branch, but uploading still fails:

Uploading to Moonraker at http://octoprint.at.home:7125/ was not successful.

The status of the printer is 'error'.

mcu 'mcu': Unable to connect
Once the underlying issue is corrected, use the
"FIRMWARE_RESTART" command to reset the firmware, reload the
config, and restart the host software.
Error configuring printer - Unknown error

No exceptions in the log file.

emtrax-ltd commented 8 months ago

I tried the branch, but uploading still fails:

Uploading to Moonraker at http://octoprint.at.home:7125/ was not successful.

The status of the printer is 'error'.

mcu 'mcu': Unable to connect
Once the underlying issue is corrected, use the
"FIRMWARE_RESTART" command to reset the firmware, reload the
config, and restart the host software.
Error configuring printer - Unknown error

No exceptions in the log file.

it looks like the upload implies a "start print job". Do you use the upload dialog or the "fire & forget" mode?

wollew commented 8 months ago

Do you use the upload dialog or the "fire & forget" mode?

I am using the upload dialog, "Start print job" is unchecked.

emtrax-ltd commented 8 months ago

Do you use the upload dialog or the "fire & forget" mode?

I am using the upload dialog, "Start print job" is unchecked.

For further investigation of this problem the cura.log is required

wollew commented 8 months ago

Sorry for taking a little bit longer, this morning I tried again, interesting enough I got a different error message:

Uploading to Moonraker at http://octoprint.at.home:7125/ was not successful.

NetworkError.ServiceUnavailableError - Error transferring http://octoprint.at.home:7125/printer/info - server replied: Klippy Host not connected

Relevant part of the cura.log is attached.

wollew commented 4 months ago

Unfortunately this does not work for me, /printer/info returns 503 if the printer is not turned on and so we end up in the else branch in _checkPrinterStatus. I can try to create a PR if you're interested.

emtrax-ltd commented 4 months ago

Uploading to Moonraker at http://octoprint.at.home:7125/ was not successful.

NetworkError.ServiceUnavailableError - Error transferring http://octoprint.at.home:7125/printer/info - server replied: Klippy Host not connected

It fails because the Klipper service is not active/started on the Pi. This service should actually be active all the time, even if the printer itself is not switched on or the printer's MCU/board is without power.

wollew commented 4 months ago

Uploading to Moonraker at http://octoprint.at.home:7125/ was not successful. NetworkError.ServiceUnavailableError - Error transferring http://octoprint.at.home:7125/printer/info - server replied: Klippy Host not connected

It fails because the Klipper service is not active/started on the Pi. This service should actually be active all the time, even if the printer itself is not switched on or the printer's MCU/board is without power.

It is true that the klipper service is not running, it automatically ends/dies when I turn off my Ender running klipper (because it does have a USB connection any more). And it automatically restarts (via systemd) as soon I power up the printer. Never had any problems with that and frankly I thought it is the default behaviour. So klipper.service should be up when the MCU is powered down? But even if klipper is not ready, moonraker sure is (which can be queried via /server/info). So I don't really see why uploads shouldn't be possible.

emtrax-ltd commented 4 months ago

Try this branch: https://github.com/emtrax-ltd/Cura2MoonrakerPlugin/tree/pwrdevfix

Uploading to Moonraker at http://octoprint.at.home:7125/ was not successful. NetworkError.ServiceUnavailableError - Error transferring http://octoprint.at.home:7125/printer/info - server replied: Klippy Host not connected

It fails because the Klipper service is not active/started on the Pi. This service should actually be active all the time, even if the printer itself is not switched on or the printer's MCU/board is without power.

It is true that the klipper service is not running, it automatically ends/dies when I turn off my Ender running klipper (because it does have a USB connection any more). And it automatically restarts (via systemd) as soon I power up the printer. Never had any problems with that and frankly I thought it is the default behaviour. So klipper.service should be up when the MCU is powered down? But even if klipper is not ready, moonraker sure is (which can be queried via /server/info). So I don't really see why uploads shouldn't be possible.

Try latest version of branch: https://github.com/emtrax-ltd/Cura2MoonrakerPlugin/tree/pwrdevfix - there is a new commit!

wollew commented 4 months ago

LGTM, will confirm once my currently running print is done. Thank you.

wollew commented 4 months ago

As expected, this fixed the problem for me.