MQTT API¶
You may enable the smartdirector to interface with external systems using MQTT publish-subscribe paradigm through a dedicated MQTT broker. The smartdirector works as a MQTT client performing publish or subscribe actions on topics defined that correspond to the data model attributes.
MQTT APIs are not enabled by default. To enable the APIs, you must configure the broker related settings before you enable the service.
Enabling MQTT API service
- Navigate to the Commission System application in smartmanager and select the MQTT tab under the System Settings section.
- Configure IP address of the MQTT Broker and client ID (smartdirector identity as reported to the broker)
- Configure the other settings as appropriate based on your environment
- Upload the certificates for the authentication
- The MQTT service is automatically restarted upon saving the configuration changes
- Check the the status of the connection to broker to ensure that the smartdirector is connected to the broker.
The external applications may now publish and subscribe to the attributes of the data model that are available as topics in the broker.
MQTT Brokers and Topics¶
Different MQTT Brokers may require the topics to be specified differently. These can be configured by setting the subscription topic and publishing topic settings in the MQTT configuration. Preset definitions exist for some of the common cloud providers like IBM Watson IOT, Microsoft Azure IOT, Amazon AWS IOT. You may also provide a custom definition that your broker expects.
The data formats follow the data model discussed in the HTTPs API reference1.
The following are examples of publish and subscribe commands using Mosquitto2 clients with its broker using the Default brokertype settings.
mosquitto_sub -t "smartengine/event/type/location/id/106/wallSwitch/#" -u <USERID> -P <PASSWORD>
Response | |
---|---|
|
mosquitto_pub -t "smartengine/command/type/location/id/106/wallSwitch" -u <USERID> -P <PASSWORD> -m
request data | |
---|---|
|
mosquitto_pub -t "smartengine/command/type/location/id/0/policyTrigger" -u <USERID> -P <PASSWORD> -m
request data | |
---|---|
|
Additional use cases can be implemented with MQTT in same manner as above using the examples and data models discussed in API reference guide1.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article