I am sure that I am missing something obvious, but when I try directly connecting to a specific service on my BLE device, the device locks up and will not connect. It works when using the BL CLient Connect and Discover example but will not work when I use the example to supply it the specific UUID (BL Client Read and Write). Has anybody run into this or does anybody has any suggestions?
Thanks in advance!
Here is my code:
import binascii
import struct
import time
from digi import ble
def get_characteristics_from_uuids(connection, s_uuid, c_uuid):
print("in loop")
services = list(connection.gattc_services(s_uuid))
print("got services")
if len(services):
# Assume that there is only one service per UUID, take the first one
my_service = services[0]
characteristics = list(connection.gattc_characteristics(my_service, c_uuid))
return characteristics
# Couldn't find specified characteristic, return an empty list
return []
TEST_ADDRESS = "24:0a:c4:00:00:01"
address_type = ble.ADDR_TYPE_PUBLIC
# Put address into bytes object (without colons)
address = binascii.unhexlify(TEST_ADDRESS.replace(':', ''))
# The service and characteristic UUIDs
service_uuid = 0xDEAD
characteristic_uuid = 0xBEEF
ble.active(True)
print("Attempting connection to: {}".format(TEST_ADDRESS))
with ble.gap_connect(address_type, address) as conn:
print("connected")
service = list(conn.gattc_services(service_uuid))
print("Service", service)
# There is only one temperature service and characteristic, so use the first and only one in the list
characteristic = get_characteristics_from_uuids(conn, service_uuid, characteristic_uuid)[0]
while True:
value = conn.gattc_read_characteristic(characteristic)
print("Value is", value)