adafruit / adafruit/Adafruit_CircuitPython_BLE

Pyportal Titano BLE advertisement length error

Open
#186 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
138
Forks
58
PR merge metrics
No merged PRs in 30d

Description

Hi everyone,

This issue was originally posted on the Adafruit Forums: https://forums.adafruit.com/viewtopic.php?p=970491#p970491

I've been trying to use BLE with CircuitPython, and I've hit a snag with the PyPortal Titano. I have:

- Updated CircuitPython to version 8.0.5
- Upgraded the libraries on the device to those from the 8.x bundle
- Updated the Airlift firmware to NINA_W102-1.7.4 using Adafruit's guide

```python

# SPDX-FileCopyrightText: 2020 Dan Halbert, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense

# pylint: disable=unused-import
import board
import busio
from digitalio import DigitalInOut
from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_airlift.esp32 import ESP32

# If you are using a Metro M4 Airlift Lite, PyPortal,
# or MatrixPortal, you can use the default pin settings.
# Leave this DEFAULT line uncommented.
# If you are using a board with pre-defined ESP32 Pins:
esp32 = ESP32()

# If you are using a Metro M7 **OR**
# if you are using CircuitPython 6.0.0 or earlier,
# on PyPortal and PyPortal Titano only, use the pin settings
# below. Comment out the DEFAULT line above and uncomment
# the line below. For CircuitPython 6.1.0, the pin names
# have changed for these boards, and the DEFAULT line
# above is correct.
# esp32 = ESP32(tx=board.TX, rx=board.RX)

# If you are using an AirLift FeatherWing or AirLift Bitsy Add-On,
# use the pin settings below. Comment out the DEFAULT line above
# and uncomment the lines below.
# If you are using an AirLift Breakout, check that these
# choices match the wiring to your microcontroller board,
# or change them as appropriate.
# esp32 = ESP32(
# reset=board.D12,
# gpio0=board.D10,
# busy=board.D11,
# chip_select=board.D13,
# tx=board.TX,
# rx=board.RX,
# )

# If you are using an AirLift Shield,
# use the pin settings below. Comment out the DEFAULT line above
# and uncomment the lines below.
# esp32 = ESP32(
# reset=board.D5,
# gpio0=board.D6,
# busy=board.D7,
# chip_select=board.D10,
# tx=board.TX,
# rx=board.RX,
# )

adapter = esp32.start_bluetooth()

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

while True:
ble.start_advertising(advertisement)
print("waiting to connect")
while not ble.connected:
pass
print("connected: trying to read input")
while ble.connected:
# Returns b'' if nothing was read.
one_byte = uart.read(1)
if one_byte:
print(one_byte)
uart.write(one_byte)

```

When I try to use this code

[From this Adafruit Guide](https://learn.adafruit.com/adafruit-pyportal/circuitpython-ble)

I get this error from Mu:

```python
0;🐍main.py | 8.0.5\]0;🐍main.py | 8.0.5\Traceback (most recent call last):
File "main.py", line 64, in
File "adafruit_ble/__init__.py", line 215, in start_advertising
ValueError: Data too large for advertisement packet
]0;🐍215@adafruit_ble/__init__.py ValueError | 8.0.5\
Code done running.
```

I've also done all of this using a Feather M4 Express with the standalone Airlift breakout (ADA4201) and it works just fine, so this seems to be something specific to the Titano or built-in airlifts. The code also works fine when run on a Feather nRF52840 and a Seeed Xiao nRF52840.

Mikeysklar on the forum asked me to print `advertisement` after the code runs:

```python

uart = UARTService()
advertisement = ProvideServicesAdvertisement(uart)
```

On the Titano this gives:
` services= >`

On the Feather M4 Express with Airlift breakout this gives:
` flags= >`

The BLE code is a little beyond me, so I can't quite see what's going wrong here. Any help would be very much appreciated.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at adafruit_ble/__init__.py line 215, then reproduce the PyPortal Titano failure with the BLE guide example and compare its advertisement output with the working Feather M4 Airlift setup. Done means the example starts advertising without the advertisement-size error on the Titano while retaining the working behavior on the other reported boards.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.