-1

I am using micropython for esp32 to make BLE app using aioble library.i am using as per sample code + add from library but i am facing this problem and don't understand why. Is it because the library is having problems?. I have followed the instructions on github but the error still occurs, I can't handle it

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())

2 Answers2

0

You need to specify the actual error message to get some help. Note that you need to put on your microcontroller the aioble library files (typically under lib/aioble) as aioble is not part of the standard micropython firmware.

Pascal
  • 116
  • 8
0

You need to import aioble using mip. See the user instructions on installation with mpremote. It cannot be done through thonny.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 31 '23 at 17:15