Skip to content

Commit d42718b

Browse files
committed
docs(readme): Update and clarify instructions and formatting
1 parent 8e268dc commit d42718b

File tree

1 file changed

+54
-42
lines changed

1 file changed

+54
-42
lines changed

README.rst

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,74 @@ PrusaConnect SDK for Printer
33

44
Printer instance
55
----------------
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
711

812
.. code:: python
913
1014
from prusa.connect.printer import Printer, const
1115
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+
1225
SERVER = "https://connect.prusa3d.com"
13-
SN = 'SERIAL_NUMBER_FROM_PRINTER'
14-
FINGERPRINT = 'Printer fingerprint'
15-
TOKEN = 'secret token from prusa_printer_settings.ini'
16-
printer = Printer(const.PrinterType.I3MK3, SN, SERVER, TOKEN)
26+
TOKEN = "Secret token from prusa_printer_settings.ini"
27+
28+
printer.set_connection(SERVER, TOKEN)
1729
1830
printer.loop() # communication loop
1931
20-
Or you can use `Printer.from_config()` method which reads these values from the ini file.
32+
Or you can use `printer.connection_from_config()` method which reads these values directly from the .ini file.
2133

2234
.. code:: python
2335
24-
from prusa.connect.printer import Printer, const
25-
26-
SERVER = "https://connect.prusa3d.com"
27-
SN = 'SERIAL_NUMBER_FROM_PRINTER'
28-
printer = Printer.from_config("./prusa_printer_settings.ini",
29-
const.PrinterType.I3MK3, SN)
36+
printer.connection_from_config("./prusa_printer_settings.ini")
3037
3138
printer.loop() # communication loop
3239
3340
3441
Registration
3542
------------
36-
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.
3844

3945
.. code:: python
4046
4147
from time import sleep
4248
from prusa.connect.printer import Printer, const
4349
4450
SERVER = "https://connect.prusa3d.com"
45-
SN = 'SERIAL_NUMBER_FROM_PRINTER'
46-
printer = Printer(const.PrinterType.I3MK3, SN, SERVER)
51+
SN = "Printer serial number"
52+
FINGERPRINT = "Printer fingerprint"
53+
PRINTER_TYPE = const.PrinterType.I3MK3
54+
printer = Printer(PRINTER_TYPE, SN, FINGERPRINT)
55+
56+
printer.set_connection(SERVER, None)
4757
4858
tmp_code = printer.register()
4959
print(f"Use this code `{tmp_code}` in add printer form "
5060
f"{SERVER}/printers/overview?code={tmp_code}.")
5161
52-
token = None
53-
while token is None:
54-
token = printer.get_token(tmp_code)
62+
while printer.token is None:
63+
print("Waiting for the printer registration on the Connect web...")
5564
sleep(1)
5665
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}
5870

5971
Telemetry
6072
---------
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`.
6274

6375
.. code:: python
6476
@@ -67,29 +79,26 @@ Printer must send telemetry to connect at least each second. Because obtaining t
6779
6880
...
6981
70-
# start communication loop
82+
# Start communication loop in a separate thread
7183
thread = Thread(target=printer.loop)
7284
thread.start()
7385
74-
# each second send telemetry to internal queue in the main-thread
86+
# Send telemetry to the main thread queue once per second
7587
while True:
7688
printer.telemetry(const.State.READY, temp_nozzle=24.1, temp_bed=23.2)
7789
sleep(1)
7890
79-
8091
Events
8192
------
82-
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:
8395

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`.
91100

92-
Examples for these groups follow below.
101+
Examples of each category are provided below.
93102

94103
Event callback
95104
--------------
@@ -101,15 +110,15 @@ You can inform Connect about some specific situation using events.
101110
102111
...
103112
104-
# start communication loop
113+
# Start communication loop
105114
thread = Thread(target=printer.loop)
106115
thread.start()
107116
108117
try:
109118
...
110119
except Exception as err:
111-
# send event to internal queue
112-
printer.event_cb(const.Event.ATTENTION, const.Source.WUI,
120+
# Send event to internal queue
121+
printer.event_cb(const.Event.FAILED, const.Source.WUI,
113122
reason=str(err))
114123
115124
Printer state
@@ -122,11 +131,11 @@ Printer state
122131
123132
...
124133
125-
# start communication loop
134+
# Start communication loop
126135
thread = Thread(target=printer.loop)
127136
thread.start()
128137
129-
# toggle the state each second
138+
# Toggle the state each second
130139
while True:
131140
if printer.state == const.State.READY:
132141
printer.set_state(const.State.BUSY, const.Source.MARLIN)
@@ -168,26 +177,29 @@ a dictionary as a value.
168177
...
169178
170179
@printer.handler(const.Command.START_PRINT)
171-
def start_print(args: List[str]):
180+
def start_print(args: list[str]):
172181
"""This handler will be called when START_PRINT command was sent to
173182
the printer."""
174183
printer.set_state(const.State.PRINTING, const.Source.CONNECT)
175184
print("Printing file: {args[0]}")
176185
...
177186
178187
@printer.handler(const.Command.STOP_PRINT)
179-
def start_print(args: List[str]):
188+
def start_print(args: list[str]):
180189
"""This handler will be called when STOP_PRINT command was sent to
181190
the printer."""
182191
printer.set_state(const.State.READY, const.Source.CONNECT)
183192
print("Printing stopped")
184193
...
185194
186-
# communication loop
195+
# Communication loop
187196
thread = Thread(target=printer.loop)
188197
thread.start()
189198
190-
# try run command handler each 100 ms
199+
# Set printer state to READY.
200+
printer.set_state(const.State.READY, const.Source.CONNECT)
201+
202+
# Try run command handler each 100 ms
191203
while True:
192204
printer.command()
193205
sleep(0.1)

0 commit comments

Comments
 (0)