如何使用和调试esp 32中micropython-aoble库?

r1zhe5dt  于 2023-01-06  发布在  Python
关注(0)|答案(1)|浏览(365)

我正在使用micropython for esp32来制作使用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())
bwitn5fc

bwitn5fc1#

你需要指定实际的错误信息来获得一些帮助。注意你需要在你的微控制器上放上aioble库文件(通常在lib/aioble下),因为aioble不是标准micropython固件的一部分。

相关问题