Saving BLE client service discovery on a PICO_W: How to create a uctypes struct layout that contains an array of another uctypes struct layout? #15597
Unanswered
brianreinhold
asked this question in
RP2040 / Pico
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First, why do this? The memory fragmentation on the PICO is so severe that the most robust way to avoid it is to predefine buffers of sufficient and fixed size to hold the data one needs. While the application is running, this buffer is used and reused as needed.
In this case I am writing a Bluetooth LE client that communicates with health devices. There is certain information about each health device that one needs to persist in order to reconnect without user involvement. This information is saved to a file for each device. A list of addresses for the device is independently maintained.
When a device is discovered, the list of addresses is checked, and if it is found, the saved data is read from the file and placed in the reserved
uctypes struct
.How does one do this? First one defines a layout (mimicking a class C struct)
Sorry for the big size but they are all basically strings, ints, and booleans. That aside, one then defines the buffer that is to hold this data and then one creates an 'instance' of the
phd_info_layout
struct.The backing buffer is
phdinfoBuffer
. One can then usephdinfo_struct
like a C struct, for examplephdinfo_struct.manufacturer = "A&D Medical".encode('utf-8')
This works fine. However, what I have NOT been able to figure out is how to add and element that is itself a layout.
Why do I want to do that? A serious shortcoming of the aioble library is that is does NOT save service discovery results and thus one must do service discovery every connection. A bonded peripheral does not expect this, and once encryption is established, is indicates or notifies any data it has, and the client is still engaged in service discovery, and once that is done, invokes the subscription. By then the measurement data is long gone and forever lost. Not good!!!
So I want to add to the
phdinfo_struct
saved service discovery results. One can define a layout for a service as follows:The problem is the characteristics. A service can have several characteristics, in this case '_NUM_OF_CHAR' characteristics. I can define a layout for a single characteristic as follows:
However, what I do NOT know how to do (I have tried many things) is how to add an array of
characteristic_layouts
to myservice_layout
. If I ever figure out how to do that, then I can add an array ofservice_layouts
to myphdinfo_layout
.I would appreciate any help on how to do this!!!
Beta Was this translation helpful? Give feedback.
All reactions