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

Unable to get it running with Readme examples #270

Open
Skaronator opened this issue Oct 29, 2023 · 5 comments
Open

Unable to get it running with Readme examples #270

Skaronator opened this issue Oct 29, 2023 · 5 comments

Comments

@Skaronator
Copy link

I'm trying to get it running, but the examples from the Readme are all outdated and / or the error handling appears to be wrong?

My use case is basic. My Prusa XL is already connected to Prusa Connect and I just want to get the current printer state.

My odyssey ---- Let's just go through what I did and why it's frustrating.

Picking up the very first example from the Readme:

from prusa.connect.printer import Printer, const

SERVER = "https://connect.prusa3d.com"
SN = 'SERIAL_NUMBER_FROM_PRINTER'
FINGERPRINT = 'Printer fingerprint'
TOKEN = 'secret token from prusa_printer_settings.ini'
printer = Printer(const.PrinterType.I3MK3, SN, SERVER, TOKEN)

printer.loop()  # communication loop

Running this will result in the first error:

File "/home/niklas/Workspace/prusa-demo/./main.py", line 14, in <module>
    printer = Printer(const.PrinterType.I3MK3, SN, SERVER, TOKEN)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/niklas/Workspace/prusa-demo/venv/lib/python3.11/site-packages/prusa/connect/printer/__init__.py", line 116, in __init__
    if max_retries > 1:
       ^^^^^^^^^^^^^^^
TypeError: '>' not supported between instances of 'str' and 'int'

The arguments from Printer are different now. The 3rd Argument is now finterprint (instead of SERVER) and the 4th argument is now max_retries (instead of TOKEN)


The next issue, the Prusa XL doesn't exist as PrinterType.

class PrinterType(Enum):
"""Printer Type"""
I3MK25 = (1, 2, 5)
I3MK25S = (1, 2, 6)
I3MK3 = (1, 3, 0)
I3MK3S = (1, 3, 1)
SL1 = (5, 1, 0)
TRILAB_DQ2 = (6, 2, 0)
TRILAB_DQ2P = (6, 2, 1)
TRILAB_AQI = (7, 2, 0)

Okay, maybe it's too new, but Prusa Mini (and MK4) don't even exist. Looking at the code, the PrinterType is optional, so I'll leave it empty:

def __init__(self,
type_: Optional[const.PrinterType] = None,
sn: Optional[str] = None,
fingerprint: Optional[str] = None,
max_retries: int = 1):


Upnext I tried the following code:

While I know the SerialNumber I have no clue what fingerprint is. So I used the Printer UUID from the Prusa Connect settings page of my printer.

printer = Printer(None, "<real SN>", "<UUID as Fingerprint>", 10)

thread = Thread(target=printer.loop)
thread.start()

while True:
  print(printer.state)
  sleep(1)

Running that looks good! I got a State back!

$ ./main.py 
State.BUSY
State.BUSY

But wait a second.. HOW? I didn't even enter an API Token and just the SN and UUID shouldn't be enough. So I tried setting stupid data like this:

- printer = Printer(None, "<real SN>", "<UUID as Fingerprint>", 10)
+ printer = Printer(None, "dummystring", "dummystring", 10)

Running that looks good as well? I got a state back and no error whatsoever.

$ ./main.py 
State.BUSY
State.BUSY

Digging deeper into the SDK Code I have to call printer.set_connection. The function want a Server and a Token but not the API Token, a different token. I did some research and looks like downloading the "LAN settings" from Prusa Connect contains both, the Server and the token. Furthermore, the API Key is still not set, so just set this as well.

Running that code now, which looks like this:

SN = '10381-xyxy'
printer = Printer(None, SN, None, 10)
printer.api_key = "xyz"
printer.set_connection("https://connect.prusa3d.com", "xyz")

thread = Thread(target=printer.loop)
thread.start()

while True:
  print(printer.state)
  sleep(1)

Running it?

$ ./main.py 
State.BUSY
State.BUSY

Which is still wrong! It should be PRINTING

Would it be possible to provide an up2date Readme example that shows the current printer status, nozzle temperature, print time and document which (API) tokens and fingerprints I need to get it running?

@CuriousTimo
Copy link

CuriousTimo commented Oct 29, 2023

I think you are mixing up a few things.

  • Prusa Connect is the online environment hosted by Prusa (https://connect.prusa3d.com/)
  • Prusa Link V1 is what is running on the Raspberry Pi to connect the MK2.5, MK3 machines to Prusa Connect and to give those machines a local LAN web interface.
  • Prusa Link V2 is what is running natively on the Prusa Mini and XL machines to Prusa Connect and provides those machines with the local LAN web interface.

Since you want to connect locally to an XL you should look into PrusaLink v2. It is the same as what the Home Assistant integration uses for example.

From what I can tell, based on the python, you are looking into the V1 source code. This is not correct for the Prusa XL.
Also you should look into the part of the API that handles the local API directly to the printer, not the Prusa Connect stuff.

@Skaronator
Copy link
Author

I'm specially looking for to accessing the Print Queue and Set Ready command for my home assistant. Both are Prusa Connect features and not available/part of Prusa Link Vx. Hence, why I'm looking at this SDK.

Looks like this library is mostly meant for a Printer that communicates with Prusa Connect and not a User/Script that reads data from Prusa Connect?

@CuriousTimo
Copy link

In that case it might be much easier to just use the dev tools on the browser when working on connect.prusa.com and look at what is happening there on the network tab in dev tools

@Skaronator
Copy link
Author

Yeah, I was really hoping this "Python printer library for Prusa Connect" from Prusa directly could do most of the heavy lifting.

@UmBsublime
Copy link

I'm somewhat confused by this thread. I'm also trying the example code from the readme and not really getting expected results.

I currently own a prusaXL which is registered to connect.prusa3d.com. I have not found any way instantiate a prusa.connect.printer.Printer that allows me to query my printer.

The constructor for prusa.connect.printer.Printer does not even seem to match the examples in the readme

class Printer:
 ...
def __init__(self,
                 type_: Optional[const.PrinterType] = None,
                 sn: Optional[str] = None,
                 fingerprint: Optional[str] = None,
                 max_retries: int = 1,
                 mmu_supported: bool = True):

And here is the example from readme

from prusa.connect.printer import Printer, const

SERVER = "https://connect.prusa3d.com"
SN = 'SERIAL_NUMBER_FROM_PRINTER'
FINGERPRINT = 'Printer fingerprint'
TOKEN = 'secret token from prusa_printer_settings.ini'
printer = Printer(const.PrinterType.I3MK3, SN, SERVER, TOKEN)

This leaves me with 2 questions:

  1. My end goal is to fetch telemetry for my printer through connect.prusa3d.com is this something possible with this module ?
  2. How do I instantiate the Printer object to allow this and where can I find the printer fingerpint ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants