Remote hub (BLE client)
hub is a BLE client for another LEGO Powered-Up / Control+
hub. It handles the NimBLE scan/connect state machine, mirrors the
remote hub’s ports as port objects, and exposes hub
properties.
Basic pattern
import lpf2, time
remote = lpf2.hub()
remote.init() # scan indefinitely
# remote.init("aa:bb:cc:dd:ee:ff") # target a specific MAC
# remote.init(scan_duration=30) # bounded scan
while not remote.isConnected():
time.sleep_ms(10)
while not remote.infoReady():
time.sleep_ms(10)
print(remote.getName(), remote.getHubAddress())
print(remote.getAllInfoStr())
The C firmware polls hub.update() in the background — it
pumps BLE and dispatches inbound LWP messages, so scripts can wait
on isConnected() / infoReady() without pumping
anything manually. See Automatic polling.
Ports on the remote hub
p = remote.getPort(lpf2.port_num.poweredup.A)
if p is not None:
p.setMode(0) # request notifications on mode 0
Values arrive through the normal port.getValue() path once
notifications start.
Manual port configuration
For non-standard mode setups:
remote.setPortMode(port_num=0, mode=0, delta=1, notify=True)
# Combined-mode input format:
remote.setPortModeCombo(
port_num=0,
combo_idx=0,
nibble_pairs=[0x00, 0x10], # mode0/ds0, mode1/ds0
deltas_per_mode=[1, 1],
)
Hub properties
remote.getBatteryType()
remote.getHubType()
remote.setName("MyHub")
print(remote.getHubPropStr(lpf2.hub_property.NAME))
State flags
infoReady()— true once initial hub-property + port- info requests have completed (or timed out).
Shutdown
remote.shutDownHub() # send LWP shutdown to the remote hub
Reference: lpf2.hub, lpf2.hub_type,
lpf2.hub_property, lpf2.port_num.