Replies: 2 comments 6 replies
-
import asyncio
from bleak import BleakScanner, BleakClient
import objc
from Foundation import NSBundle
async def scan_and_connect():
devices = await BleakScanner.discover()
print("Available devices:")
for i, device in enumerate(devices):
print(f"{i + 1}. {device.name} [{device.address}]")
device_index = int(input("Select device to connect (enter index): ")) - 1
selected_device = devices[device_index]
async with BleakClient(selected_device.address) as client:
try:
if await client.is_connected(): An exception would be thrown on the print(f"Connected to {selected_device.name} [{selected_device.address}]")
services = await client.get_services()
print("Services and Characteristics:")
for service in services:
print(f"Service: {service.uuid}")
for char in service.characteristics:
print(f" Characteristic: {char.uuid}, Properties: {char.properties}")
char_uuid = "af0badb1-5b99-43cd-917a-a77bc549e3cc"
await client.write_gatt_descriptor(char_uuid, b"\x41", response=True) I think this should be value = await client.read_gatt_char(char_uuid)
print("I/O Config Post-Write Value: {0}".format(value))
else:
print(f"Failed to connect to {selected_device.name}")
except Exception as e:
print(f"Failed to connect to {selected_device.name}: {e}")
async def main():
await scan_and_connect()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main()) Better to use |
Beta Was this translation helpful? Give feedback.
0 replies
-
I have also tried with write_gatt_char but the result is not better |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I tried writing char but got the following error
"Failed to connect to iPhone: Failed to write characteristic 21: Error Domain=CBATTErrorDomain Code=6 "The request is not supported." UserInfo={NSLocalizedDescription=The request is not supported.}"
Please check the main file I have attached with the code content
main.txt
Beta Was this translation helpful? Give feedback.
All reactions