Created
May 31, 2022 18:43
-
-
Save keshuaixu/e67efc2d2a14ed91c6bc1bba12ae2e6b to your computer and use it in GitHub Desktop.
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
import asyncio | |
import struct | |
from bleak import BleakScanner | |
from bleak import BleakClient | |
pot_uuids = [f'babb122c-de4c-11ec-9d64-0242ac12000{i}' for i in range(1,9)] | |
time_uuid = 'babb122c-de4c-11ec-9d64-0242ac120102' | |
all_pots_uuid = 'babb122c-de4c-11ec-9d64-0242ac120200' | |
async def main(): | |
device = await BleakScanner.find_device_by_filter( | |
lambda d, ad: d.name and d.name.lower() == 'dVRK SUJ'.lower() | |
) | |
if device is None: | |
print('cannot find the dESSJ') | |
exit(-1) | |
async with BleakClient(device) as client: | |
print(f'Connected: {client.is_connected}. Address: {device.address}.') | |
while 1: | |
pot_values = [] | |
for pot_uuid in pot_uuids: | |
raw = await client.read_gatt_char(pot_uuid) | |
# print(raw) | |
parsed = struct.unpack('<H', raw)[0] # uint16, little endian | |
pot_values.append(parsed) | |
print(pot_values) | |
# raw = await client.read_gatt_char(all_pots_uuid) | |
# parsed = struct.unpack('<8H', raw) # uint16, little endian | |
# print(parsed) | |
if __name__ == "__main__": | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment