aioble: Extend BufferedCharacteristic functionality to allow for non-read-only characteristics #629
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BufferedCharacteristic
is an undocumented characteristic class that merely callsbluetooth.BLE.gatts_set_buffer
, allowing it to extend the internal buffer, which is useful for longer writes to successfully happen.Oddly enough,
BufferedCharacteristic
currently defaults to read-only characteristics (seeread=True
), and does not allow specifying other characteristic types.In my own personal testing, I had issues writing data longer than 20 bytes to a characteristic due to this buffer size issue (see here for more info). Calling
gatts_set_buffer
with a longermax_len
fixes it, but this is not currently exposed to the user in any way through aioble (there's a TODO to allow user to pass in the BLE object).I tried two different approaches, both porting this
_register
function over to regularCharacteristic
, and extendingBufferedCharacteristic
(this PR). Both function in my case, but doing former defeats the point ofBufferedCharacteristic
and as such PRing the latter felt like it made more sense.This PR, as such, extends
BufferedCharacteristic
in a backwards-compatible manner (hence the uglyread=True
+read=read
) allowing specifying different flags for the characteristic, and hopefully makes it more useful in the process.If a different approach is desired (i.e. not making this backwards compatible, changing
Characteristic
, exposing BLE object, etc) I can also change the PR to do that.(Tested and functioning on MicroPython v1.19.1-963-g668a7bd28 of 2023-03-10 on ESP32.)