From a3cc3ebdaf7a8624706a7d79fda6e779df96b7df Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 12 May 2020 13:33:24 -0400 Subject: [PATCH 1/2] 512 is max length for variable length, not fixed --- adafruit_ble/characteristics/__init__.py | 2 +- adafruit_ble/characteristics/string.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_ble/characteristics/__init__.py b/adafruit_ble/characteristics/__init__.py index ebecc53..8fa42f6 100644 --- a/adafruit_ble/characteristics/__init__.py +++ b/adafruit_ble/characteristics/__init__.py @@ -51,7 +51,7 @@ 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 + is 512, or on nRF, 510 if ``fixed_length`` is True. The default, 20, 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 diff --git a/adafruit_ble/characteristics/string.py b/adafruit_ble/characteristics/string.py index c9f154e..e4e7cfa 100755 --- a/adafruit_ble/characteristics/string.py +++ b/adafruit_ble/characteristics/string.py @@ -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, ) From 52ff3eaa4dfb3b9bf6be58f3ac49a2b8ec3f5850 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 12 May 2020 13:45:55 -0400 Subject: [PATCH 2/2] pylint caught an inconsistency --- adafruit_ble/advertising/__init__.py | 2 +- adafruit_ble/characteristics/__init__.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/adafruit_ble/advertising/__init__.py b/adafruit_ble/advertising/__init__.py index 0781f70..649901d 100644 --- a/adafruit_ble/advertising/__init__.py +++ b/adafruit_ble/advertising/__init__.py @@ -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: diff --git a/adafruit_ble/characteristics/__init__.py b/adafruit_ble/characteristics/__init__.py index 8fa42f6..6c3e481 100644 --- a/adafruit_ble/characteristics/__init__.py +++ b/adafruit_ble/characteristics/__init__.py @@ -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 on nRF, 510 if ``fixed_length`` is True. 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