Skip to main content

FLAP Message Types

A message is reassembled from the data of all fragments of one transfer (see Transfers). Its first byte is the message type, the rest is the value:

+----------+------------------------------+
| Type | Value |
| 1 byte | 0 to 16383 bytes |
+----------+------------------------------+

Most values are CBOR maps with small integer keys. The Cloud ignores a message with an unknown type or an invalid value and does not acknowledge it.

Message Types​

TypeNameDirectionValue
0x00CREATE_SESSIONUplinkCBOR map with information about the device
0x01GET_TIMESTAMPUplinkEmpty. The Cloud answers with SET_TIMESTAMP
0x02UPLOAD_CONFIGUplinkConfiguration hash (8 B), 0x00, CBOR array of configuration lines
0x03UPLOAD_DECODERUplinkCodec hash (8 B), CBOR decoder definition
0x04UPLOAD_ENCODERUplinkCodec hash (8 B), CBOR encoder definition
0x05UPLOAD_STATSUplinkCBOR map with uptime and cellular network statistics
0x06UPLOAD_DATAUplinkDecoder hash (8 B), CBOR application data
0x07UPLOAD_SHELLUplinkCBOR map with results of shell commands
0x08UPLOAD_FIRMWAREUplinkCBOR map with a firmware update request or status
0x80SET_SESSIONDownlinkCBOR map with the session parameters
0x81SET_TIMESTAMPDownlinkUnix time in seconds as a 64-bit integer (8 B)
0x82DOWNLOAD_CONFIGDownlink0x00, CBOR array of configuration commands
0x86DOWNLOAD_DATADownlinkEncoder hash (8 B), CBOR application data
0x87DOWNLOAD_SHELLDownlinkCBOR map with shell commands to run
0x88DOWNLOAD_FIRMWAREDownlinkCBOR map with a firmware chunk
0xFFREQUEST_REBOOTDownlinkReserved

Session Start​

After the device connects to the network, it opens a session before it sends any data:

  1. The device sends CREATE_SESSION. The Cloud acknowledges it with the P flag, because the SET_SESSION response is waiting.
  2. The device polls and receives SET_SESSION. It sets its clock from the timestamp in it.
  3. SET_SESSION contains the hashes of the decoder, encoder and configuration the Cloud knows for this device. The device uploads only those that differ: UPLOAD_DECODER, UPLOAD_ENCODER, UPLOAD_CONFIG.
  4. The device is ready to send UPLOAD_DATA and to poll for downlinks.

The FLAP headers of the first five packets are c000, 3001, 1002, c003 and 2004.

CREATE_SESSION​

KeyValueType
0Watchdog timeout (reserved, 0)Integer
1Vendor nameText
2Product nameText
3Hardware variantText
4Hardware revisionText
5Firmware bundleText
6Firmware nameText
7Firmware versionText
8Bluetooth passkeyText
9IMSIInteger
10IMEIInteger
11Modem firmware versionText
12 to 15CHESTER-Z serial number, hardware revision, hardware variant, firmware version (only with CHESTER-Z)Text
16Serial numberInteger
17ICCIDText

SET_SESSION​

KeyValueType
0Session IDInteger
1Decoder hashInteger (64 bit)
2Encoder hashInteger (64 bit)
3Configuration hashInteger (64 bit)
4Current time, Unix time in secondsInteger
5Device ID in HARDWARIO CloudText
6Device name in HARDWARIO CloudText

Codecs and Data​

A decoder converts CBOR data from the device into JSON, an encoder converts JSON downlinks into CBOR. Both are built into the firmware and uploaded automatically during the session start, so the Cloud always decodes data with the codec of the firmware that sent it.

The codec hash identifies a codec. It is computed over the CBOR codec definition (the value after the hash):

digest = SHA-256( codec )
w[k] = digest[8k .. 8k+7] read as a little-endian 64-bit integer for k = 0..3
hash = w[0] ^ w[1] ^ w[2] ^ w[3] (sent as big-endian)

The Cloud checks the hash of an uploaded codec. UPLOAD_DATA and DOWNLOAD_DATA start with the hash of the codec that the data belongs to.

Configuration​

UPLOAD_CONFIG carries the configuration of the device as a CBOR array of text lines in the format of the config show shell command, preceded by an 8-byte configuration hash and the byte 0x00 (no compression). The Cloud stores the hash and returns it in SET_SESSION, so the device uploads its configuration only when it has changed.

DOWNLOAD_CONFIG carries configuration commands, see Config downlink. The device runs them, saves the configuration and reboots.

Shell Commands​

DOWNLOAD_SHELL is a CBOR map with an array of commands (key 0) and a 16-byte message ID (key 1). The device runs the commands and answers with UPLOAD_SHELL: a CBOR map with an array of results (key 0) and the same message ID (key 1). Each result contains the command (key 0), its return code if it is not zero (key 1) and an array of output lines (key 2). See Shell downlink.

Firmware Update​

Firmware updates over the air use UPLOAD_FIRMWARE and DOWNLOAD_FIRMWARE:

  1. The device requests an update with the type download and the firmware ID.
  2. The Cloud sends the firmware in chunks (type chunk). The device answers each chunk with the type next and the offset of the next chunk.
  3. After the last chunk the device reports swap and reboots into the new firmware.
  4. After a successful boot it reports ack. If anything fails it reports error.

See Firmware for how to start an update from HARDWARIO Cloud.