ph_mqttsub PowerHome formula function
Description
Allows the specified PowerHome
MQTT controller to subscribe to
MQTT topics
Syntax
ph_mqttsub ( as_ctlr, as_topic, ai_qos, ai_type )
Argument | Description |
as_ctlr | String. The ID of the PowerHome MQTT controller |
as_topic | String. The MQTT topic to subscribe to.
Wildcards are allowed |
ai_qos | Integer. The QOS (Quality of Service) level.
Valid values are 0, 1, and 2 |
ai_type | Integer. Specifies how the subscription
request is handled within PowerHome. A value of 0 will queue the request
with the specified controller. Any other value will cause the the
controller to immediately send the request and receive feedback of success/failure |
Return value
Integer. Returns 0
if request for subscription was queued successfully when ai_type = 0.
Returns 0 if subscription to topic was successful 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 subscription when ai_type <>
0
Usage
Use this function to subscribe
to MQTT topics using a currently connected PowerHome MQTT
controller. The PowerHome MQTT controller allows you to declare Analog I/O
devices with a Publish Topic and a Subscribe Topic and will already be
subscribed by the controller. The PH MQTT controller also supports
Subscribed topics delcared in the PowerHome Explorer under
PowerHome->MQTT->MQTT Subscribe. You would typically use this
function to subscribe to topics that are NOT already subscribed to with
the Analog I/O section or the MQTT Subscribe section (doing so
would be redundant). If you subscribe to a topic using this function
that is not already subscribed via Analog I/O or MQTT Subscribe, then the MQTT
controller will fire a Generic Controller trigger for the
controller on Command 1, Option 1 whenever a published message
matching the topic is received. The trigger variables will hold the topic, the
message, the QOS, the retain flag, and whether or not the message is
a duplicate
Examples
The following examples demonstrate typical syntax/usage for this function.
• ph_mqttsub("MQTT","home/1stfloor/+/temperature",0,1) -
Returns a 0 if the topic subscription was successful. Returns -11 if an error
occurred. This example subscribes to a wildcard topic for all temperatures on
the 1st
floor