You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.rst
+54-42Lines changed: 54 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -3,62 +3,74 @@ PrusaConnect SDK for Printer
3
3
4
4
Printer instance
5
5
----------------
6
-
You can create a Printer instance using the constructor and passing `server` and `token` to it. These you can find in `prusa_printer_settings.ini`.
6
+
You can create a Printer instance using the constructor passing printer type,
7
+
serial number and printer fingerprint to it. Serial number can be found on the printer label.
8
+
For I3MK3, printer fingerprint is a SHA256 HEX digest of the serial number.
9
+
For SL1,
10
+
For HT95
7
11
8
12
.. code:: python
9
13
10
14
from prusa.connect.printer import Printer, const
11
15
16
+
SN="Printer serial number"
17
+
FINGERPRINT= sha256(SN.encode()).hexdigest()
18
+
PRINTER_TYPE= const.PrinterType.I3MK3
19
+
printer = Printer(PRINTER_TYPE, SN, FINGERPRINT)
20
+
21
+
For setting the connection you should then call `set_connection` passing `server` and `token`to it. These you can find in the `prusa_printer_settings.ini` file. You can download it after printer registration from the Connect web by selecting your printer -> Settings -> LAN settings -> Download settings. If the printer has not been registered yet, refer to the Registration section below.
22
+
23
+
.. code:: python
24
+
12
25
SERVER="https://connect.prusa3d.com"
13
-
SN='SERIAL_NUMBER_FROM_PRINTER'
14
-
FINGERPRINT='Printer fingerprint'
15
-
TOKEN='secret token from prusa_printer_settings.ini'
If the printer has not been registered yet, you need to use `Printer.register()` to get a temporary code. This code is then used in the **Add Printer** form in Connect Web. After the printer
37
-
has been added to Connect, `Printer.get_token()` will return printer's persistent token.
43
+
If the printer has not been registered yet, you need to use `Printer.register()` to get a temporary code. Enter this code in the **Add Printer** form in Connect Web. After the printer has been added to Connect, your Printer instance will automatically retrieve the code in the background.
print(f"Use this code `{tmp_code}` in add printer form "
50
60
f"{SERVER}/printers/overview?code={tmp_code}.")
51
61
52
-
token =None
53
-
while token isNone:
54
-
token = printer.get_token(tmp_code)
62
+
while printer.token isNone:
63
+
print("Waiting for the printer registration on the Connect web...")
55
64
sleep(1)
56
65
57
-
print("Printer is registered with token %s"% token)
66
+
print(f"Printer is registered with token {printer.token}")
67
+
68
+
Note: For I3MK3 the Add Printer form does not allow you manually enter the temporary code.
69
+
You can use this url to add it directly: https://connect.prusa3d.com:443/add-printer/connect/{PRINTER_TYPE}/{tmp_code}
58
70
59
71
Telemetry
60
72
---------
61
-
Printer must send telemetry to connect at least each second. Because obtaining telemetry values might not be atomic, this must be done in a different thread than `Printer.loop`.
73
+
Printer must send telemetry to Connect at least once per second. Because obtaining telemetry values might not be atomic, this must be done in a separate thread from `Printer.loop`.
62
74
63
75
.. code:: python
64
76
@@ -67,29 +79,26 @@ Printer must send telemetry to connect at least each second. Because obtaining t
67
79
68
80
...
69
81
70
-
#start communication loop
82
+
#Start communication loop in a separate thread
71
83
thread = Thread(target=printer.loop)
72
84
thread.start()
73
85
74
-
#each second send telemetry to internal queue in the main-thread
86
+
#Send telemetry to the main thread queue once per second
Events are a way to send information about the printer to Connect. They can be split into a few groups:
93
+
Events are a way to send information about the printer to Connect.
94
+
They can be grouped into several categories:
83
95
84
-
* **Command answers** - Response for Connect if the command was be ACCEPTED,
85
-
REJECTED, etc. These are handled by the SDK in `Printer.loop` method or in `Command.__call__` method.
86
-
* **State change** - indicating that the printer state has changed. This are sent
87
-
by `Printer.set_state` method.
88
-
* **FILE INFO** events which are created by `FileSystem` object.
89
-
* Alternatively you can inform Connect about other events like attaching/detaching of storage.
90
-
You can do this by calling `Printer.event_cb`.
96
+
**Command answers** – Responses to Connect indicating whether a command was ACCEPTED, REJECTED, etc. These are handled by the SDK in the `Printer.loop` method or the `Command.__call__` method.
97
+
**State changes** – Indicate that the printer's state has changed. These are sent by the `Printer.set_state` method.
98
+
**FILE INFO** events – Created by the FileSystem object.
99
+
**Other events** – For example, informing Connect about storage being attached or detached. You can do this by calling `Printer.event_cb`.
91
100
92
-
Examples for these groups follow below.
101
+
Examples of each category are provided below.
93
102
94
103
Event callback
95
104
--------------
@@ -101,15 +110,15 @@ You can inform Connect about some specific situation using events.
0 commit comments