Gain from using binary over base64 payload

Hi, sharing my experience from trying to migrate to the binary method. It seems the size gain is useful, but maybe a little less than I hoped for:

● ┌────────────────┬───────────┬──────────────┬──────────────┬───────────────┬───────────────┐
│ Packet │ Raw bytes │ Base64 bytes │ Saving │ Time (base64) │ Time (binary) │
├────────────────┼───────────┼──────────────┼──────────────┼───────────────┼───────────────┤
│ IMU (axlb.qo) │ 6 144 │ 8 192 │ −2 048 (25%) │ ~8 s │ ~6 s │
├────────────────┼───────────┼──────────────┼──────────────┼───────────────┼───────────────┤
│ GPS (egpsb.qo) │ 3 072 │ 4 096 │ −1 024 (25%) │ ~4 s │ ~3 s │
└────────────────┴───────────┴──────────────┴──────────────┴───────────────┴───────────────┘

From claude: “The 25% reduction is exactly what you expect from removing base64 encoding (every 3 raw bytes → 4 base64 chars). Transmission time scales proportionally since the
Notecard I²C throughput is roughly constant.”, which by the way implemented the rust logic on its own using note-c as a template…

Can the chunk/segment delays be reduced for binary data or is it the same as for regular i2c?

Add binary note transmission support by gauteh · Pull Request #28 · gauteh/notecard-rs · GitHub and Use binary-mode to transmit data to notecard by gauteh · Pull Request #192 · gauteh/sfy · GitHub

Another advantage is that I see far fewer JSON errors when using binary mode.

By the way, how is the binary data packed? It seems like the COBS stuff is removed, and re-encoded as base64 when retrieved from notehub? but without the extra padding that usually ends up in the regular json payload (probably added on the notecard?). Couldn’t find this mentioned in the docs. The binary transmission guide also don’t mention that it is possible to use note.add for binary.

Hi @gauteh,

Good stuff! That 25% improvement is exactly what we would expect. One thing you might want to look at is tuning NoteI2CMax (see the note-c implementation) which lets you set the host library’s max-chunk size.

By the way, how is the binary data packed? It seems like the COBS stuff is removed, and re-encoded as base64 when retrieved from notehub? but without the extra padding that usually ends up in the regular json payload (probably added on the notecard?).

COBS is just used between your host and Notecard…Notehub never sees it. Notecard stores and ships the raw bytes and then Notehub only converts to base64 at the very end. The “extra padding” you used to see was likely you sending a base64 string inside a JSON field to the Notecard (with its associated overhead when wrapping it in JSON).

Rob

Thanks, I’ve tried tuning the chunk size, but this always get’s me into instant communication errors. But those errors already happen during simple requests, no note.adds or anything.

– gaute