Skip to content

Conversation

@wwj718
Copy link

@wwj718 wwj718 commented May 3, 2021

use cases from the documentation:

# Run script on the first device we find called Pybricks hub
pybricksdev run ble "Pybricks Hub" demo/shortdemo.py

# Run script on device with address 90:84:2B:4A:2B:75 (doesn't work on Mac)
pybricksdev run ble 90:84:2B:4A:2B:75 demo/shortdemo.py

work on Mac!

Copy link
Member

@dlech dlech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

I have made some suggestions. Please have a look.


print("Connecting to", device)
self.client = BleakClient(device)
self.client = BleakClient(device.address)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By passing the address instead of device object will cause Bleak to have to scan for the device again. This would make connections much slower.

if device.name != name:
if device_or_address in [device.name, device.address]:
queue.put_nowait(device)
else:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else: return is not needed since there is nothing in the function after this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is ok

" address = await find_device('Pybricks Hub', timeout=5)\n",
" await hub.connect(address)\n",
" device = await find_device('Pybricks Hub', timeout=5)\n",
" await hub.connect(device.address)\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be device and not device.address?

async def find_device(name: str, timeout: float = 5) -> BLEDevice:
"""Quickly find BLE device address by friendly device name.
async def find_device(device_or_address: str, timeout: float = 5) -> BLEDevice:
"""Quickly find BLE device address by friendly device name or address.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also mention that "address" does not work on macOS. Instead, macOS assigns each device a UUID that has to be used instead of the Bluetooth address.

Device was not found within the timeout.
"""
print("Searching for {0}".format(name))
print("Searching for {0}".format(device_or_address))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we need to make some other changes anyway, we could change this to:

Suggested change
print("Searching for {0}".format(device_or_address))
print(f"Searching for {device_or_address}")

@dlech dlech force-pushed the master branch 2 times, most recently from edc8734 to 069206f Compare May 17, 2021 20:58
@dlech
Copy link
Member

dlech commented May 18, 2021

This should be fixed in v1.0.0-alpha.8.

@dlech dlech closed this May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants