`I am trying to scan for devices advertising the UART service using Micropython on esp32. but I get AttributeError: 'NoneType' object has no attribute 'scan'
below is my code:
# Initialize and enable the BLE radio.
ble = ubluetooth.BLE()
ble.active(True)
# Create a BLE scanner object.
scanner = ble.gap_scan(10, 30000, 30000)
# Scan for devices advertising the UART service.
print('Scanning for devices advertising the UART service...')
devices = scanner.scan(10)
# Connect to the first device with the matching UART service UUID.
for device in devices:
for advertised_service in device.services:
if advertised_service.uuid == UART_SERVICE_UUID:
# Connect to the device.
print(f'Connecting to device {device.name}...')
connection = ble.connect(device)
# Wait for the connection to be established.
while not connection.is_connected:
pass
print('Connection established!')
# Stop scanning.
scanner.stop()
break
if connection.is_connected:
break
`