Difference between revisions of "MQTT Interface"

From Hubitat Documentation
Jump to: navigation, search
(Replaced content with "<big>'''We're moving!''' Please visit http://docs2.hubitat.com for the latest documentation.</big> <big> This document is available at: http://docs2.hubitat.com/en/develo...")
(Tag: Replaced)
 
(13 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=Overview=
+
<big>'''We're moving!''' Please visit http://docs2.hubitat.com for the latest documentation.</big>
'''NOTE: This interface is in alpha status and is liable to change.  Once sufficient feedback has been received it will be finalized and the method names will change.''' Hubitat allows for opening and maintaining a connection to an MQTT broker from the hub. All code needs to be contained in a driver, there is no option to open an MQTT client connection from an app. Hubitat provides methods to connect and disconnect to the broker, subscribe and publish messages to topics. In addition it is required to create a method in the driver that accepts incoming messages (parse) and another method that will be called with any status updates for the client connection (mqttClientStatus).
 
  
=Methods=
+
<big>
 
+
This document is available at: http://docs2.hubitat.com/en/developer/interfaces/mqtt-interface
==Hubitat Provided Methods==
+
</big>
 
 
===<code>mqttConnect</code>===
 
 
 
:;Signature
 
:: <code>void hubitat.helper.InterfaceUtils.alphaV1mqttConnect(DeviceWrapper device, String broker, String clientId, String username, String password)</code>
 
 
 
:;Parameters
 
:: device - The current device that is calling the method.
 
:: broker - The url of the broker to connect to.
 
:: clientId - The client id to use when connecting to the broker.
 
:: username - The username to use when connecting to the broker, use null if no username is necessary.
 
:: password - The password to use when connecting to the broker, use null if no password is necessary.
 
 
 
===<code>mqttDisconnect</code>===
 
 
 
:;Signature
 
:: <code>void hubitat.helper.InterfaceUtils.alphaV1mqttDisconnect(DeviceWrapper device)</code>
 
 
 
:;Parameters
 
:: device - The current device that is calling the method.
 
 
 
===<code>mqttSubscribe</code>===
 
:;Signature
 
:: <code>void hubitat.helper.InterfaceUtils.alphaV1mqttSubscribe(DeviceWrapper device, String topicFilter, int qos = 1)</code>
 
 
 
:;Parameters
 
:: device - The current device that is calling the method.
 
:: topicFilter - The topic / filter to subscribe to.
 
:: qos - (optional, defaults to 1) The qos to use when subscribing.
 
 
 
===<code>mqttUnsubscribe</code>===
 
:;Signature
 
:: <code>void hubitat.helper.InterfaceUtils.alphaV1mqttUnsubscribe(DeviceWrapper device, String topicFilter)</code>
 
 
 
:;Parameters
 
:: device - The current device that is calling the method.
 
:: topicFilter - The topic filter to unsubscribe from.
 
 
 
===<code>mqttPublish</code>===
 
:;Signature
 
:: <code>void hubitat.helper.InterfaceUtils.alphaV1mqttPublish(DeviceWrapper device, String topic, String payload, int qos = 1, boolean retained = false)</code>
 
 
 
:;Parameters
 
:: device - The current device that is calling the method.
 
:: topic - The topic to publish the message to.
 
:: payload - The body of the message.
 
:: qos - (optional, defaults to 1) The qos to use when publishing the message.
 
:: retained - (optional, defaults to false) Retain message in queue if subscriber is not listening.
 
 
 
===<code>parseMqttMessage</code>===
 
:;Signature
 
:: <code>Map hubitat.helper.InterfaceUtils.alphaV1parseMqttMessage(String stringToParse)</code>
 
 
 
:;Parameters
 
:: stringToParse - The string coming from the MQTT brokers subscribed topic.
 
 
 
:;Returns
 
:: Map - the string passed as a parameter is split into a Map and returned.
 
 
 
==User defined methods==
 
 
 
: '''<code>parse(String message)</code>'''  - This method is called with any incoming messages from the subscribed topics of the MQTT broker. This is a standard method for drivers.
 
 
 
: '''<code>mqttClientStatus(String message)</code>''' - This method is called with any status messages from the MQTT client connection (disconnections, errors during connect, etc)
 

Latest revision as of 19:47, 25 September 2022

We're moving! Please visit http://docs2.hubitat.com for the latest documentation.

This document is available at: http://docs2.hubitat.com/en/developer/interfaces/mqtt-interface