ph_mqttpub (General syntax) PowerHome formula function
Description
Publishes an MQTT topic/message using
an MQTT controller actively setup and configured within PowerHome. For
topics already defined in the MQTT->MQTT Publish section of PowerHome
Explorer, please see this version of the ph_mqttpub function:
ph_mqttpub (MQTT table)
Syntax
ph_mqttpub ( as_ctlr, as_topic, as_message, ai_qos, ai_retain, ai_type )
Argument | Description |
as_ctlr | String. The ID of the MQTT controller within PowerHome |
as_topic | String. The MQTT topic to publish to |
as_message | String. The message for the MQTT topic |
ai_qos | Integer. The MQTT QOS (Quality Of Service).
Valid values are 0, 1, and 2. Any other value will be treated as 0 |
ai_retain | Integer. The MQTT retain message flag. Use 0
to not retain the message, any other value to retain this message |
ai_type | Integer. Specifies how the message is to be
published. A value of 0 will send the message to the controller queue
where it is executed after other queued messages. Any other value causes
the controller to send the message immediately with feedback if
an error occurs |
Return value
Integer. Returns 0 if message was
queued successfully when ai_type = 0. Returns 0 if message was published
successfully when ai_type <> 0. Returns -1 if the controller ID is
not found. Returns -51 if the command is not supported by the controller.
Returns -11 if an error occurs during publish
when ai_type <> 0
Usage
Use this function to publish MQTT messages
to a topic using a currently connected PowerHome MQTT controller. This
particular syntax for ph_mqttpub( ) is to publish general topics/messages that
are not currently defined within the Analog I/O screen or the MQTT Publish
screen. For more information concerning MQTT, the protocol, and how it
is used, a very good reference can be found here:
https://www.hivemq.com/mqtt-essentials/
Examples
The following examples demonstrate typical syntax/usage for this function.
• ph_mqttpub("MQTT","home/1stfloor/familyrm/temperature","78.3",0,0,0)
- Returns a 0 if the topic/message was successfully queued. This example will
publish a message of "78.3" to the "home/1stfloor/familyrm/temperature" topic
with a QOS level of 0. The message will not be
retained.