-
Notifications
You must be signed in to change notification settings - Fork 56
Add JSON characteristic #162
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
Conversation
37bff64
to
65f350b
Compare
Hi @mraleson, Thanks for working on this. It seems like some neat and useful functionality. I would recommend to also go ahead and add a new script inside of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting idea, and adds convenience.
adafruit_ble/characteristics/json.py
Outdated
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE.git" | ||
|
||
|
||
class JsonCharacteristic(Characteristic): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you make this a subclass of StringCharacteristic
, that would seem to save a few encoding/decoding steps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this initially, but because of the packing/unpacking of initial_value in init and also in the setter getter inheriting from StringCharacteristic it ended up not really saving any typing. It also added an additional inheritance layer that hid attributes like max_length.
adafruit_ble/characteristics/json.py
Outdated
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE.git" | ||
|
||
|
||
class JsonCharacteristic(Characteristic): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use JSON
instead of Json
. The former is typical in existing Python libraries, including those that are included in CPython.
class JsonCharacteristic(Characteristic): | |
class JSONCharacteristic(Characteristic): |
adafruit_ble/characteristics/json.py
Outdated
`json` | ||
==================================================== | ||
|
||
This module provides Json characteristic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this grammatical, and expand on what is going on a bit more.
adafruit_ble/characteristics/json.py
Outdated
|
||
|
||
class JsonCharacteristic(Characteristic): | ||
"""Json string characteristic for JSON serializable values of a limited size (max_length).""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Json string characteristic for JSON serializable values of a limited size (max_length).""" | |
"""JSON string characteristic for JSON serializable values of a limited size (max_length).""" |
examples/ble_json_central.py
Outdated
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
# Read sensor readings from peripheral BLE device using JSON characteristic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix grammar -> "a JSON characteristic" , or similar.
Hi all, I updated the code with some examples and I took a stab at resolving the requested changes. I haven't had a chance to test again with all of the changes in their entirety. Please let me know if there is a process you follow for testing and I can do that as well. |
Hey @mraleson looks like this is failing on |
You can add a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE to 8.3.0 from 8.2.4: > Merge pull request adafruit/Adafruit_CircuitPython_BLE#162 from mraleson/json-characteristic > Patch: Replaced discord badge image > Update .gitignore
Adds a JSON characteristic so python arrays, dicts, etc can be set/get easily on a connected ble device. This was very helpful for fast prototyping and debugging. I found it difficult to send large values of the UART due to the small buffer, lack of flow control, reliable messaging etc. It also has an advantage over making many individual characteristics, the Nordic chip I was using on the Feather Sense was unable to support the number of individual characteristics I needed without running out of memory. I also considered a msgpack variant, but it didn't save enough space for me to justify the lack of debugging utility. One consideration is the size is limited by the characteristic buffer size.