我试图在XBee micropython中使用NOTIFY属性接收BLE特征值,但我只接收空字节
我可以将BLE设备与我的XBee 3设备连接,但在连接后,在尝试通过gattc_read_characteristic()方法接收数据时,它以空字节接收。但我可以在我的android手机应用程序中接收数据。请给我一些解决办法 这是mycode我试图在XBee micropython中使用NOTIFY属性接收BLE特征值,但我只接收空字节,python,bluetooth-lowenergy,xbee,micropython,Python,Bluetooth Lowenergy,Xbee,Micropython,我可以将BLE设备与我的XBee 3设备连接,但在连接后,在尝试通过gattc_read_characteristic()方法接收数据时,它以空字节接收。但我可以在我的android手机应用程序中接收数据。请给我一些解决办法 这是mycode import binascii from digi import ble def get_characteristics_from_uuids(connection, service_uuid, characteristic_uuid): se
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)
如果我理解的一切都是正确的,那么您试图从一个只支持notify的特性中读取。(根据,该特性只有notify。)
您想调用
gattc\u configure
以启用通知并设置对该特性的回调,而且(使用Thunderboard设备,但这是一个起点)。如果我对所有事情都理解正确,那么您尝试读取的是仅支持notify的特性。(根据,该特性只有notify。)
您想调用
gattc\u configure
以启用通知并设置对该特性的回调,还有(使用Thunderboard设备,但这是一个起点)。非常感谢您,这台设备对我很有用。。在gattc_configure()中添加回调方法后。非常感谢您,这一方法对我来说非常有效。。在gattc_configure()中添加回调方法后。