Part Number:CC2642R
使用6843AOP蓝牙模式,具体如下
1,通过python写了一个脚本来接收蓝牙数据,如下,开始的时间才0.1s级别,之后就1-2s级别,导致不能及时接收到数据(即表现为不能接收到每一帧的数据),导致这样的原因是什么
python脚本程序如下
import asyncio import binascii import bleak import time async def run():# 定义你的 Simple Peripheral 设备的 UUID 和 characteristic UUIDsimple_peripheral_uuid = "58:53:03:B8:93:85"characteristic_uuid = "0000fff1-0000-1000-8000-00805f9b34fb"# 创建一个缓冲区来存储接收到的数据data_buffer = bytearray()# 连接到 Simple Peripheral 设备async with bleak.BleakClient(simple_peripheral_uuid) as client:while True:start_time = time.time() # 记录开始时间# 读取 characteristic 的值value = await client.read_gatt_char(characteristic_uuid)hex_value = binascii.hexlify(value).decode('utf-8') # 将16进制数据转换为十六进制字符串print(f"Received data: {hex_value}, Timestamp: {time.time()}")# 计算数据接收的时间间隔end_time = time.time()time_diff = end_time - start_timeprint(f"Time interval: {time_diff}") loop = asyncio.get_event_loop() loop.run_until_complete(run())
输出如下:
Received data: ea, Timestamp: 1703747388.7936957
Time interval: 0.13491177558898926
Received data: eb, Timestamp: 1703747388.89803
Time interval: 0.10433435440063477
Received data: ec, Timestamp: 1703747389.0213535
Time interval: 0.12332344055175781
Received data: ec, Timestamp: 1703747389.1479049
Time interval: 0.12655138969421387
Received data: ed, Timestamp: 1703747389.2683158
Time interval: 0.12041091918945312
Received data: ed, Timestamp: 1703747389.389125
Time interval: 0.12080931663513184
Received data: ee, Timestamp: 1703747389.4953651
Time interval: 0.10624003410339355
Received data: ef, Timestamp: 1703747389.6293945
Time interval: 0.13402938842773438
Received data: ef, Timestamp: 1703747389.7480822
Time interval: 0.11868762969970703
Received data: f0, Timestamp: 1703747389.8582203
Time interval: 0.1101381778717041
Received data: f0, Timestamp: 1703747389.9894485
Time interval: 0.13122820854187012
Received data: f1, Timestamp: 1703747390.0999336
Time interval: 0.11048507690429688
Received data: f2, Timestamp: 1703747390.231091
Time interval: 0.13115739822387695
Received data: f2, Timestamp: 1703747390.3394058
Time interval: 0.10831475257873535
Received data: f3, Timestamp: 1703747390.463464
Time interval: 0.12405824661254883
Received data: f3, Timestamp: 1703747390.5894291
Time interval: 0.12596511840820312
Received data: f4, Timestamp: 1703747390.7009616
Time interval: 0.11153244972229004
Received data: f5, Timestamp: 1703747390.8267455
Time interval: 0.12578392028808594
Received data: fa, Timestamp: 1703747392.819329
Time interval: 1.9925835132598877
Received data: 04, Timestamp: 1703747394.8199818
Time interval: 2.00065279006958
Received data: 0e, Timestamp: 1703747396.8081524
Time interval: 1.994560956954956
2,通过连接AOP的帧来接收蓝牙的输出数据,用TTL转USB的串口器连接下图的RX,TX,接收到的数据是连续的,即可以接收到每一帧的数据
Galaxy Yue:
您好,
1.增加缓冲区的太小,可以减少接收数据的时间间隔
将data_buffer()的大小从bytearray()改成bytearray(1024)试试
2.可以用pygatt 或 bluepy 其他蓝牙库试一试