Skip to content

BLE disconnect event crash #6451

@callmeduncan

Description

@callmeduncan

CircuitPython version

Adafruit CircuitPython 7.3.0 on 2022-05-23; Adafruit ItsyBitsy nRF52840 Express with nRF52840

Code/REPL

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

import time

import adafruit_ble
from adafruit_ble_adafruit.adafruit_service import AdafruitServerAdvertisement
from adafruit_ble_adafruit.temperature_service import TemperatureService

# PyLint can't find BLERadio for some reason so special case it here.
ble = adafruit_ble.BLERadio()  # pylint: disable=no-member

connection = None

while True:
    print("Scanning for an Adafruit Server advertisement...")
    for adv in ble.start_scan(AdafruitServerAdvertisement, timeout=5):
        connection = ble.connect(adv)
        print("Connected")
        break

    # Stop scanning whether or not we are connected.
    ble.stop_scan()

    if connection and connection.connected:
        temp_service = connection[TemperatureService]
        while connection.connected:
            print("Temperature:", temp_service.temperature)
            time.sleep(1)

Behavior

This is the 'ble_adafruit_simpletest_client.py' from 7.x bundle, I am also running 'ble_adafruit_simpletest.py' on a second board to connect with it.
If I cause the connection to drop by rebooting / interrupting the board running 'ble_adafruit_simpletest.py' the other board running 'ble_adafruit_simpletest_client.py' locks up.
REPL can no-longer be accessed
Mass storage is still working

Description

This seems to affect all 7.x releases

On 6.3 it crashes in the same way if the board is powered on from cold, however if you power on, ctrl+c to the REPL, ctrl+d to resume and then disconnect the other side it doesn't crash, but it does not drop out of the while connection.connected: loop.

Additional information

https://forums.adafruit.com/viewtopic.php?f=60&t=191584&p=926989
supervisor.disable_ble_workflow() does not seem to help

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions