Avisos
Vaciar todo

Python script to start print  

  RSS
nickjvturner
(@nickjvturner)
New Member
Python script to start print

Hey,

I would like to create a python script that could set my printer as 'ready' so that it would process the next job in the print queue.

Any pointers on how to get started with this?

I did write functional scripts for the mini that simply pulled telemetry data, but I am struggling with my I3 printers.

Should I address Prusa Link or Prusa Connect and is there any API documentation with some examples?

...

OR... what I am really after is a way to schedule a print job to start at a particular time, but I figure I can schedule that myself once / if I can get a script functioning.

Thank you

Respondido : 16/12/2022 11:13 pm
Tojik
(@tojik)
Miembro Moderator
RE: Python script to start print

Hi, i think there's no API for setting your printer to ready. But the jobs should be able to be scheduled, so once the feature is there, you'd just set your printer to ready ahead of time, then the job would start at the set time. There might be one possible way to script this, but it's a hack on top of a hack. You can create the folder PrusaLink menu in the root of your printer's SD card. PrusaLink should create a file setready.g in this folder automatically. (see release notes for 0.7.0rc1) You'd then ask the printer to print that file over the API documented on our github under Prusa-Link-Web but please remember that it is janky as all heck and might not work.

Respondido : 16/12/2022 11:56 pm
nickjvturner me gusta
towlerg
(@towlerg)
Noble Member
RE: Python script to start print

Octoprint will do many of the things your trying to do. Plus Octoprint has a API and plugins are usually written in python, which gives you a head start.

If your not aware of Octoprint, it accepts files (most conveniently  from Prusaslicer directly) and streams via a raspberry to your printer. IIRC both Min and Mk3 are supported.

Respondido : 17/12/2022 1:46 pm
Tojik
(@tojik)
Miembro Moderator
RE: Python script to start print

Respondido : 17/12/2022 2:11 pm
nickjvturner
(@nickjvturner)
New Member
Topic starter answered:
RE: Python script to start print

Thank you!!

I am keen to stick with Prusa Connect & Link for now.

Happy to share that after sleeping on it, I found what I was looking for, it looks this (at it's most basic level):

#!/usr/bin/env python3

import requests
from requests.auth import HTTPDigestAuth
import pprint
import json

response = requests.get(
	'http://{local IP of Prusa printer}/api/job', 
	auth=HTTPDigestAuth('prusa-link-username', 'prusa-link-password')
)

pretty_response = json.loads(response.content)

pprint.pprint(pretty_response)

 

I will write up a blog article about this, nickjvturner.com

The piece I was missing was the authentication type which is specifically 'Digest Auth' with algorithm 'MD5-sess' (required if you want to explore using Postman).

The code snippet above only GETs info, but it is also possible to POST to the same end point, with a payload of:

{
  "command": "start"
}

This triggers the currently loaded project to start-up.

Thank you to everyone at Prusa, Connect is fantastic!

Respondido : 17/12/2022 2:26 pm
Tojik
(@tojik)
Miembro Moderator
RE: Python script to start print

Oh sorry, I did not create the API and it shows 😅

Respondido : 17/12/2022 3:39 pm
nickjvturner
(@nickjvturner)
New Member
Topic starter answered:
RE: Python script to start print

no problem at all! 🙂

Respondido : 17/12/2022 3:42 pm
Compartir: