Best way to send small but not tiny amounts of binary data from Notecard?

Hi all,
I’m trying to figure out what the best approach is for sending binary data in amounts that are not tiny, but still small.

My device records readings from other sensors. These readings are each 23 bytes of binary data, and I need to be able to buffer some of these readings up - maybe 20-30 of them - and send them all at once during a Notehub sync. So, we’ve got ~700 bytes of data to send.

If I wanted to put that in a payload, 700 is more than the allowed max length from the get-go. And if I put it in a payload, I have to convert it to ascii, which doubles the size, then encode base64 which adds about another 30-40%. So suddenly my small data is growing rapidly and is nearing 2 kb.

The individual readings are very small, but batching them up seems to complicate things. On the other hand, NOT batching them up means every single reading consumes two consumption credits and that seems like it would be undesirable.

This seems like it would be a common use-case. What are some potential approaches?

Thanks for any ideas.
Scott

Hi @scase,

I’d recommend starting with the card.binary APIs. There is a guide on sending binary objects as well.

Thanks,
Rob

1 Like

Thanks for the pointer, Rob, and the links.

I’ve been working on getting set up to test this method, and just wanted to provide a little feedback that may help improve the guide and related docs here. Here are a couple of things that I think could save others reading this guide a ton of time. I mean the following to be, hopefully, helpful suggestions, not complaints.
In this section:

  • Step 2 mentions calculating the MD5 checksum for your payload, but it doesn’t mention that the note-c library includes an implementation of MD5 that can do this. (note.h → n_md5.c → NoteMD5HashString() ) This would have saved me a lot of time, as I pulled in an external MD5 library from the Nordic SDK and it was a bit of a hassle to get working. The inclusion of this feature is a great convenience and it’s already built in, so I think it makes sense to point it out. Maybe it would have been obvious to some, but I totally missed it.
  • Step 4 says to calculate the size of the COBS-encoded payload, but again doesn’t say how. It would be helpful to call out the name of the built-in function that can do this for you. (I think it’s NoteBinaryCodecMaxEncodedLength(), declared in note.h.)
  • Also on Step 4, it says to calculate the size of the encoded payload AFTER actually encoding it (Step 3). Would it make sense do that first, so that you can make sure the buffer you’re using is appropriately-sized?
  • Step 7 says to stream the binary data to the Notecard, but makes no mention of how to do this. Would it be possible to call out any examples or library functions that facilitate this?
  • note.h has some functions that I think could be really helpful, yet the guide doesn’t mention them. I found a function called NoteBinaryStoreTransmit. It looks to me like this function basically does all of the steps in this section of the guide. Wow, I wish I had seen this sooner! This could be a huge time-saver. It would be very helpful to call this function out in the guide. Maybe there are other useful functions that could be mentioned in here. You guys have done the hard work of writing and testing the code; why not highlight it for users to be able to take advantage of it more readily?

Thanks again, @RobLauer and the Blues team.

Scott

2 Likes

Hi @scase,

Fantastic feedback! We will definitely look at incorporating this in our guides.

Rob