Skip to main content

Custom services

Connhex Edge enables a new and better way of writing firmware for your IoT applications. Forget about flashing configuration files and certificates in your devices or implementing communication-related pieces of code. Just focus on the development of the core logic of your application: sending data to your remote Connhex instance will be as easy as pushing data to a queue.

Message queue

All messages sent or received by devices leveraging Connhex Edge are handled by a Publish-Subscribe message queue: each custom service can subscribe to a particular subject and push or consume data from it.

The implementation of this mechanism at the core of Connhex Edge is based on its APIs can then be used to handle your data (check NATS official documentation for further details).

Connhex Edge: services


NATS implements a one-to-many publish-subscribe pattern where a publisher sends a message on a specific subject and any active subscriber listening on that subject receives the message.

NATS subjects to MQTT topics mapping

When a message is published to a NATS subject by an edge device, it will eventually be converted to a MQTT message by Connhex Edge and then sent through a specific topic to the infrastructure.

The mapping between NATS subjects and MQTT topics is specified in the auto-generated export.toml file (specifically in the routes file section) inside your device.

Check the following example:



mqtt_topic = "channels/6abff700-344c-47d3-bcf8-53ef29f36277/messages"
nats_topic = "edge"
subtopic = ""
type = "default"
workers = 0


In this case, all messages published to the NATS subject named edge will be automatically sent to Connhex through the channels/6abff700-344c-47d3-bcf8-53ef29f36277/messages MQTT topic.

The mapping can be updated and customized on a per-device basis directly from Connhex Control.

MQTT topics to NATS subjects mapping

When a MQTT message is sent from the Connhex remote instance down to an edge device running Connhex Edge, it is automatically converted to a NATS message and then published on a specific subject.

As discussed in the Publishing a message section, the standard MQTT topic to send data from Connhex to any device is channels/<channel_id>/messages. If you're targeting a specific custom service running on your edge device, the MQTT topic will be channels/<channel_id>/messages/services/<service_name>. On the edge, instead, the standard NATS topic where messages coming from the Connhex instance are received is commands/<service_name>.

Heartbeat messages

Heartbeat messages are used by the Connhex Edge agent to understand whether a custom service is healthy or not. It periodically (by default every 10 seconds) checks if all services have published a heartbeat message to a specific NATS subject (i.e. heartbeat.<service_name>.service). If a service did not sent any heartbeat, it is marked as down.

The status of each custom service running on the edge device can be retrived remotely using Connhex Control.