Docs

OverviewGetting started
guides
AccountConnect a sensorGetting startedBuild a dashboardData & actionsTroubleshooting
reference
SIGPAC layerParcel GPS layerDatapanelsJSON formatMQTT
DocumentationMQTT

MQTT

MQTT (Message Queuing Telemetry Transport) is the protocol used to exchange messages between a sensor, an MQTT broker, and Visamic.

For protocol background, see the official MQTT website.

How the connection works

The sensor publishes a message to a topic on a broker. Visamic subscribes to that topic, reads the payload, and exposes the configured attributes to Things and panels.

The same broker, topic, authentication, and TLS settings must be configured on both sides.

Publishing and subscribing

There are two independent connections:

  • The sensor publishes messages.
  • Visamic subscribes to the topic and consumes those messages.

You can test both sides with the Mosquitto clients:

mosquitto_sub -h <broker> -p <port> -t <topic> -u <username> -P <password>
mosquitto_pub -h <broker> -p <port> -t <topic> -u <username> -P <password> -m '<json-payload>'

Add the TLS options required by the broker, such as --cafile, before running these commands.

Connection settings

The connection usually requires:

  • Broker hostname
  • Port
  • Topic
  • Client ID, when required by the broker
  • Username and password, when authentication is enabled
  • TLS and certificate settings, when encryption is enabled

Broker hosts, ports, credentials, and certificates can vary by environment. Use the values shown by the current Visamic configuration instead of relying on an old example.

Client ID

The client ID identifies an MQTT connection. Many brokers require it to be unique among active clients. If the publisher and subscriber disconnect each other, try using different client IDs.

Topics

Topics route messages through the broker. The publisher and subscriber must use the same topic, including its case and slash-separated segments.

Topics are commonly hierarchical, for example factory/line-1/temperature. Choose a topic convention that makes it clear which device owns each message.

For topic syntax, see the Mosquitto MQTT manual.

Quality of Service

MQTT provides three Quality of Service (QoS) levels:

  • QoS 0: at most once; no delivery confirmation.
  • QoS 1: at least once; a message may be delivered more than once.
  • QoS 2: exactly once; uses the most extensive handshake.

Choose the QoS level supported by both the broker and the client. Higher levels add delivery guarantees and protocol overhead.

Retained messages

When the retain flag is enabled, the broker stores the latest message for a topic and sends it to a new subscriber. This can be useful when sensors publish infrequently, but retained values should be kept current and meaningful.

Sending commands to a device

Visamic can also write to a device, for example to switch a relay when a trigger fires. Add a Thing action to a trigger, choose the Thing attribute and the value to send, and Visamic delivers it to the device that provides that attribute.

Commands are optional. Open the device details page and use the Configure button in the Device commands section. They work for MQTT, LoRaWAN, and REST devices. Database and file sources cannot receive commands.

MQTT and LoRaWAN

Set a Command topic. Visamic publishes the command there with QoS 1 and no retain flag, so the device never receives a stale command when it reconnects.

  • The command topic must not contain wildcards (+ or #).
  • It must differ from the data topic, and the data topic must not cover it. Otherwise Visamic would read its own command as device data. Such commands are rejected.
  • On the Visamic broker, the command topic must start with commands/<organization-id>/ (for example commands/<organization-id>/pump-1), so an organization can only command its own devices. External brokers have no such restriction.
  • The device must subscribe to the command topic and be allowed to receive it by the broker ACL.
  • These rules are checked when the device is saved, not only when a command is sent.

REST

Set a Command URL and a method (POST, PUT, or PATCH). The authentication headers configured for the device are reused. Visamic sends an Idempotency-Key header equal to the command ID, and any 2xx response counts as delivered.

Payload

By default the payload is a JSON object:

{ "commandId": "6f1c2e0a-0b53-4f7e-9c0e-5a1d2b3c4d5e", "attribute": "relay", "value": "on" }

attribute is the key the device uses for that attribute. It is the Command key of the Thing attribute when one is set (edit the attribute to set it) and the attribute's Source ID otherwise. Set a Command key when the Source ID is a path such as $.[0].v, which a device cannot use as a key. value is a number or boolean when the configured value is one, and a string otherwise.

To match a device's own format, set a Payload template. These placeholders are replaced:

PlaceholderReplaced with
{{commandId}}The command ID, escaped for use inside a JSON string.
{{attribute}}The attribute key, escaped for use inside a JSON string.
{{value}}The value, escaped for use inside a JSON string.
{{valueJson}}The value as a JSON literal: a number, true/false, or a quoted string. No quotes.
{{valueBase64}}The value encoded in Base64, as LoRaWAN network servers expect for downlink payloads.

For example, a downlink for The Things Stack:

{ "downlinks": [{ "f_port": 1, "frm_payload": "{{valueBase64}}", "priority": "NORMAL" }] }

Testing a device's commands

On the device details page, the Device commands card has a Send test command button. It sends a real command with an attribute and a value you type, using the saved settings, the same way a trigger action does, and shows where it was delivered or why it failed. It needs the settings to be saved first. Because the command is real, use it with care on devices that act on it (a relay, a pump). Only organization admins and managers can use it.

Delivery and retries

A command counts as delivered when the broker accepts the message (MQTT) or the endpoint answers 2xx (REST). That confirms delivery to the broker or endpoint, not that the device executed it. Visamic does not wait for the device to reply.

Temporary failures are retried with increasing delays. Configuration errors, such as a missing or invalid command topic or URL, are not retried and fail immediately. Every retry reuses the same commandId, so a device that receives a duplicate can recognize and ignore it. MQTT QoS 1 is also at-least-once, so devices should handle repeated commands.

Example payload

This valid payload contains two named measurements with a timestamp:

[
  {
    "temperature": [{ "t": "2023-05-23T17:11:13+02:00", "u": "°C", "v": 27 }]
  },
  {
    "humidity": [{ "t": "2023-05-23T17:11:13+02:00", "u": "%", "v": 60 }]
  }
]

See the JSON data format reference for more payload shapes, including map coordinates.

Visamic
  • Home
  • Pricing
  • Resources
  • Blog
  • Docs

Visamic

The IoT platform for managing devices, collecting real-time data, and visualizing operations with clarity.

LegalContact InformationWhat’s newServices Status
Kit Digital - CatalanaportesKit Digital - Catalanaportes

© 2026 Steema Software SL. All rights reserved.

Sign InGet Started Free
Sign In