Caution! Article for developers

Information on this page is intended particularly for users with advanced technical knowledge.

How to modify MQTT subtopics

Jan 27, 2023 · 4 minutes to read

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/devicebound/{CID}/#  
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/devicebound/{CID}/#  
## 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 + O. Then exit from Nano by pressing Ctrl + X.

 

Step 5 Check Cloud Adapter

To check if cloud adapter is on the startup list, you can navigate to cd /opt/iotgw and view the gw.conf file by typing in cat gw.conf or less gw.conf.

You should look under [Startup] and see if there is CloudAdapters = CloudAdapter present. Remember that cloud adapters can be renamed, and then the new name should be used in both configurations (configuration file and startup list). If your cloud adapter is not on the startup list, then you have to add a startup configuration to your configuration file:

[Startup]
CloudAdapters = CloudAdapter

If there are additional cloud adapters configured to start, you have to also add them on the list. Otherwise they will not start if you override the CloudAdapters startup with only your new cloud adapter included.

Example:

[Startup]
CloudAdapters = CloudAdapter,WNTCloudAdapter,AnotherCloudAdapter

You can check from /opt/iotgw/gw.conf or other configuration files in the /opt/iotgw/conf.d folder to see which cloud adapters need to be started before you apply your configuration settings.

 

Step 6: Reboot

To complete the procedure, proceed the Treon Gateway.

 

Treon Customer Support

If you are at any point of you are unsure how to continue, please contact Treon Customer Support.

 

Treon Customer Support

If you have further questions, please contact Treon Customer Support.

   


Was this article helpful? Let us know.
Next