Skip to content

512 is max length for variable length Characteristics, not fixed #81

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

Merged
merged 2 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion adafruit_ble/advertising/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def encode_data(data_dict, *, key_encoding="B"):
struct.pack_into(key_encoding, data, i + 1, key)
data[i + 1 + key_size : i + 1 + item_length] = bytes(value)
i += 1 + item_length
return data
return bytes(data)


class AdvertisingDataField:
Expand Down
3 changes: 2 additions & 1 deletion adafruit_ble/characteristics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class Characteristic:
:param int write_perm: Specifies whether the characteristic can be written by a client,
and if so, which security mode is required. Values allowed are the same as ``read_perm``.
:param int max_length: Maximum length in bytes of the characteristic value. The maximum allowed
is 512, or possibly 510 if ``fixed_length`` is False. The default, 20, is the maximum
by the BLE specification is 512. On nRF, if ``fixed_length`` is ``True``, the maximum
is 510. The default value is 20, which is the maximum
number of data bytes that fit in a single BLE 4.x ATT packet.
:param bool fixed_length: True if the characteristic value is of fixed length.
:param buf initial_value: The initial value for this characteristic. If not given, will be
Expand Down
2 changes: 1 addition & 1 deletion adafruit_ble/characteristics/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(
properties=properties,
read_perm=read_perm,
write_perm=write_perm,
max_length=510, # shorter than 512 due to fixed_length==False
max_length=512,
fixed_length=False,
initial_value=initial_value,
)
Expand Down