Skip to content

nordic: BLE not interoperating with some devices #9440

Closed
@dhalbert

Description

@dhalbert

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")

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions