Skip to content

UART Protocol & Firmware Integration

Provided Files

UART communication with the module is handled by the library:

yuki_module_client.c / yuki_module_client.h

For debugging purposes a python client is also available:

yuki_module_client.py

These files encapsulate the protocol and provide a simple interface for integration into your own firmware.

Integration into Your Own Firmware

Initialization

c
YukiModuleInterface iface = {
    .ctx = uart_ctx,
    .read = uart_read_fn,
    .write = uart_write_fn,
    .handler = on_value_changed
};

yuki_module_init(&iface, NULL);

Initialization is performed via yuki_module_init() with a configuration structure YukiModuleInterface, which registers read/write functions as well as a callback for incoming data:

Callback Mechanism

The callback handler(id, type, read_only, data, len) is called for incoming SET commands and passes:

  • id: identifier of the parameter
  • type: data type (e.g. TYPE_UINT8, TYPE_STRING, etc.)
  • read_only: flag indicating whether the value is write-protected
  • data: pointer to payload data
  • len: length of the payload

UART Protocol – Technical Description

The module communicates using a binary, compact TLV protocol (Type-Length-Value) over a simple UART connection. The interface is optimized for resource-constrained systems and supports both simple values and more complex payloads.

Message Format

Each message consists of a 2-byte header, a payload of up to 511 bytes, and a 2-byte CRC checksum:

Telegrammaufbau1

OffsetFieldSizeDescription
0T7 bitsType or command (e.g. CMD_SET)
0L[8]1 bitHighest bit of the payload length (bit 8 / 9)
1L[7:0]8 bitsLower 8 bits of the payload length
2VL bytesPayload

The type is left-aligned in the first 7 bits of byte 0. The 8th bit of this byte is the highest bit of the payload length. Byte 1 contains the remaining 8 bits of the payload length. This results in a maximum payload size of 511 bytes.

Telegrammaufbau2

byte0 = (T<<1) | ((L >> 8) & 1), byte1 = L & 0xFF

Protocol Commands

Type valueSymbolDescriptionResponse payload
0x00CMD_GET_PUBKEYReturns the module's public signature keyBinary public key (64 bytes)
0x01CMD_GET_IMEIReturns the modem IMEIIMEI string (15 bytes)
0x02CMD_GET_ICCIDReturns the SIM ICCIDICCID string (20 bytes)
0x04CMD_SETTransfers a value to the moduleNone
0x05CMD_SYNCSynchronizes all values with the cloudNone
0x06CMD_VERSIONReturns the module firmware versionVersion number as string
0x07CMD_STATUSReturns the system status (0 for OK or error codes)None
0x08CMD_GEO_REQRequests the current GNSS coordinatesNone
0x09CMD_GEO_RPTResponse message with GNSS coordinates

CMD_GEO_RPT Payload

OffsetSizeField nameTypeDescriptionUnit
01fix_typeUINT80 = no fix, 1 = 2D, 2 = 3D fix-
11satsUINT8Number of visible/used satellites-
24ts_utcUINT32UTC timestamp (Unix time in seconds)s
64lat_e7INT32Latitude (WGS-84)1e-7 °
104lon_e7INT32Longitude (WGS-84)1e-7 °
144alt_cmINT32Altitude above MSLcm
184hdop_centiUINT32Horizontal accuracy (HDOP × 100)1 = 0.01 HDOP
Total22 bytes--Fixed payload size for CMD_GEO_RPT-

The commands CMD_GET_PUBKEY, CMD_GET_IMEI, CMD_GET_ICCID, CMD_SYNC, CMD_VERSION, CMD_GEO_REQ and CMD_STATUS have no payload. Only the type (command byte) and length 0 are transmitted.

CMD_SET

The payload of a CMD_SET message has the following structure:

OffsetFieldSizeDescription
0ID High1 byteHigh byte of the parameter ID
1ID Low1 byteLow byte of the parameter ID
2Flags1 byteBit 4 = read_only; other bits reserved
3Type1 byteData type (see below)
4Len High1 byte(for binary and string data only): payload length, MSB
5Len Low1 byte(for binary and string data only): payload length, LSB
6Payloadn bytesValue, depending on type
6+nChecksum2 bytesCRC checksum

For non string-based types the explicit length field is omitted; the length is implied by the data type.

Supported Data Types

CodeTypeDescription
0x01INT324 bytes
0x02INT162 bytes
0x03INT81 byte
0x04UINT324 bytes
0x05UINT162 bytes
0x06UINT81 byte
0x07BOOL1 byte (0x00 or 0x01)
0x08UUID16 bytes
0x09FLOATIEEE754, 4 bytes
0x0ADATETIMEe.g. Unix timestamp
0x0BDOUBLE8 bytes
0x0CBINLength + data field
0x0DUINT648 bytes
0x0ESTRINGLength + UTF-8 data
0x0FINT648 bytes, signed

Response Messages

Every received command is acknowledged with a response message. It contains:

  • T: identical to the received message
  • L: (at least 1)
  • V[0]: error code (ErrCode)
  • V[1..n]: response payload, if present
  • CRC[n+1..n+2]: CRC16 checksum

Payload

Error Codes (ErrCode)

ValueMeaning
0x00OK
0x01Invalid command
0x02Invalid argument
0x03Device busy
0xFFInternal error

Checksum Calculation

Each message is terminated with a 16-bit checksum (CRC-16/CCITT-FALSE) used to ensure the integrity of header and payload. The checksum is calculated over all bytes of header and payload, but not over the CRC bytes themselves.

ParameterValue
Generator polynomial0x1021
Initial value0xFFFF
Final XORnone (0x0000)
Bit orderMSB-first
Checksum rangeHeader (2 bytes) + payload (L bytes)
c
uint16_t crc16_ccitt_false(const uint8_t *data, size_t len)
{
    uint16_t crc = 0xFFFF;
    for (size_t i = 0; i < len; ++i) {
        crc ^= (uint16_t)data[i] << 8;
        for (int b = 0; b < 8; ++b) {
            crc = (crc & 0x8000) ? (uint16_t)((crc << 1) ^ 0x1021) : (uint16_t)(crc << 1);
        }
    }
    return crc;
}

CRC Algorithm (reference implementation in C)

Example Message (CMD_SET, UINT8)

Header: **0x08 0x05** // T = 0x04 (CMD_SET), L = 5

Payload: 0x12 0x34 0x00 0x06 0x05 [IDH IDL FLG TYP VAL ]

Checksum: 0xF7 0x07

Parameter IDs and Mapping

The UART protocol commands use numeric parameter IDs that can be freely assigned by the user. There is no fixed list – instead, the developer can define the meaning of the IDs individually.

In the cloud (both in the dashboard and via the REST API), descriptive names and types can be assigned to these IDs. This ensures that all transmitted values are correctly named and processed in context – regardless of the numeric ID.

Example: The value with parameter ID 0x1234 can be registered in the cloud as "Battery voltage" and later be read or visualized under this name.