Shelly devices support json rpc over udp. It is quite nice to use those apis and the resulting client code is surprisingly light weight and robust.
However, there are two things that worry me:
a) what about datagrams bigger then MSS? Here the risk of losing the whole datagram doubles, triples, … Locally, it may not be so bad when one can use jumbo frames, but one the internet, it will be 1452 bytes per Datagram, before fragmentation happens
Nice. JSON over UDP is convenient, but has some drawbacks. But first your questions:
The answer to a) depends: If the payload is larger than can fit in a single datagram (the exact number can vary a bit) it has to be split. Each packet has some chance of loss. If it has to arrive, it has to be acknowledged and if split reassembled. So not bigger packets, but more of them.
For b) use WireGuard encryption. Not necessarily the VPN, just the handshake and transport protection. It’s very well aligned with UDP and lightweight enough to work on battery powered devices. I’ve added WireGuard termination to UDP Gateway specifically for this requirement.
Why am I not a fan of JSON over UDP? Extra serialization, extra size, extra constraints. None of those are huge deals, but I prefer something like MessagePack or CBOR for compact message sizes.
However, there are two things that worry me:
a) what about datagrams bigger then MSS? Here the risk of losing the whole datagram doubles, triples, … Locally, it may not be so bad when one can use jumbo frames, but one the internet, it will be 1452 bytes per Datagram, before fragmentation happens
b) how to handle encryption and authentication?