Great question! We’ve definitely had some interesting discussions internally about CBOR. It’s not really applicable right now, but we may have uses for it in the future. Either way, you can be confident that our whole user experience goal with respect to things like payload format is to do the research, compare our options, make the hard decisions, and do the difficult implementation work so that you don’t have to!
You can see all the CoAP code in the Device OS
communication folder. Many of our messages don’t even use the payload. Here’s one example that does:
- The cloud sends a function call CoAP message to the device, which is confirmable, so the device immediately responds with an ACK.
- After the function runs in the user thread, a return value is available.
- The device then sends a function return CoAP message where the payload is simply the 4-byte integer return value, no particular encoding (like CBOR) necessary.
I completely understand that the reason you’re asking is for when you as a user publish data. To Particle, that data is an opaque string, where we have no idea the format of the underlying information. You are free to format it however you like, including CBOR, although to keep it a valid string (no null bytes, ASCII, so each
char less than 128), you’d need to base64 or base85 encode that CBOR object.