我可以将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)发布于 2021-05-20 20:04:27
如果我对每件事都理解正确,你就会试图从一个只支持通知的特性中读取信息。(根据这个微芯片论坛帖子的说法,这种特征只有通知。)
您希望调用gattc_configure来启用通知,并根据该特性设置回调。配置和下面是一个使用它的例子 (带有雷电设备,但这是一个起点)。
https://stackoverflow.com/questions/67619253
复制相似问题