【问题标题】:how to use and debug micropython-aioble library for esp32?如何使用和调试 esp32 的 micropython-aioble 库?
【发布时间】: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


    【解决方案1】:

    我尝试了所有方法来修复它,但问题是所有处理它的方法只有 1 个常见错误,我不知道是不是因为库的原因。它显示为已连接,但当我浏览列表时出现错误。

    Traceback (most recent call last):
      File "<stdin>", line 64, in <module>
      File "uasyncio/core.py", line 1, in run
      File "uasyncio/core.py", line 1, in run_until_complete
      File "uasyncio/core.py", line 1, in run_until_complete
      File "<stdin>", line 45, in main
      File "/lib/aioble/device.py", line 238, in service
      File "/lib/aioble/client.py", line 127, in __anext__
      File "/lib/aioble/client.py", line 119, in _start
      File "/lib/aioble/client.py", line 192, in _start_discovery
    TypeError: can't convert NoneType to int
    

    【讨论】:

      猜你喜欢
      • 2021-07-29
      • 2021-05-03
      • 1970-01-01
      • 2022-12-24
      • 2018-12-28
      • 2021-05-28
      • 1970-01-01
      • 2021-03-29
      • 2021-08-01
      相关资源
      最近更新 更多