bricknil.hub

Hub processes for the Boost Move and PoweredUp hubs

Classes

BoostHub(name[, query_port_info, ble_id]) Boost Move Hub
CPlusHub(name[, query_port_info, ble_id]) Technic Control+ Hub
DuploTrainHub(name[, query_port_info, ble_id]) Duplo Steam train and Cargo Train
Hub(name[, query_port_info, ble_id]) Base class for all Lego hubs
PoweredUpHub(name[, query_port_info, ble_id]) PoweredUp Hub class
PoweredUpRemote(name[, query_port_info, ble_id]) PoweredUp Remote class

Members

exception bricknil.hub.UnknownPeripheralMessage[source]

Bases: Exception

exception bricknil.hub.DifferentPeripheralOnPortError[source]

Bases: Exception

class bricknil.hub.Hub(name, query_port_info=False, ble_id=None)[source]

Bases: bricknil.process.Process

Base class for all Lego hubs

Parameters:
  • name (str) – Human-readable name for this hub (for logging)
  • query_port_info (bool) – Set to True if you want to query all the port information on a Hub (very communication intensive)
  • ble_id (str) – BluetoothLE network(MAC) adddress to connect to (None if you want to connect to the first matching hub)
hubs

Class attr to keep track of all Hub (and subclasses) instances

Type:list [Hub]
message_queue

Outgoing message queue to bricknil.ble_queue.BLEventQ

Type:curio.Queue
peripheral_queue

Incoming messages from bricknil.ble_queue.BLEventQ

Type:curio.UniversalQueue
uart_uuid

UUID broadcast by LEGO UARTs

Type:uuid.UUID
char_uuid

Lego uses only one service characteristic for communicating with the UART services

Type:uuid.UUID
tx

Service characteristic for tx/rx messages that’s set by bricknil.ble_queue.BLEventQ.connect()

peripherals

Peripheral name => bricknil.Peripheral

Type:dict
port_to_peripheral

Port number(int) -> bricknil.Peripheral

Type:dict
port_info

Keeps track of all the meta-data for each port. Usually not populated unless query_port_info is true

Type:dict
hubs = []
attach_sensor(sensor: bricknil.sensor.peripheral.Peripheral)[source]

Add instance variable for this decorated sensor

Called by the class decorator bricknil.bricknil.attach when decorating the sensor

connect_peripheral_to_port(device_name, port)[source]

Set the port number of the newly attached peripheral

When the hub gets an Attached I/O message on a new port with the device_name, this method is called to find the peripheral it should set this port to. If the user has manually specified a port, then this function just validates that the peripheral name the user has specified on that port is the same as the one that just attached itself to the hub on that port.

peripheral_message_loop()[source]

The main loop that receives messages from the bricknil.messages.Message parser.

Waits for messages on a UniversalQueue and dispatches to the appropriate peripheral handler.

send_message(msg_name, msg_bytes, peripheral=None)[source]

Insert a message to the hub into the queue(bricknil.hub.Hub.message_queue()) connected to our BLE interface

class bricknil.hub.PoweredUpHub(name, query_port_info=False, ble_id=None)[source]

Bases: bricknil.hub.Hub

PoweredUp Hub class

class bricknil.hub.PoweredUpRemote(name, query_port_info=False, ble_id=None)[source]

Bases: bricknil.hub.Hub

PoweredUp Remote class

class bricknil.hub.BoostHub(name, query_port_info=False, ble_id=None)[source]

Bases: bricknil.hub.Hub

Boost Move Hub

class bricknil.hub.DuploTrainHub(name, query_port_info=False, ble_id=None)[source]

Bases: bricknil.hub.Hub

Duplo Steam train and Cargo Train

This is hub is found in Lego sets 10874 and 10875

class bricknil.hub.CPlusHub(name, query_port_info=False, ble_id=None)[source]

Bases: bricknil.hub.Hub

Technic Control+ Hub