- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there anyway to clear data in a characteristic before writing new data to it? I'm running into and issue where if I write 5 bytes of data to a characteristic and then 3 bytes of data, the first 3 bytes get overwritten like they should, but the remaining 2 bytes from the first write are still there. Is there anyway to clear previous data before writing new data to a characteristic?
Solved! Go to Solution.
- Labels:
-
ReadWrite Characteristics
-
SDK 2.X
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
UINT8 loop;
for(loop = 0; loop < SIZE_OF_CHAR; loop++)
db_pdu.pdu[loop] = 0;
Jacob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Put it immediately before your writeHandle() call, whatever function that may be in.
Jacob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please ignore the last post, you need to clear it immediately prior to writing to it (which happens to be before writeHandle().
UINT8 loop;
for(loop = 0; loop < SIZE_OF_CHAR; loop++)
db_pdu.pdu[loop] = 0;
db_pdu.pdu[5] = data;
bleprofile_WriteHandle(....
Jacob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Right, I just don't know what function gets called in this case. I can put it in the store_in_... functions which call bleprofile_writeHandle at the end, but those functions don't get called when the android app changes the characteristic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you're doing this from the Android side, it will be easier to overwrite it from there. At the end of your 3 byte write, add two bytes zeroed out.
If this isn't an option and you need to work within the firmware, you need to register for a callback for when the client writes to your GATT database. You can then find out the length of the write, compare it to the size of the characteristic, and zero out the left over spaces. See hello_sensor for an example of registering for a callback to a client write. This callback will be passed the necessary parameters to execute what I described above.
Jacob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for all your help! I have access to the android side so I'll just zero the rest out from that side.