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

nordic: BLE not interoperating with some devices #9440

Closed
dhalbert opened this issue Jul 20, 2024 · 0 comments · Fixed by #9441
Closed

nordic: BLE not interoperating with some devices #9440

dhalbert opened this issue Jul 20, 2024 · 0 comments · Fixed by #9441
Assignees
Milestone

Comments

@dhalbert
Copy link
Collaborator

Problem found by @Erland in discord, while testing against a commercial device under development.

A simple BLE UART (NUS) service central could not receive notifications from another device.

I was able to reproduce this using an nRF52840 acting as a NUS central and an ESP32-S3 acting as a NUS peripheral. nRF52840 to nRF52840 worked OK.

Test programs:

central

from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService
import time

time.sleep(2)
print("---Central---")
ble = BLERadio()
uart_connection = None

while True:
    if not uart_connection:
        print("Scanning to connect...")
        for adv in ble.start_scan(ProvideServicesAdvertisement):
            print(".", end="")
            if UARTService in adv.services:
                uart_connection = ble.connect(adv)
                print("Connected")
                break
        ble.stop_scan()

    if uart_connection and uart_connection.connected:
        uart_service = uart_connection[UARTService]
        while uart_connection.connected:
            if uart_service.in_waiting:
                print(uart_service.read(uart_service.in_waiting))

peripheral

from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService
import time

time.sleep(2)
print("---Peripheral---")

ble = BLERadio()
uart = UARTService()
advertisement = ProvideServicesAdvertisement(uart)

#time.sleep(1)
while True:
    print("Advertising...")
    ble.start_advertising(advertisement)
    while not ble.connected:
        pass
    print("connected")
    while ble.connected:
        if uart.in_waiting:
            print("got", uart.read(uart.in_waiting))
        uart.write(str(time.monotonic()).encode())
        time.sleep(2)
    print("disconnected")
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.

1 participant