Caution! Article for developers
Information on this page is intended particularly for users with advanced technical knowledge.How to modify MQTT subtopics
Jul 26, 2024 · 3 minutes to read
Introduction
By changing cloud adapters configuration from /opt/iotgw/conf.d by adding file with name ending with .conf you can change mqtt pub/sub topics.
This can be done with for example “nano /opt/iotgw/conf.d/mqtt_topics.conf” and adding configuration below to the file. Remember to change the “CloudAdapter” section name to your cloud adapters name.
If your cloud adapter was created with config UI (via the browser) the cloud adapters name should be “CloudConfigUI”.
[CloudAdapter]
/# Publishing topic
MqttPubTopic = treon/devices/{CID}
/# Subscribing topic
MqttSubTopic = treon/devices/{CID}/devicebound/#
where {CID}:
/## MQTT topic definition
/## topic can contain variables:
/## {GID} - gateway id
/## {SID} - sensor id
/## {CID} - mqtt client id
/## {T} - topic from zero MQ queues. Set e.g. by variable CloudTopic
/##
You can change your MQTT publishing and subscribing topics by creating a cloud adapter configuration file (or editing if it exists already) in the /opt/iotgw/conf.d folder. Remember to change the CloudAdapter section name to your cloud adapter’s name. If your cloud adapter was created with Config UI, the cloud adapter’s name should be CloudConfigUI.
Step 1: Connect to the Gateway via SSH
Step 2: Navigate to the right folder
Navigate to the conf.d folder using the command: cd /opt/iotgw/conf.d
Step 3: Configuration file
Create a configuration file using a text editor, e.g. Nano: ‘nano cloudtopic.conf’. If you already have a cloud configuration file, you can add the topic settings to your file under your cloud adapter. Keep in mind that if there is any conflicting configurations in other configuration files, the last one in alphabetical order will be applied. Therefore you should name your file appropriately to be the last one.
Replace cloudtopic with the name you would like instead. The text editor will now open. Paste the following lines inside the .conf file using right click and edit the fields required for your connection type. The ‘#’ or ‘##’ symbols mean comments, and that line is not executed unless you remove the symbols # or ##. Comment or delete unused lines depending on your cloud configuration.
[CloudAdapter]
# Publishing topic
MqttPubTopic = treon/devices/{CID}
# Subscribing topic
MqttSubTopic = treon/devices/{CID}/devicebound/#
## where {CID} is a variable:
## MQTT topic definition
## topic can contain variables:
## {GID} - gateway id
## {SID} - sensor id
## {CID} - mqtt client id
## {T} - topic from ZeroMQ queues. Set e.g. by variable CloudTopic
##
Step 4: Save & Exit
Save the file by pressing Ctrl + S. Then exit from Nano by pressing Ctrl + X.
Step 5 Restart the Iotgw
Restart the Iotgw service with the following command:
systemctl restart iotgw
Treon Support
You still have questions? Our dedicated team of experts is happy to help you! Please contact Treon Support directly by e-mail.
Did you know? Treon offers Premium Support and Maintenance Packages for our customers. Get even more out of Treon and boost your sales - inquire now about features and prices!