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

Reconnecting to Feather nRF52840 Express causes exception #130

Closed
Kimpehzor opened this issue Aug 14, 2021 · 4 comments
Closed

Reconnecting to Feather nRF52840 Express causes exception #130

Kimpehzor opened this issue Aug 14, 2021 · 4 comments
Assignees

Comments

@Kimpehzor
Copy link

Kimpehzor commented Aug 14, 2021

I am running this example code on a Feather nRF52840 Express.

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

"""
This example solicits that apple devices that provide notifications connect to it, initiates
pairing, prints existing notifications and then prints any new ones as they arrive.
"""

import time
import adafruit_ble
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
import adafruit_ble_apple_notification_center as ancs

# PyLint can't find BLERadio for some reason so special case it here.
radio = adafruit_ble.BLERadio()  # pylint: disable=no-member
a = SolicitServicesAdvertisement()
a.solicited_services.append(ancs.AppleNotificationCenterService)
radio.start_advertising(a)

while not radio.connected:
    pass

print("connected")

known_notifications = set()

while radio.connected:
    for connection in radio.connections:
        if not connection.paired:
            connection.pair()
            print("paired")

        ans = connection[ancs.AppleNotificationCenterService]
        for notification in ans.wait_for_new_notifications():
            print(notification)

        print(len(ans.active_notifications))
    time.sleep(1)

print("disconnected")

The script runs without issue until I encounter a reconnect. If the Bluetooth connection is disconnected (manually by disabling Bluetooth on the phone or walking out of Bluetooth range) and then reconnected, this exception is thrown upon reconnecting:

Traceback (most recent call last):
File "code.py", line 33, in
File "adafruit_ble/init.py", line 88, in getitem
File "adafruit_ble/init.py", line 52, in _discover_remote
ConnectionError: Connection has been disconnected and can no longer be used. Create a new connection.

Restarting the script does not help. Disabling / Re-enabling bluetooth does not help.

I have reproduced the issue using:
CircuitPython - 6.3.0
CircuitPython - 7.0.0-alpha.6
iOS 14.7
iOS 15 Public Beta 5

The only temporary solution I have found so far is to unpair/re-pair the feather via iOS. This solves the issue until the next disconnect occurs.

@tannewt tannewt self-assigned this Aug 16, 2021
@tannewt
Copy link
Member

tannewt commented Aug 24, 2021

Please try absolute newest of CircuitPython. I just tried the demo and it worked ok.

@blalor
Copy link

blalor commented Sep 1, 2021

I'm also experiencing this error, using CircuitPython 6.3.0 and the "Absolute Newest" bundle adafruit-circuitpython-bundle-py-20210901.zip (which I wouldn't expect to completely work because different major versions, but I'm trying to hack my way around this issue).

@tannewt is this issue coming from this project, or from CircuitPython itself?

@blalor
Copy link

blalor commented Sep 1, 2021

Interesting, after "forgetting" the CircuitPython device from my iPhone, the problem seems to have gone away. 🤔

@tannewt
Copy link
Member

tannewt commented Sep 1, 2021

@tannewt is this issue coming from this project, or from CircuitPython itself?

I suspect the CircuitPython core. We reworked BLE quite a bit to add the BLE workflow in 7 so it's not really worth debugging 6.3.0. I'm planning a 7 release candidate this week and hopefully a stable release next week or the week after depending on how the RC goes.

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

No branches or pull requests

3 participants