Skip to content

Commit 5d58457

Browse files
authored
Merge pull request #81 from dhalbert/max_length
512 is max length for variable length Characteristics, not fixed
2 parents 96774b1 + 52ff3ea commit 5d58457

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

adafruit_ble/advertising/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def encode_data(data_dict, *, key_encoding="B"):
8686
struct.pack_into(key_encoding, data, i + 1, key)
8787
data[i + 1 + key_size : i + 1 + item_length] = bytes(value)
8888
i += 1 + item_length
89-
return data
89+
return bytes(data)
9090

9191

9292
class AdvertisingDataField:

adafruit_ble/characteristics/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class Characteristic:
5151
:param int write_perm: Specifies whether the characteristic can be written by a client,
5252
and if so, which security mode is required. Values allowed are the same as ``read_perm``.
5353
:param int max_length: Maximum length in bytes of the characteristic value. The maximum allowed
54-
is 512, or possibly 510 if ``fixed_length`` is False. The default, 20, is the maximum
54+
by the BLE specification is 512. On nRF, if ``fixed_length`` is ``True``, the maximum
55+
is 510. The default value is 20, which is the maximum
5556
number of data bytes that fit in a single BLE 4.x ATT packet.
5657
:param bool fixed_length: True if the characteristic value is of fixed length.
5758
:param buf initial_value: The initial value for this characteristic. If not given, will be

adafruit_ble/characteristics/string.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(
5151
properties=properties,
5252
read_perm=read_perm,
5353
write_perm=write_perm,
54-
max_length=510, # shorter than 512 due to fixed_length==False
54+
max_length=512,
5555
fixed_length=False,
5656
initial_value=initial_value,
5757
)

0 commit comments

Comments
 (0)