CBOR Serialization in the Golioth Zephyr SDK: 20% Data Savings!

Originally published at: CBOR Serialization in the Golioth Zephyr SDK: 20% Data Savings! - Golioth

Golioth provides a lot of different services for your IoT fleet. Under the hood they all boil down to one thing: transferring some type of data to or from a constrained device. Whether it’s your microcontroller-based sensors sending back readings, or the new settings from the cloud being pushed to a device via Remote Procedure Call (RPC), it’s all data transfer. That data should be as efficient as possible, which is why Golioth uses CBOR for serialization. This saves bandwidth and radio-on time (ie: battery life). So you’d be wise to use CBOR in your application code. Let’s dive into an example! What is CBOR? CBOR is the Concise Binary Object Representation. It uses the JSON data model, but packs the data more tightly. The result is not human readable, but that’s the point. IoT networks are basically robots talking to other robots, we want to tailor our data packets with that in mind. Golioth makes it easier by doing the work under the hood (in our SDK) so you don’t have to think about it…you just reap the data savings. Sending Data with CBOR Let’s stream some data to Golioth using the LightDB Stream sample. Our data for this will include the following: int32_t neg_reading = −2147483647 double temperature = 23.45 double pressure = 100.133019 double humidity = 32.204101 double accX = 0.480525 double accY = 0.156906 double accZ = -9.100571 char text[] = “Golioth” If we were sending this as JSON, it would look pretty nice: { “neg_reading”: -2147483647, “weather”: { “temperature”: 23.45, “pressure”: 100.133019, “humidity”: 32.204101 }, “accelerometer”: { “accX”: 0.480525, “accY”: 0.156906, “accZ”: -9.100571 }, “text”: “Golioth” } But we can reduce the data footprint with…