Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low timeout values for BLERadio().start_scan() can lead to safe mode when calling BLERadio().connect() #3826

Closed
catequalsgood opened this issue Dec 15, 2020 · 3 comments · Fixed by #3861

Comments

@catequalsgood
Copy link

I have been using a Feather Sense in a project and noticed that about once a day it would go into safe mode. After some testing I have narrowed it down to specific values for the timeout of start_scan(). Large values (for example 0.1) seem fine and the code runs for several days. Very small values (for example 0.01) are simply ignored so that start_scan() never times out. Values in between (for example 0.05) run fine for a few hours or sometimes even a day but eventually cause the Feather to go into safe mode.

My setup for testing was the following:
One ItsyBitsy nRF52840 running the unmodified ble_adafruit_simpletest.py example code.
One Feather nRF52840 Sense running a modified version of the ble_adafruit_simpletest_client.py example (below).

import time

import adafruit_ble
from adafruit_ble_adafruit.adafruit_service import AdafruitServerAdvertisement
import supervisor

ble = adafruit_ble.BLERadio()

connection = None

print("Scanning for an Adafruit Server advertisement...")
for adv in ble.start_scan(AdafruitServerAdvertisement, timeout=0.05):
    print("about to connect")
    connection = ble.connect(adv)
    print("connected")
    break

ble.stop_scan()

supervisor.reload()

The last line printed to the REPL is "about to connect".
The safe mode message I get is the following:

Auto-reload is off.
Running in safe mode! Not running saved code.

You are in safe mode: something unanticipated happened.
CircuitPython core code crashed hard. Whoops!
Nordic Soft Device failure assertion.
Please file an issue with the contents of your CIRCUITPY drive at 
https://github.com/adafruit/circuitpython/issues

Press any key to enter the REPL. Use CTRL-D to reload.

For my project I will just increase the timeout to 0.1 but since it took me a while to identify the issue I thought I would share. I did most of the testing running beta versions of 6.0.0 but after updating CircuitPython to the final 6.0.0 and updating the libraries the behavior is still the same.

@tannewt
Copy link
Member

tannewt commented Dec 15, 2020

Thanks for the issue! Since it is a safe mode, I'm going to move it into the circuitpython repo.

@tannewt tannewt transferred this issue from adafruit/Adafruit_CircuitPython_BLE Dec 15, 2020
@tannewt tannewt added this to the 6.x.x - Bug Fixes milestone Dec 15, 2020
@dhalbert
Copy link
Collaborator

I believe this may be due to the non-zero timeout being less than the interval, because the default interval is 0.1 seconds. I put in a check for this which will require the timeout either being zero or >= the interval.

This was referenced Dec 18, 2020
@dhalbert dhalbert linked a pull request Dec 22, 2020 that will close this issue
@dhalbert
Copy link
Collaborator

Fixed by #3861.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants