example: Add async example of GATT interface - #5
Conversation
|
Hello @kawasaki Thank you for submitting pull request. Let me review the code. |
| # Clean up | ||
| await device.disconnect() | ||
|
|
||
| run(main()) |
There was a problem hiding this comment.
Do you mind putting this function call under if __name__ == "__main__":. It is considered a good practice. (also the if len(sys.argv) < 2:)
| from typing import Any | ||
|
|
||
| from sdbus import SdBus, sd_bus_open_system | ||
| from sdbus.dbus_proxy_async_interfaces import DbusIntrospectableAsync |
There was a problem hiding this comment.
By the way the DbusInterfaceCommonAsync inherits from DbusIntrospectableAsync and does not need to be imported from private internal module.
|
Thanks for the review! Will rework the code next weekend. |
Add an example script which shows properties of services and
characteristics that the specified BLE device provides.
I confirmed this script using micro:bit with Scratch HEX installed.
$ python examples/sdbus_async/gatt_props.py XX:XX:XX:XX:XX:XX
Wait discovery for 5 seconds
Conneting to /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX...
Conneted
Find services...
service0008
service000c
service0013
=============================================
service: service0008
UUID: 00001801-0000-1000-8000-00805f9b34fb
device: /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX
primary: True
includes paths: []
missing propeties: ['handle']
char0009
UUID: 00002a05-0000-1000-8000-00805f9b34fb
service: /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/service0008
value: b''
flags: ['indicate']
notifying: False
MTU: 23
missing propeties: ['write acquired', 'notify acquired', 'handle']
=============================================
...
Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
|
I've reflected your comments and also avoided two global variables, DEV_ADDR and DEV_PATH. Thanks again for the comments. It looks better :) |
| for service in services: | ||
| await print_service_props(dbus, dev_path, service) | ||
| break | ||
| await sleep(1) |
There was a problem hiding this comment.
Isn't this an unreachable code because of break?
There was a problem hiding this comment.
My bad, the next line "await sleep(1)" has extra indent... Will create another pull request to fix it.
|
Thank you! |
Hello @igo95862,
Recently, I wrote a simple python script and confirmed that python-sdbus-bluez works with BLE (Bluetooth Low Energy) device as expected. I suggest to add the script to python-sdbus-bluez as another example. Could you take a look in it?