Description
Several examples are available that show scanning while advertising (i.e. no stop_advertising). E.g. Clue rock-paper-scissors, and some non circuitpython examples for the nRF52840 (e.g. https://learn.adafruit.com/introducing-the-adafruit-nrf52840-feather/dual-roles-bleuart).
On the bluefruit at .start_scan()
, I get "_bleio.BluetoothError: Unknown system firmware error: 0011", which is NRF_ERROR_BUSY, implying scanning can't occur during advertising. I can find no other report of this error (which seems odd). Code works under circuitpython 6.3.0.
This appears to be some change in _bleio in 7.x.x (since 6.3.0).
Hardware, as reported in boot_out.txt:
Adafruit Circuit Playground Bluefruit with nRF52840
Board ID:circuitplayground_bluefruit
circuitpython, as reported in boot_out.txt and repl:
Adafruit CircuitPython 7.1.1 on 2022-01-14; Adafruit Circuit Playground Bluefruit with nRF52840
only 1 library in lib/ folder:
adafruit-circuitpython-ble-7.x-mpy-8.2.0/lib/adafruit_ble
reported by repl:
>>> import adafruit_ble
>>> print( adafruit_ble.__version__ )
8.2.0
(I tried the "simple game" of Clue rock-paper-scissors, same error.)
Circuitpython vs adafruit_ble matrix:
adafruit_ble
8.2.0 8.1.0 7.3.4
circuitpython
7.1.1 fail fail fail
en_US-20220210-c234d92 fail fail
6.3.0 works works
example code
import traceback # remove for circuitpython 6.3.0
import time
import _bleio # for the exception
from adafruit_ble import BLERadio
from adafruit_ble.advertising import Advertisement
print("\nstart")
MAX_SEND_TIME_S = 5
# 20ms is the minimum delay between advertising packets
# in Bluetooth Low Energy
# extra 10us deals with API floating point rounding issues
MIN_AD_INTERVAL = 0.02001 # changing has no effect
ble = BLERadio()
advertisement = Advertisement()
advertisement.short_name = "HELLO"
advertisement.connectable = False # True has no effect
print("loop")
# related to the previous bonding? no
# ble._adapter.erase_bonding()
# advertise while scanning:
ble.start_advertising(advertisement, interval= MIN_AD_INTERVAL)
while True:
# does waiting have any effect? no
# time.sleep(0.2)
# Timeout value is in seconds
# window and interval are 0.1 by default - same value means
# continuous scanning (sending Advertisement will interrupt this)
gotit = 10
while(gotit > 0):
try:
# the .start_scan() will throw:
# Traceback (most recent call last):
# File "code.py", line 47, in <module>
# File "adafruit_ble/__init__.py", line 250, in start_scan
# _bleio.BluetoothError: Unknown system firmware error: 0011
for adv in ble.start_scan(
Advertisement,
# does non-continuous have any effect? no
#window=0.1,
#interval=0.2,
#minimum_rssi=-90,
# does a buffer have any effect? no
#buffer=256,
# does a timeout have any effect? no
# timeout=MAX_SEND_TIME_S
):
gotit = 0
print("received: ", adv.short_name)
ble.stop_scan()
break
except _bleio.BluetoothError as e:
# does retrying have any effect? no
# should we have done a stop_scan for retry? no
#ble.stop_scan()
gotit -= 1
time.sleep(0.03)
if (gotit==9): # we don't need to see it 10 times
print( traceback.format_exception( None, e, e.__traceback__) )
print("fail...",gotit, e) # fails 0..9
if gotit == 0:
print("Failed")
break