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

_bleio: Unable to write more than 20 bytes to a peripheral characteristic when acting as central #3975

Closed
jlopez opened this issue Jan 12, 2021 · 5 comments · Fixed by #3993
Assignees
Labels

Comments

@jlopez
Copy link

jlopez commented Jan 12, 2021

I'm using the nRF52840 as a central and trying to write to a BLE peripheral's characteristic. The data written is 26 bytes long. But it fails with:

ValueError: Value length > max_length

The Characteristic.max_length seems to be set to 20 bytes, the default. And there's no way to specify a different one as the characteristic is created internally by Connection.discover_remote_services

The device I'm trying to connect to is a Spark 40 by Positive Grid. Here's the code I'm using:

from _bleio import adapter, UUID

PREFIXES = b"\x03\x03\xc0\xff"
SVC_UUID = UUID(0xFFC0)
CHR_UUID = UUID(0xFFC2)
DATA = b"\x01\xfe\x00\x00\x53\xfe\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\x01\x00\x00\x00\x02\x23\xf7"

def find_chr(svcs, uuid):
    return next(c for s in svcs for c in s.characteristics if c.uuid == uuid)

for scan_entry in adapter.start_scan(prefixes=PREFIXES):
    adapter.stop_scan()
    conn = adapter.connect(scan_entry.address, timeout=1)
    print("Found")

if conn:
    print("Connected")
    services = conn.discover_remote_services((SVC_UUID,))
    characteristic = find_chr(services, CHR_UUID)
    if characteristic:
        print("Writing value")
        # Will throw ValueError: Value length > max_length
        characteristic.value = DATA
    conn.disconnect()

The output:

Found
Connected
Writing value
Traceback (most recent call last):
  File "code.py", line 23, in <module>
ValueError: Value length > max_length
@dhalbert dhalbert self-assigned this Jan 12, 2021
@dhalbert
Copy link
Collaborator

@jlopez Could you try this test UF2, which I hope will fix your issue? It's for a Feather nRF52840. If you need it for another board, just ask. You will need to unzip it, because GitHub won't allow uploads of .uf2's directly.

feather840-6.1.0-rc.0-146-gccace62ac.uf2.zip

@jlopez
Copy link
Author

jlopez commented Jan 13, 2021

Sure thing. I have an ItsyBitsy nRF52840, though. Once I get an updated .uf2 I'll give it a shot. Thanks!

@dhalbert
Copy link
Collaborator

@jlopez
Copy link
Author

jlopez commented Jan 13, 2021

It works! The write now succeeds without an exception. Thanks again! 😄

@jlopez jlopez closed this as completed Jan 13, 2021
@jlopez jlopez reopened this Jan 13, 2021
@dhalbert
Copy link
Collaborator

dhalbert commented Jan 13, 2021

Great! Will submit a PR shortly.

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

Successfully merging a pull request may close this issue.

3 participants