Skip to main content

Connhex Message Policy (CMP)

The Connhex Message Policy (CMP) describes a way for connectables to send messages.

What is it and why should I care?

You can see CMP as an abstraction over base message formats, with the main goal of routing messages based on what type of information is carried.

If the connectable-to-cloud communication correctly implements CMP, Connhex Core will automatically route messages to dedicated tables, ensuring faster data retrieval and storage costs minimization. It also provides a great starting point for many communication scenarios.

Components

There are three types of messages: infos, params and data.

TypeIDFormatNotes
InfosinfosJSONContains information that describes a connectable (e.g. serial, firmware version, ...). It consists of information that either can't be edited or doesn't change at runtime.
ParamsparamsSenMLContains all the connectable's configuration parameters (e.g. current operating mode, ...): these can be edited at runtime.
DatadataSenMLContains any time series collected by the connectable during its operation (e.g. temperature, pressure, ...).

To tag a payload according to this classification, the connectable only needs to specify the corresponding ID as the last segment of the target path 1:

channels/<chan_id>/messages/events/<ID>

If ID is not specified, all routing will default to data.

Transmission rate

The majority of use cases see data as the most frequent message, followed by params and infos. Use the table below as an additional tool to map your messages into these three types.

TypeFrequency
InfosAt every connectable boot/reboot, after a firmware update, ...
ParamsAny time one or more parameters are updated, after a network loss event (if any parameters have changed), ...
DataAny time new data is collected, or at regular intervals.

Typical usage

The CMP is typically used in a device-first approach, where each device dynamically defines the metrics it sends: what follows is a typical use case.

Suppose a web UI needs to display collected metrics as charts. It will request data through the reader API, specifying each metric as name.

Metrics

To know which metrics should be passed, one could in principle hard-code them client-side. However, this is not flexible, since it requires updating the frontend application each time a new metric needs to be displayed.

The CMP provides an immediate alternative:

  • the device sends a params message, containing all the metrics URNs
  • the UI fetches the last params message and displays a select menu with all metrics
  • once the user selects a metric, data is fetched and presented.

Now, let's imagine logged metrics change 2: the device will send another params message and the UI will automatically update. This approach offers the flexibility to choose whether to keep old metrics visible or not: just keep including them in the params message or remove them.

You can find here an implementation of this strategy.


  1. Topic if the connectable uses MQTT, URL for HTTP, ...
  2. For example, a new peripheral is connected to the device.