pythonbluetooth-lowenergyxbeemicropython

I tried to receive the BLE characteristics value with NOTIFY property in XBee micropython, But iam receiving only empty bytes


I can connect the BLE device with my XBee 3 device, but after connecting while trying to receive data through gattc_read_characteristic() method, it is receiving as empty bytes. But i can receive the data in my android mobile app. Please give me some solution !

Here is mycode.

import binascii
from digi import ble


def get_characteristics_from_uuids(connection, service_uuid, characteristic_uuid):
    services = list(connection.gattc_services(service_uuid))
    if len(services):
        my_service = services[0]
        print(my_service)
        characteristics = list(connection.gattc_characteristics(my_service, characteristic_uuid))
        print(characteristics)
        return characteristics
    return []


BLE_MAC_ADDRESS = "00:A0:50:F4:D8:8B"
address_type = ble.ADDR_TYPE_PUBLIC

address = binascii.unhexlify(BLE_MAC_ADDRESS.replace(':', ''))
environment_service_uuid = '49535343-fe7d-4ae5-8fa9-9fafd205e455'
oxi_characteristic_uuid = '49535343-1e4d-4bd9-ba61-23c647249616' 
oxi_descriptor_uuid = 0x2902

ble.active(True)
print("Attempting connection to: {}".format(BLE_MAC_ADDRESS))


with ble.gap_connect(address_type, address) as conn:
    print("connected")
    oxy_characteristic = get_characteristics_from_uuids(conn, environment_service_uuid, oxi_characteristic_uuid)[0]
    descriptors = list(conn.gattc_descriptors(oxy_characteristic))
    oxy_descriptor = descriptors[0]
    conn.gattc_write_descriptor(oxy_descriptor, b'11')
    print(oxy_characteristic)
    print(oxy_descriptor)
    ble.
    if oxy_characteristic is None:
        print("Did not find the OXI characteristic")
    else:
        while True:
            oxi_data = conn.gattc_read_characteristic(oxy_characteristic)
            print(oxi_data)

Solution

  • If I'm understanding everything right, you're trying to read from a characteristic which only supports notify. (According to this Microchip forum post, that characteristic only has notify.)

    You want to call gattc_configure to enable notifications and set up a callback on that characteristic. Here are the typehints for gattc_configure, and here's an example using it (with a Thunderboard device, but it's a starting point).