Bytecodes
The LWP3 bytecodes
module contains enums for interpreting binary values
used in the LWP3 protocol.
- class AlertKind(value)
Alert conditions received from the hub.
- HIGH_CURRENT = 2
The battery current is high.
- LOW_SIGNAL = 3
The Bluetooth signal strength is low.
- LOW_VOLTAGE = 1
The battery voltage is low.
- OVER_POWER = 4
The hub is using too much power.
- class AlertOperation(value)
Operations that can be done with hub alerts.
- DISABLE_UPDATES = 2
Disables updates from the hub.
- ENABLE_UPDATES = 1
Enables updates from the hub.
- REQUEST_UPDATE = 3
Requests a single update from the hub.
- UPDATE = 4
Contains an update received from the hub.
- class AlertStatus(value)
Indicates if the alert is present or not.
- ALERT = 255
The alert condition is present.
- OK = 0
Status is OK.
- class BatteryKind(value)
The kind of battery.
- NORMAL = 0
Standard AA or AAA batteries.
- RECHARGEABLE = 1
Rechargeable Li-ion or Li-po battery pack.
- class BluetoothAddress(value: str | bytes)
A Bluetooth address.
These addresses use the same EUI-48 format as MAC addresses but are for identifying individual Bluetooth devices instead of network cards.
- class Capabilities(value)
Describes the capabilities of a hub.
These flags are used in advertising data.
- CENTRAL = 1
The hub supports the central role.
- IO = 4
The hub has I/O ports for connecting sensors/motors.
- PERIPHERAL = 2
The hub supports the peripheral role.
- REMOTE = 8
The hub acts as a remote control.
- class DataFormat(value)
I/O Device data format.
- DATA16 = 1
16-bit signed integer, little-endian.
- DATA32 = 2
32-bit signed integer, little-endian.
- DATA8 = 0
8-bit signed integer.
- DATAF = 3
32-bit floating point, little-endian.
- class ErrorCode(value)
Generic error codes.
- ACK = 1
- BUFFER_OVERFLOW = 3
- INTERNAL_ERROR = 8
- INVALID = 6
Invalid use (e.g. invalid parameters).
- NACK = 2
- OVER_CURRENT = 7
- TIMEOUT = 4
- UNKNOWN_COMMAND = 5
The command is not supported.
- class Feedback(value)
An enumeration.
- BUFFER_EMPTY_COMPLETED = 2
- BUFFER_EMPTY_IN_PROGRESS = 1
- BUSY = 16
- DISCARDED = 4
- IDLE = 8
- class HubAction(value)
Instructs the hub to perform an action.
- DISCONNECT = 2
Instructs the hub to disconnect Bluetooth.
- FAST_POWER_OFF = 47
Fast power off (factory use).
- PORT_VCC_OFF = 4
Turns off 3.3V on I/O port pin 4 for all ports.
- PORT_VCC_ON = 3
Turns on 3.3V on I/O port pin 4 for all ports.
- POWER_OFF = 1
Switches the hub off.
- RESET_BUSY = 6
Resets busy indication on status light.
- SET_BUSY = 5
Sets busy indication on status light.
- WILL_DISCONNECT = 49
The hub will disconnect.
- WILL_POWER_OFF = 48
The hub will switch off.
- WILL_UPDATE = 50
The hub will restart in firmware update mode.
- class HubKind(value)
Indicates the kind of hub.
This is used both in advertising data an in messages.
- BOOST = 64
LEGO BOOST Move Hub.
- CITY = 65
LEGO 2-port Hub.
- DUPLO_TRAIN = 32
LEGO Duplo Train.
- EV3 = 226
LEGO MINDSTORMS EV3 brick. (unofficial Pybricks addition)
- HANDSET = 66
LEGO 2-port Handset (remote control).
- LUIGI = 68
LEGO Luigi Hub.
- MARIO = 67
LEGO Mario Hub.
- NXT = 225
LEGO MINDSTORMS NXT brick. (unofficial Pybricks addition)
- RCX = 224
LEGO MINDSTORMS RCX brick. (unofficial Pybricks addition)
- TECHNIC = 128
LEGO 4-port Technic Hub.
- TECHNIC_LARGE = 129
LEGO SPIKE Prime Hub and MINDSTORMS Robot Inventor hubs.
- TECHNIC_SMALL = 131
LEGO SPIKE Essential Hub.
- WEDO2 = 0
LEGO WeDo 2.0 Hub.
- property system: SystemKind
Gets ths system that this hub belongs to.
- class HubProperty(value)
Properties used in
MessageKind.HUB_PROPERTY
messages.- BATTERY_KIND = 7
Battery type.
- BATTERY_VOLTAGE = 6
Battery voltage (as percent).
- BDADDR = 13
Bluetooth address.
- BOOTLOADER_BDADDR = 14
Bootloader Bluetooth address.
- BUTTON = 2
The button state.
- FW_VERSION = 3
The firmware version.
- HUB_KIND = 11
The kind of hub.
- HW_NET_FAMILY = 15
Hardware network family.
- HW_NET_ID = 12
Hardware network ID.
- HW_VERSION = 4
The hardware version.
- LWP_VERSION = 10
LEGO Wireless Protocol version.
- MFG_NAME = 8
Manufacturer name.
- NAME = 1
The hub name.
- RADIO_FW_VERSION = 9
Bluetooth radio firmware version.
- RSSI = 5
Radio signal strength indication.
- VOLUME = 18
Sound volume level.
- class HubPropertyOperation(value)
Operations for hub property messages.
- DISABLE_UPDATES = 3
Disables continuous updates for a property.
- ENABLE_UPDATES = 2
Enables continuous updates for a property.
- REQUEST_UPDATE = 5
Requests a single property update.
- RESET = 4
Resets a property to the default value.
- SET = 1
Sets a property.
- UPDATE = 6
Contains the current value of a property.
- class HwNetCmd(value)
Hardware network commands.
These commands are for creating hub-to-hub connections, not hub to phone/tablet/computer connections.
- CONNECTION_REQUEST = 2
This message is used to route/gate a connection request from a peripheral device up to the controlling Central device. The user should be able to press the button on any devices in the current connected network for requesting a connection. Both the Pressed and the Release is send.
- EXTENDED_FAMILY = 12
This is the answer returned for above command (Get Extended Family 0x0A).
- EXTENDED_FAMILY_SET = 13
The user can set both the Family and the SubFamily in one tx/rx. Further both are only using 3 bits for the addressing leaving one bit each for future use and/or escape (extended use).
- FAMILY = 7
This is the answer returned for above command (Get Family 0x06). Used by the Central Role device to decide the Family at auto connection.
- FAMILY_REQUEST = 3
When send upstream (from any device in the H/W network) this message is a request for a new Family and SubFamily, if possible.
- FAMILY_SET = 4
This command is send from the controlling Central device and has the new family added as payload.
- GET_EXTENDED_FAMILY = 11
Requesting the previous used Family and SubFamily for a specific (the addressed) device. The user can get both the Family and the SubFamily in one tx/rx. Further both are only using 3 bits for the addressing leaving one bit each for future use and/or escape.
- GET_FAMILY = 6
Requesting the previous used Family for a specific (the addressed) device, just entered a network - no family decided yet.
- GET_SUBFAMILY = 8
Requesting the previous used SubFamily (Function) on a specific (addressed) device. E.g. a 2 port R/C to a 4 port hub. I.e. addressing a specific port (A+B or C+D)
- JOIN_DENIED = 5
This command is send to a peripheral trying to connect to a network where the maximum of nodes is reached (i.e. no further connections available).
- RESET_LONG_PRESS = 14
The timing of the user CONNECTION PRESS may be stretched (timer reset) when connecting in a Bluetooth active environment. I.e. the LONG PRESS normally is used for powering down a device, but also used for gating key presses to the Central in a connection sequence (allowing a longer connection time without powering down.
- SUBFAMILY = 9
This is the answer returned for above command (Get SubFamily 0x08). Used by the Central Role device to decide the SubFamily at auto connection.
- SUBFAMILY_SET = 10
This command is send from the controlling Central device and has the new SubFamily added as payload.
- class HwNetExtFamily(value)
Combination of
HwNetFamily
andHwNetSubfamily
encoded in a single byte.- property family: HwNetFamily
- static from_parts(family: HwNetFamily, subfamily: HwNetSubfamily) HwNetExtFamily
- property subfamily: HwNetSubfamily
- class HwNetFamily(value)
Hardware network family.
Families are denoted by the status light color.
- BLUE = 4
- CYAN = 6
- GREEN = 1
- PINK = 8
- PURPLE = 5
- RED = 3
- TEAL = 7
- WHITE = 0
- YELLOW = 2
- class HwNetSubfamily(value)
Hardware network subfamily.
Subfamilies are denoted by the number of flashes of the status light.
- FLASH_0 = 0
- FLASH_1 = 1
- FLASH_2 = 2
- FLASH_3 = 3
- FLASH_4 = 4
- FLASH_5 = 5
- FLASH_6 = 6
- FLASH_7 = 7
- class IODeviceCapabilities(value)
Sensor capabilities flags. (48-bit)
- class IODeviceKind(value)
The kind of attached I/O device.
- BOOST_COLOR_DISTANCE_SENSOR = 37
BOOST Color and Distance Sensor
- BOOST_HUB_ACCEL = 40
BOOST Move Hub built-in accelerometer (tilt sensor).
- BOOST_HUB_MOTOR = 39
BOOST Move Hub built-in motor.
- BOOST_INTERACTIVE_MOTOR = 38
BOOST Interactive Motor
- DUPLO_TRAIN_BEEPER = 42
DUPLO Train hub built-in beeper.
- DUPLO_TRAIN_COLOR_SENSOR = 43
DUPLO Train hub built-in color sensor.
- DUPLO_TRAIN_MOTOR = 41
DUPLO Train hub built-in motor.
- DUPLO_TRAIN_SPEED = 44
DUPLO Train hub built-in speed sensor.
- EV3_COLOR_SENSOR = 29
EV3 Color Sensor.
- EV3_GYRO_SENSOR = 32
EV3 Gyro Sensor.
- EV3_IR_SENSOR = 33
EV3 Infrared Sensor.
- EV3_ULTRASONIC_SENSOR = 30
EV3 Ultrasonic Sensor.
- HUB_BATTERY_CURRENT = 21
Powered Up Hub battery current.
- HUB_BATTERY_VOLTAGE = 20
Powered Up Hub battery voltage.
- HUB_IMU_ACCEL = 57
Powered Up hub built-in IMU accelerometer.
- HUB_IMU_GESTURE = 54
Powered Up hub built-int IMU gesture.
- HUB_IMU_GYRO = 58
Powered Up hub built-in IMU gyro
- HUB_IMU_ORIENTATION = 59
Powered Up hub built-in IMU orientation.
- HUB_IMU_TEMPERATURE = 60
Powered Up hub built-in IMU temperature.
- HUB_PIEZO = 22
Powered Up Hub piezo buzzer.
- HUB_RSSI = 56
Powered Up hub Bluetooth RSSI
- HUB_STATUS_LIGHT = 23
Powered Up Hub status light.
- HUB_UNKNOWN_X32 = 50
Technic Control+ Hub ?
- LIGHTS = 8
Powered Up Lights.
- MEDIUM_MOTOR = 1
Powered Up Medium Motor.
- NONE = 0
No device.
- REMOTE_BUTTONS = 55
Powered Up Handset Buttons.
- SPIKE_COLOR_SENSOR = 61
SPIKE/MINDSTORMS Color Sensor.
- SPIKE_FORCE_SENSOR = 63
SPIKE/MINDSTORMS Force Sensor.
- SPIKE_LARGE_MOTOR = 49
SPIKE Prime Large Motor.
- SPIKE_MEDIUM_MOTOR = 48
SPIKE Prime Medium Motor.
- SPIKE_ULTRASONIC_SENSOR = 62
SPIKE/MINDSTORMS Ultrasonic Distance Sensor.
- TECHNIC_LARGE_ANGULAR_MOTOR = 76
Technic Large Angular motor, gray.
- TECHNIC_LARGE_MOTOR = 46
Technic Control+ Large Motor.
- TECHNIC_MEDIUM_ANGULAR_MOTOR = 75
Technic Medium Angular Motor, gray.
- TECHNIC_XL_MOTOR = 47
Technic Control+ XL Motor.
- TRAIN_MOTOR = 2
Powered Up Train Motor
- WEDO_GENERIC = 36
WeDo 2.0 generic device.
- WEDO_MOTION_SENSOR = 35
WeDo 2.0 Motion Sensor.
- WEDO_TILT_SENSOR = 34
WeDo 2.0 Tilt Sensor.
- class IODeviceMapping(value)
An enumeration.
- ABSOLUTE = 16
- DISCRETE = 4
- RELATIVE = 8
- SUPPORTS_MAPPING_V2 = 64
- SUPPORTS_NULL = 128
- class IOEvent(value)
Events from I/O ports.
- ATTACHED = 1
An I/O device was attached.
- ATTACHED_VIRTUAL = 2
A virtual I/O device was attached.
- DETACHED = 0
An I/O device was detached.
- class LWPVersion
The LEGO Wireless Protocol (LWP) version.
- property major: int
Gets the major version component.
- property minor: int
Gets the minor version component.
- static parse(version: str) LWPVersion
Parses a string with the format
XX.XX
.
- class LastNetwork(value)
Describes the last network ID used in the LWP3 pairing process.
This is used both in advertising data and messages.
- DISABLE_HW_NET = 254
Disable hardware network (default 4).
- DONT_CARE = 255
Don’t care (not implemented).
- LOCKED = 251
Locked (default 1).
- NONE = 0
No connection has been made yet.
- NOT_LOCKED = 252
Not locked (default 2).
- RSSI = 253
RSSI dependant (default 3).
- MAX_NAME_SIZE = 14
The maximum allowable size of the hub name in bytes.
- class MessageKind(value)
Indicates the kind of message.
- ERROR = 5
Generic error messages.
- FW_LOCK = 17
Message to lock the bootloader flash memory (factory use).
- FW_LOCK_STATUS = 19
Reply to
FW_LOCK_STATUS_REQ
.
- FW_LOCK_STATUS_REQ = 18
Message to request the bootloader flash memory lock state.
- FW_UPDATE = 16
Message to put the hub in firmware update mode.
- HUB_ACTION = 2
Messages that perform a hub action.
- HUB_ALERT = 3
Messages to subscribe or retrieve hub alerts.
- HUB_ATTACHED_IO = 4
Messages received when an I/O device is attached.
- HUB_PROPERTY = 1
Messages that get or set hub a hub property.
- HW_NET_CMD = 8
Commands used for hardware networks.
- PORT_INFO = 67
Reply to a
PORT_INFO_REQ
.
- PORT_INFO_REQ = 33
Messages that request port information.
- PORT_INPUT_FMT = 71
Reply to a
PORT_INPUT_FMT_SETUP
.
- PORT_INPUT_FMT_COMBO = 72
Reply to a
PORT_INPUT_FMT_SETUP_COMBO
.
- PORT_INPUT_FMT_SETUP = 65
Message to set up input format for a single mode.
- PORT_INPUT_FMT_SETUP_COMBO = 66
Message to set up input format for a mode combo.
- PORT_MODE_INFO = 68
Reply to a
PORT_MODE_INFO_REQ
.
- PORT_MODE_INFO_REQ = 34
Messages tha request mode information.
- PORT_OUTPUT_CMD = 129
Messages to execute port output commands.
- PORT_OUTPUT_CMD_FEEDBACK = 130
Message that indicate a port output command has completed.
- PORT_VALUE = 69
Value update from a single mode.
- PORT_VALUE_COMBO = 70
Value update from a mode combo.
- VIRTUAL_PORT_SETUP = 97
Message to set up virtual port that provides synchronization of two ports.
- class ModeCapabilities(value)
An enumeration.
- INPUT = 2
- LOGICAL_COMBINABLE = 4
- LOGICAL_SYNCHRONIZEABLE = 8
- OUTPUT = 1
- class ModeInfoKind(value)
An enumeration.
- CAPABILITIES = 8
- FORMAT = 128
- INTERNAL_USE = 6
- MAPPING = 5
- MOTOR_BIAS = 7
- NAME = 0
- PCT = 2
- RAW = 1
- SI = 3
- SYMBOL = 4
- UNK10 = 10
- UNK11 = 11
- UNK12 = 12
- UNK9 = 9
- class PortID(value)
Represents the ID of an external or internal I/O port.
All enum members are dynamic. (0 to 49 are external and 50 - 100 are internal)
- property internal: bool
Tests if the port is internal.
- class PortInfoFormatSetupCommand(value)
An enumeration.
- LOCK = 2
Lock I/O device for setup.
- RESERVED = 5
Not used.
- RESET = 6
Reset I/O device.
- SET = 1
Set mode and data format combos.
- UNLOCK_DISABLED = 4
Unlock and start with updates disabled.
- UNLOCK_ENABLED = 3
Unlock and start with updates enabled.
- class PortOutputCommand(value)
An enumeration.
- GOTO_ABS_POS = 13
- GOTO_ABS_POS_2 = 14
- PRESET_ENCODER = 19
- PRESET_ENCODER_2 = 20
- SET_ACC_TIME = 5
- SET_DEC_TIME = 6
- START_POWER = 1
- START_POWER_2 = 2
- START_SPEED = 7
- START_SPEED_2 = 8
- START_SPEED_FOR_DEGREES = 11
- START_SPEED_FOR_DEGREES_2 = 12
- START_SPEED_FOR_TIME = 9
- START_SPEED_FOR_TIME_2 = 10
- WRITE_DIRECT = 80
- WRITE_DIRECT_MODE_DATA = 81
- class Status(value)
Indicates the status of a connection request.
This is used both in advertising data and in messages.
- CENTRAL = 2
The requesting device can be a central.
- PERIPHERAL = 1
The requesting device can be a peripheral.
- REQUEST_CONNECT = 64
A hard-coded request.
- REQUEST_WINDOW = 32
A button press is extending the request window.
- class SystemKind(value)
Indicates the system that a hub belongs to.
This is encoded in
HubKind
and is not used as a bytecode on its own.- DUPLO = 32
LEGO Duplo
- LEGACY = 224
Pre-Powered Up (unofficial Pybricks addition)
- SYSTEM = 64
LEGO System
- SYSTEM_ = 96
LEGO System
- TECHNIC = 128
LEGO Technic
- WEDO2 = 0
LEGO WeDo 2.0