Metro m4 AirLift Lite as BLE server

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
PierreDeQuebec
 
Posts: 96
Joined: Sun Jul 25, 2021 3:26 pm

Metro m4 AirLift Lite as BLE server

Post by PierreDeQuebec »

Hello,
I am trying to use my Metro m4 AirLift Lite microcontroller as a BLE server. My goal is to connect to a GoPro camera via a BLE connection and synchronize the camera clock with the clock on my GPS shield. I am using the following code to test the BLE functionality of my microcontroller.

Code: Select all

# coding: utf8
#ble_search_gopro.py

# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# This example scans for any BLE advertisements and prints one advertisement and one scan response
# from every device found. This scan is more detailed than the simple test because it includes
# specialty advertising types.

from adafruit_ble import BLERadio

from adafruit_ble.advertising import Advertisement
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService
from adafruit_airlift.esp32 import ESP32

esp32 = ESP32()
adapter = esp32.start_bluetooth()

ble = BLERadio(adapter)
uart_server = UARTService()
advertisement = ProvideServicesAdvertisement(uart_server)

print("scanning")
found = set()
scan_responses = set()
# By providing Advertisement as well we include everything, not just specific advertisements.
# Advertisement

for advertisement in ble.start_scan(ProvideServicesAdvertisement):
    addr = advertisement.address
    if advertisement.scan_response and addr not in scan_responses:
        scan_responses.add(addr)
    elif not advertisement.scan_response and addr not in found:
        found.add(addr)
    else:
        continue
    print(addr, advertisement)
    print("\t" + repr(advertisement))
    print()

print("scan done")
At runtime, I get the following message:

Code: Select all

scanning
Traceback (appels les plus récents en dernier) :
  Fichier "code.py", ligne 31, dans <module>
  Fichier "adafruit_ble/__init__.py", ligne 250, dans start_scan
NotImplementedError: 
Line 31 is the line in the 'for' loop. Line 251 refers to the start_scan () method in __init__ of the BLERadio module.

Obviously, CircuitPython results in a non-implemented method. But which? First question: Can the microcontroller and its library allow to implement a BLE server? If so, what is wrong with my code?

Thank you.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Metro m4 AirLift Lite as BLE server

Post by adafruit_support_mike »

CircuitPython can only run an AirLift as a BLE peripheral, not as a BLE central. The .start_scan() method on line 31 only works for central devices.

User avatar
PierreDeQuebec
 
Posts: 96
Joined: Sun Jul 25, 2021 3:26 pm

Re: Metro m4 AirLift Lite as BLE server

Post by PierreDeQuebec »

OK, understood. Can you recommend an Adafruit microcontroller that could act as a 'central'?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Metro m4 AirLift Lite as BLE server

Post by adafruit_support_mike »

The nRF52840 works as a central device:

https://www.adafruit.com/product/4062

The tutorial describle the code you’ll use:

https://learn.adafruit.com/introducing- ... 40-feather

Locked
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”