| ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
|---|
LEGO Wireless Protocol v3 device¶
- class LWP3Device(hub_kind, name=None, timeout=10000, pair=False, num_notifications=8, connect=True)¶
Connects to a hub running official LEGO firmware using the LEGO Wireless Protocol v3.
- Parameters:
hub_kind (int) – The hub type identifier of the hub to connect to.
name (str) – The name of the hub to connect to or
Noneto connect to any hub.timeout (int) – The time, in milliseconds, to wait for a connection before raising an exception.
pair (bool) – Whether to attempt pairing for a secure connection. This is required for some newer hubs.
num_notifications (int) – Number of incoming messages from the remote hub to store before discarding older messages.
connect (bool) – Choose
Falseto skip connecting.connect()can be called later to connect.
Changed in version 3.6: Added
pairparameter.Changed in version 3.7: Added
num_notificationsparameter.- awaitconnect()¶
Connects to the device. Only needed if you disconnected or initialized with
connect=False.- Raises:
OSError – If the connection attempt fails or times out.
- awaitwrite(buf)¶
Sends a message to the remote hub.
- Parameters:
buf (bytes) – The raw binary message to send. Maximum 20 bytes.
- Raises:
ValueError – If the message exceeds 20 bytes.
OSError – If the device is not connected or the write fails.
- read() bytes | None¶
Retrieves the oldest buffered message received from the remote hub.
If all buffered messages have already been read, this returns
None.- Returns:
The oldest raw binary message or
Noneif there are no more messages.
Changed in version 3.7: Now supports reading multiple buffered messages instead of blocking until one new message was received.