Dongle¶
Dongle is a handle to the USB dongle's serial link. It is only needed when
sharing one dongle across multiple Robot instances. A Robot
created without a transport argument manages its own Dongle internally.
Constructor¶
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
port |
str \| None |
None |
Serial device path (e.g. "COM3", "/dev/ttyACM0"). When None, scans all connected ports for an Espressif USB VID (0x303A) and uses the first match. |
baud |
int |
921600 |
Baud rate. Must match the dongle firmware. |
Raises: RuntimeError — No dongle found and port was not specified.
Methods¶
open¶
Open the serial port and start the background receive thread. Returns self.
Called automatically by __enter__.
close¶
Stop the receive thread and close the serial port. Called automatically by
__exit__.
add_recv_callback¶
Register a callback invoked for every ESP-NOW packet received from the dongle. Multiple callbacks may be registered; each is called in registration order. Adding the same callable a second time is a no-op.
Parameters
| Parameter | Type | Description |
|---|---|---|
fn |
Callable[[bytes, int, bytes], None] |
Signature: fn(packet, rssi, mac). rssi is signal strength in dBm (negative integer). mac is the 6-byte sender MAC address. |
remove_recv_callback¶
Deregister a callback previously added with
add_recv_callback(). Silently ignores fn if it is not
currently registered.
Context manager¶
Dongle implements __enter__ / __exit__. __enter__ calls open()
and returns self; __exit__ calls close() unconditionally.
Multiple robots example¶
One dongle communicates with all robots on the same ESP-NOW channel. Pass the
same Dongle to each Robot — each robot registers its own receive callback and
filters packets by device ID.