【发布时间】:2022-12-09 14:36:13
【问题描述】:
我正在使用适用于 esp32 的 micropython 来使用 aioble 库制作 BLE 应用程序。我正在按照示例代码使用 + 从库中添加,但我面临这个问题并且不明白为什么。是因为图书馆有问题吗?我按照github上的说明操作了,还是报错,无法处理
import sys
sys.path.append("")
from micropython import const
import uasyncio as asyncio
import aioble
import bluetooth
SERVICE_UUID = bluetooth.UUID('00001800-0000-1000-8000-00805F9B34FB')
mtu_connect = 0
async def find_temp_sensor():
# Scan for 5 seconds, in active mode, with very low interval/window (to
# maximise detection rate).
async with aioble.scan(10000, interval_us=12000, window_us=10000, active=True) as scanner:
async for result in scanner:
# See if it matches our name and the environmental sensing service.
print(result, result.name(), result.rssi, result.services())
if result.name() == "70001697":
return result.device
return None
async def main():
device = await find_temp_sensor()
while not device:
print("Temperature sensor not found")
device = await find_temp_sensor()
return
print(device)
mtu_connect = 0
while mtu_connect < 3:
try:
print("Connecting to", device)
connection = await device.connect()
service = await connection.service(SERVICE_UUID)
print("service", service.uuid)
# Discover characteristics.
uuids = []
async for char in service.characteristics():
uuids.append(char.uuid)
print("found", sorted(uuids))
print("Connecting done!")
break
except asyncio.TimeoutError:
print("Timeout during connection")
mtu_connect = mtu_connect + 1
asyncio.run(main())
【问题讨论】:
标签: python python-3.x bluetooth-lowenergy micropython aio