MQTT

Here’s the complete document translated into English:

Introduction to MQTT

MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol ideal for devices with limited resources and low-bandwidth networks. MQTT operates on a publish/subscribe model, where clients can publish messages to specific “topics” and subscribe to these topics to receive messages.

What is an MQTT Broker?

An MQTT broker is a server that receives messages published by clients and distributes them to the corresponding subscribers. Mosquitto is a popular example of an MQTT broker that can be used with Calaos.

Enabling Mosquitto in Calaos

Mosquitto is already integrated into Calaos OS. You just need to enable it to use it.

To enable Mosquitto in Calaos, use the following command:

systemctl enable --now mosquitto

You can configure authentication and other settings in the configuration file located at /mnt/calaos/mosquitto/config/mosquitto.conf.

To apply the configuration changes, restart Mosquitto with:

systemctl restart mosquitto

Debugging

To debug what is happening with MQTT, you can use a tool like MQTTX. MQTTX allows you to connect to the MQTT broker and monitor the exchanged messages, which is useful for testing and verifying the configurations of topics and payloads.

Using MQTT in Calaos

In Calaos, MQTT can be used for different types of inputs and outputs (IO). Each MQTT IO must be configured with topic_sub, topic_pub, and path.

Supported MQTT IO Types

  • Temperature sensor
  • Switch
  • Analog input
  • Text input
  • Light On/Off
  • Dimmable light
  • RGB light
  • Analog output

Example Configuration of an MQTT Temperature Sensor

To configure an MQTT temperature sensor in Calaos, suppose the sensor sends its value in JSON format to the topic mqtt_devices/temp_01 with the following JSON payload: { "temp": 24.15, "humidity": 43, "battery": 85 }. For this configuration, we will focus on the temperature value.

Configuration Parameters:

Here is the configuration to adopt in Calaos Installer when creating the MQTT Temperature IO:

NameValue
nameTemperature Sensor
topic_submqtt_devices/temp_01
pathtemp
host127.0.0.1
port1883
precision1

By configuring these parameters in Calaos, you will be able to receive and display the temperature values sent by the MQTT temperature sensor.

General Parameters for MQTT IOs

NameTypeMandatoryDescription
topic_substringyesTopic to subscribe to.
topic_pubstringyesTopic to publish to.
pathstringyesPath to find the value in the MQTT payload. If the payload is JSON, the information will be extracted based on the path.
userstringnoUser for authentication with the MQTT broker. Password must be defined in this case.
keepaliveintnoKeepalive time in seconds. Time between two MQTT PINGs.
portintnoTCP port of the MQTT broker. Default value is 1883.
passwordstringnoPassword for authentication with the MQTT broker. User must be defined in this case.
hoststringnoIP address of the MQTT broker. Default value is 127.0.0.1.
enabledboolnoEnable the Input/Output. Default value is true. This parameter is added if it is not found in the configuration.
log_historyboolnoIf enabled, write an entry in the event log history for this IO.
visibleboolnoDisplay the Input/Output on all user interfaces if set. Default to true.
loggedboolnoIf enabled, and if influxdb is enabled in the local configuration, send the value to influxdb for this IO.
gui_typestringnoInternal graphical type for all Calaos objects. Read-only parameter, set automatically.
io_typestringyesIO type, can be “input”, “output”, “inout”.
idstringyesUnique ID identifying the Input/Output in calaos-server.

Specific Parameters for Each Type of MQTT IO

MqttInputAnalog

Analog input used to read analog values, display them, and use them in rules.

NameTypeMandatoryDescription
topic_substringyesTopic to subscribe to.
topic_pubstringyesTopic to publish to.
precisionintnoPrecision of the returned value. Represents the number of decimals after the dot.
namestringyesName of the Input/Output.
pathstringyesPath to find the value in the MQTT payload.
io_stylelistyesGUI display style.
coeff_afloatnoUsed with coeff_b to apply an equation of the form displayed_value = coeff_a * raw_value + coeff_b. Default value is 1.0.
coeff_bfloatnoUsed with coeff_a to apply an equation of the form displayed_value = coeff_a * raw_value + coeff_b. Default value is 0.0.
unitstringnoUnit displayed on the UI as a suffix.

MqttInputString

Text input used to read string values.

NameTypeMandatoryDescription
topic_substringyesTopic to subscribe to.
topic_pubstringyesTopic to publish to.
namestringyesName of the Input/Output.
pathstringyesPath to find the value in the MQTT payload.

MqttInputSwitch

Switch with press/release states.

NameTypeMandatoryDescription
on_valuestringyesValue to interpret as ON.
off_valuestringyesValue to interpret as OFF.

MqttInputTemp

Temperature sensor used to display temperature and control heating devices via rules based on the temperature value.

NameTypeMandatoryDescription
topic_substringyesTopic to subscribe to.
topic_pubstringyesTopic to publish to.
precisionintnoPrecision of the returned value.
namestringyesName of the Input/Output.
pathstringyesPath to find the value in the MQTT payload.

MqttOutputAnalog

Analog output used to control analog output devices connected to Calaos.

NameTypeMandatoryDescription
datastringyesData sent when publishing to the topic.
stepfloatnoSet a step for increment/decrement value. Default is 1.0.

MqttOutputLight

Basic light with only two states, ON or OFF. Can also be used to control simple relays.

NameTypeMandatoryDescription
datastringyesData sent when publishing to the topic.
on_valuestringyesValue to interpret as ON.
off_valuestringyesValue to interpret as OFF.

MqttOutputLightDimmer

Light with dimming control. Light intensity can be changed.

NameTypeMandatoryDescription
datastringyesData sent when publishing to the topic.

MqttOutputLightRGB

RGB light. Choose a color to be set for this light.

NameTypeMandatoryDescription
path_brightnessstringyesPath to find the brightness value in the MQTT payload.
path_ystringyesPath to find the Y (X/Y Color space) value in the MQTT payload.
path_xstringyesPath to find the X (X/Y Color space) value in the MQTT payload.
datastringyesData sent when publishing the color to the topic.