如何解决我尝试在 XBee micropython 中使用 NOTIFY 属性接收 BLE 特性值,但我只接收空字节
我可以将 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 和 here's an example using it(使用 Thunderboard 设备,但这是一个起点)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。