Skip to content

[Bug] movehub at stable v4.0.1 firmware does not broadcast if PC connected #2826

Closed
pybricks/pybricks-micropython
#504

Description

@BertLindeman

Describe the bug
A Move Hub running Pybricks v4.0.1 does no BLE broadcasting when it is connected to a PC via BLE.

The same program works correctly when the Move Hub is running standalone.

A City Hub running the same firmware and the same broadcast program, broadcasts correctly while connected to a PC.

The Move Hub can still observe broadcasts while connected to the PC.

To reproduce
Steps to reproduce the behavior:

  1. BLE connect the movehub with FW v4.0.1 to a PC
  2. Run the example broadcast program (see below) on the movehub
  3. run on any other hub the observe program
  4. look at the color of the observer hub:
    • GREEN = broadcast received
    • RED = no broadcast received

Repeat without the PC BLE connection.

In that case the Move Hub broadcasts correctly and the observer shows GREEN.

Expected behavior
BLE broadcasting should continue while the hub has an active PC connection.

If broadcasting is intentionally disabled while connected, this should be documented and/or indicated to the application and raise some kind of error..

Additional information

  • Move Hub: Pybricks v4.0.1

  • City Hub: Pybricks v4.0.1 - broadcasting works with PC connected.

  • Move Hub observing: works both with and without a PC connection.

  • The same behavior was also reproduced with the firmware built for drv/bluetooth: Scan at a 50% duty cycle so broadcasting works. pybricks-micropython#500.

  • A separate passive BLE scanner running on a Raspberry Pi Pico 2 W confirms that the Move Hub's LEGO manufacturer-data advertisements disappear when the PC BLE connection is active.
    This does not appear to be an issue in BLERadio.observe() on the receiving hub.

broadcast script
from pybricks.messaging import BLERadio
from pybricks.parameters import Port
from pybricks.pupdevices import Motor
from pybricks.tools import wait

# Initialize the hub.
radio = BLERadio(broadcast_channel=1)

# Initialize the motors.
left_motor = Motor(Port.A)
right_motor = Motor(Port.B)

while True:
    # Read the motor angles to be sent to the other hub.
    left_angle = left_motor.angle()
    right_angle = right_motor.angle()

    # Set the broadcast data and start broadcasting if not already doing so.
    data = (left_angle, right_angle)
    # print(data)
    wait(10)  # needed due to https://github.com/pybricks/support/issues/2751
    radio.broadcast(data)

    # Broadcasts are only sent every 100 milliseconds, so there is no reason
    # to call the broadcast() method more often than that.
    wait(100)
observe script
from pybricks.hubs import ThisHub
from pybricks.messaging import BLERadio
from pybricks.parameters import Color
from pybricks.tools import wait

# Run this on the hub that is OBSERVING.
hub = ThisHub()
radio = BLERadio(observe_channels=[1])

while True:
    data = radio.observe(1)
    hub.light.on(Color.GREEN if data is not None else Color.RED)
    wait(100)
ble_sniffer_simple.py
"""
ble_sniffer_simple.py
Minimal passive BLE scanner for Pico 2 W (MicroPython) to prove whether a
Pybricks hub is broadcasting (LEGO manufacturer data, company ID 0x0397).
Same script works unmodified for any hub - flash a hub with Pybricks
v4.0.1, start its broadcast program, run this, and watch for output.

No external dependencies - the LEGO manufacturer ID check (company ID
0x0397, i.e. bytes 151, 3) is inlined below.
"""
import time

import bluetooth
from micropython import const

_IRQ_SCAN_RESULT = const(5)
_ADV_TYPE_MANUFACTURER_DATA = const(0xFF)


def _is_lego(manu):
    try:
        return manu[2] == 151 and manu[3] == 3
    except IndexError:
        return False

_count = 0
_stop = False
_start_ms = time.ticks_ms()


def _find_adv_structure(payload, adv_type):
    i = 0
    n = len(payload)
    while i + 1 < n:
        length = payload[i]
        if length == 0:
            break
        if payload[i + 1] == adv_type:
            return bytes(payload[i:i + 1 + length])
        i += 1 + length
    return None


def _bt_irq(event, data):
    global _count, _stop
    try:
        if event == _IRQ_SCAN_RESULT:
            _, _, _, _, adv_data = data
            manu = _find_adv_structure(adv_data, _ADV_TYPE_MANUFACTURER_DATA)
            if manu and _is_lego(manu):
                channel = manu[4]
                _count += 1
                elapsed = time.ticks_diff(time.ticks_ms(), _start_ms)
                print("{:6d}ms  channel {}  count {}".format(elapsed, channel, _count))
    except KeyboardInterrupt:
        # Ctrl-C can land here instead of in the main loop's sleep_ms();
        # without this it's swallowed and the summary below never runs.
        _stop = True


ble = bluetooth.BLE()
ble.active(True)
ble.irq(_bt_irq)

print("Scanning for Pybricks LEGO broadcasts (Ctrl-C to stop)...")
ble.gap_scan(0, 30000, 30000, False)  # continuous, passive

try:
    while not _stop:
        time.sleep_ms(500)
except KeyboardInterrupt:
    pass
finally:
    ble.gap_scan(None)
    ble.active(False)
    elapsed_s = time.ticks_diff(time.ticks_ms(), _start_ms) / 1000
    print()
    if _count:
        print("RESULT: {} LEGO broadcast packets in {:.1f}s -> Received broadcasts".format(_count, elapsed_s))
    else:
        print("RESULT: 0 LEGO broadcast packets in {:.1f}s -> NO broadcast received".format(elapsed_s))

Activity

  1. added
    triage
    on Sep 10, 2026
  2. dlech commented on Sep 10, 2026

    @dlech
    Member

    I think this has long been a known issue / technical limitation of the move hub. Hopefully we documented that somewhere. And it used to raise an exception at one time but that was removed in pybricks/pybricks-micropython@0c7da32.

  3. BertLindeman commented on Sep 10, 2026

    @BertLindeman
    Author

    Could not find the doc and asked a few AI assistents do they couldn't either.

  4. dlech commented on Sep 10, 2026

    @dlech
    Member

    #1819 😄

  5. dlech commented on Sep 10, 2026

    @dlech
    Member

    If we aren't going to raise an exception, maybe we should do something like Python warnings and print a message to stdout.

  6. BertLindeman commented on Sep 10, 2026

    @BertLindeman
    Author

    If we aren't going to raise an exception, maybe we should do something like Python warnings and print a message to stdout.

    Agree.
    And your memory is better than mine.

  7. dlech commented on Sep 10, 2026

    @dlech
    Member

    I didn't remember it either. 😉

  8. added
    topic: bluetooth
    software: pybricks-micropython
    and removed
    triage
    on Sep 12, 2026
  9. dlech commented on Sep 12, 2026

    @dlech
    Member

    Well, it turns out that it is technically possible to broadcast while connected after all. We just have to bypass the vendor-specific commands and go with direct HCI commands similar to what we did on technic/city hubs. The interval gets even worse, more like 200ms, but I suppose that is better than nothing.

  10. BertLindeman commented on Sep 12, 2026

    @BertLindeman
    Author

    The interval gets even worse, more like 200ms, but I suppose that is better than nothing.

    Silently not transmitting is a horrible debug situation. Slow transmitting is very acceptable on a movehub.
    Great work David.

  11. BertLindeman commented on Sep 12, 2026

    @BertLindeman
    Author

    And sure it works!
    Can be closed after merge into master. I'll test, sure 😄 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    software: pybricks-micropythontopic: bluetooth

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions