Skip to content
Lieven edited this page Jan 5, 2017 · 6 revisions

Welcome to the serial2mqtt wiki!

The serial2mqtt program runs on Linux and accepts data from a serial device, this data is CBOR serialization embedded in a SLIP envelope. This protocol contains instructions for the mqtt service on connection,publish,subscribe,disconnect. This serial connection can be delivered by Bluetooth (/dev/rfcomm0 ), USB ( /dev/ttyUSB0 /dev/ttyACM0 ) or a serial port directly.

String hashing

The protocol is optimized for small microcontroller usage and uses integer field denominators. To ease programming and make the format easy extendible, the programmer uses string form presentation. Thanks to C++11 standard these are converted at compile time to uint16_t. The hashing is based on FNV which delivers a good spread and little conflicts on the hashes generated.

    constexpr uint16_t H(const char* s){...};
    case H("request") : {
    }

Also enum fields can be handled in this way. Example KV pair : {H("parity"),H("even")}

Line format

The CBOR message is composed of KeyValue pairs. The keys are 16 bit unsigned integers, the values are any supported CBOR format. Some fields are reserved for routing purposes and standard usage. Reserved fields : "dst","src","request","reply","event","error"

So a message send to this program serial2mqtt could look like :

    H("dst"),H("mqtt"),H("request"),H("publish"),H("src"),H("Router"),H("topic"),"topic/property1",H("message"),"value1"

The JSON equivalent looks like :

{ "dst":"mqtt","src":"Router","request":"publish","topic":"topic/property1","message":"value1" }

the serial2mqtt uses default values if no extra fields are provided.

Clone this wiki locally