adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.08k stars 1.21k forks source link

BLE HID issues on esp32s3 #9669

Closed lukasmwerner closed 1 week ago

lukasmwerner commented 2 weeks ago

CircuitPython version

Adafruit CircuitPython 9.2.0-beta.0-16-gec5cca6983 on 2024-09-27; TinyS3 with ESP32S3

Code/REPL

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

"""
This example acts as a keyboard to peer devices.
"""

# import board
import sys
import time

from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS

import adafruit_ble
from adafruit_ble.advertising import Advertisement
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.standard.hid import HIDService
from adafruit_ble.services.standard.device_info import DeviceInfoService

# Use default HID descriptor
hid = HIDService()
device_info = DeviceInfoService(
    software_revision=adafruit_ble.__version__, manufacturer="Adafruit Industries"
)
advertisement = ProvideServicesAdvertisement(hid)
advertisement.appearance = 961
scan_response = Advertisement()

ble = adafruit_ble.BLERadio()
if ble.connected:
    for c in ble.connections:
        c.disconnect()

print("advertising")
ble.start_advertising(advertisement, scan_response)

k = Keyboard(hid.devices)
kl = KeyboardLayoutUS(k)
while True:
    while not ble.connected:
        pass
    print("Start typing:")
    while ble.connected:
        c = sys.stdin.read(1)
        sys.stdout.write(c)
        kl.write(c)
        # print("sleeping")
        time.sleep(0.1)
    ble.start_advertising(advertisement)

Behavior

Traceback (most recent call last):
  File "code.py", line 23, in <module>
  File "adafruit_ble/services/standard/hid.py", line 352, in __init__
  File "adafruit_ble/services/__init__.py", line 81, in __init__
  File "adafruit_ble/characteristics/__init__.py", line 164, in __set__
  File "adafruit_ble/characteristics/__init__.py", line 124, in _ensure_bound
  File "adafruit_ble/characteristics/__init__.py", line 149, in __bind_locally
ValueError: Value length > max_length

Description

No response

Additional information

No response

dhalbert commented 2 weeks ago

Does not fail in 9.2.0-alpha.2351, so the change is recent. And does not fail with #9597 merge.

lukasmwerner commented 2 weeks ago

Is there a way I can download a 9.2.0-alpha build?

dhalbert commented 2 weeks ago

Try https://adafruit-circuit-python.s3.amazonaws.com/index.html?prefix=bin/unexpectedmaker_tinys3/en_US/, and pick the release with PR9597. #9597 fixed some things that prevent BLE HID from working. I was just seeing if it was the same error.

lukasmwerner commented 2 weeks ago

Cool looks like it is working there! Thank you so much for your help @dhalbert. Looking forward to the 9.2 release

dhalbert commented 2 weeks ago

I'm reopening this because the latest builds, past #9597, cause the error you found. So there was a regression we need to fix.

dhalbert commented 1 week ago

I did a bisect and 03b077dd912d9fd7faf9fb167fb7d8f48af300ab is the first "bad" commit.