Repository navigation
pb connect connects the hub chosen with pb use - #13
Merged
Merged
Conversation
A hub's type is in its scan response, as the PnP ID in service data, and the scan response arrives after the advertisement. A hub reported on its advertisement alone was listed without a type, and the picker showed it as a row of its own. Seen on Windows with a City hub. A sighting without a PnP ID is now passed over until one with it comes. Every Pybricks firmware sends one, so a hub that still has not after SCAN_RESPONSE_SECONDS has a firmware bug: it is logged, once per scan, and not listed. Tested with bleak's scanner replaced by one that replays advertisements.
dlech
force-pushed
the
connect-honors-use
branch
from
November 24, 2026 00:14
53284ec to
fb91f1b
Compare
A real hub advertises only every so often, so one switched on beside another may be heard a second after it. Simulated hubs were all heard the moment a search began, which hides anything that decides too soon. FakeHub.heard_after says how far into a search the hub is first heard. It defaults to at once, so nothing that uses a simulated hub changes.
…hosen with pb use pb connect with no --hub went to whichever hub answered first, or to one already connected, even with another hub chosen with pb use. Every other command acts on the chosen hub, so a user ended up with one hub chosen and a different one connected. hub.connect with nothing named now goes to the chosen hub if there is one; otherwise to one already connected; otherwise to the only hub found. A chosen hub that is not found is named in the error, with the name in its data too, and pb connect says how to choose another with pb use. Several hubs and nothing to say which is refused with the new HUB_AMBIGUOUS, which lists them, rather than guessed at. That includes several sharing the name asked for or chosen, as every hub flashed without a name does. pb connect then asks which, in a terminal, and says how to tell them apart without one. - Two ids on one transport are two hubs, and so are two names on any. One hub on a cable and over Bluetooth has an id each way, but the same name. - A hub only paired over RFCOMM, which lists the paired set switched on or not, counts and is chosen only when no other transport heard one, and pb connect does not offer it then either. - To hear a second hub at all, a search without an id listens for AMBIGUITY_SECONDS, 1 s, after the first hub heard, on USB as well. A City hub was measured advertising up to a second apart on Windows. A paired hub instead waits up to PAIRED_SECONDS, 3 s, for one to be heard, since Bluetooth takes a moment to start. Waiting on a permission dialog still moves the end of the search later. A connected hub with the name asked for or chosen, or the connected one when nothing is named, is that hub: a connected hub has stopped advertising, so a search would pass it by and connect another hub with the same name. It is handed back unless another transport is asked for, and refused when exclusive. hub.connect says whether the hub was connected already, as already_connected, and pb connect says "Already connected" rather than claiming to have connected it. PROTOCOL_VERSION and MIN_PROTOCOL_VERSION are 4: a client of 3 does not know HUB_AMBIGUOUS. pb connect also escapes the hub names it prints with rich markup, which "Connected to ..." did not before. Tried on Windows with a Prime hub and a City hub, both named Pybricks Hub: asked which with the name chosen, with nothing chosen and with --hub, said Already connected for the connected one by choice and by --hub while the other advertised, and named the chosen hub when both were off. Fixes: pybricks/support#2866
dlech
force-pushed
the
connect-honors-use
branch
from
November 24, 2026 01:38
cf333fd to
21bad7a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pb connect with no --hub went to whichever hub answered first, or to one
already connected, even with another hub chosen with pb use. Every other
command acts on the chosen hub, so a user ended up with one hub chosen
and a different one connected.
hub.connect with nothing named now goes to the chosen hub if there is
one; otherwise to one already connected; otherwise to the only hub
found. A chosen hub that is not found is named in the error, with the
name in its data too, and pb connect says how to choose another with
pb use.
Several hubs and nothing to say which is refused with the new
HUB_AMBIGUOUS, which lists them, rather than guessed at. That includes
several sharing the name asked for or chosen, as every hub flashed
without a name does. pb connect then asks which, in a terminal, and
says how to tell them apart without one.
One hub on a cable and over Bluetooth has an id each way, but the
same name.
or not, counts and is chosen only when no other transport heard one,
and pb connect does not offer it then either.
AMBIGUITY_SECONDS, 1 s, after the first hub heard, on USB as well. A
City hub was measured advertising up to a second apart on Windows. A
paired hub instead waits up to PAIRED_SECONDS, 3 s, for one to be
heard, since Bluetooth takes a moment to start. Waiting on a
permission dialog still moves the end of the search later.
A connected hub with the name asked for or chosen, or the connected one
when nothing is named, is that hub: a connected hub has stopped
advertising, so a search would pass it by and connect another hub with
the same name. It is handed back unless another transport is asked for,
and refused when exclusive. hub.connect says whether the hub was
connected already, as already_connected, and pb connect says "Already
connected" rather than claiming to have connected it.
PROTOCOL_VERSION and MIN_PROTOCOL_VERSION are 4: a client of 3 does not
know HUB_AMBIGUOUS. pb connect also escapes the hub names it prints
with rich markup, which "Connected to ..." did not before.
Tried on Windows with a Prime hub and a City hub, both named Pybricks
Hub: asked which with the name chosen, with nothing chosen and with
--hub, said Already connected for the connected one by choice and by
--hub while the other advertised, and named the chosen hub when both
were off.
Fixes pybricks/support#2866