我试图在 XBee micropython 中使用 NOTIFY 属性 接收 BLE 特性值,但我只接收空字节

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

我可以将 BLE 设备与我的 XBee 3 设备连接,但是在尝试通过 gattc_read_characteristic() 方法接收数据时连接后,它接收的是空字节。但我可以在我的 android 移动应用程序中接收数据。请给我一些解决方案!

这是我的代码。

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)

如果我没有理解错,那么您正在尝试 读取 仅支持通知的特性。 (根据this Microchip forum post,该特性只有通知。)

您想调用 gattc_configure 以启用通知并设置该特征的回调。 Here are the typehints for gattc_configure, and here's an example using it(使用 Thunderboard 设备,但这是一个起点)。