This shows you the differences between two versions of the page.
uphp:functions:mqtt_subscribe [2019/11/29 05:02] admin |
uphp:functions:mqtt_subscribe [2021/09/13 05:57] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======mqtt_subscribe====== | ||
- | |||
- | < | ||
- | |||
- | Subscribe to an MQTT channel | ||
- | |||
- | ====Description==== | ||
- | |||
- | <well size=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | </ | ||
- | |||
- | ====Parameters==== | ||
- | |||
- | < | ||
- | |||
- | < | ||
- | |||
- | ====Return Values==== | ||
- | |||
- | 1 if successful and 0 on failure | ||
- | |||
- | ====Example==== | ||
- | |||
- | <code php> | ||
- | <? | ||
- | // Use the # as a wildcard so any messages to /cluster/1/ or its sub channels will be received | ||
- | |||
- | mqtt_subscribe("/ | ||
- | ?> | ||
- | </ | ||
- | |||
- | ====Example Callback==== | ||
- | Callbacks can use the '' | ||
- | |||
- | <code php> | ||
- | <? | ||
- | $f=fopen(" | ||
- | $st=fgets($f); | ||
- | $msg=fgets($f); | ||
- | $response=""; | ||
- | if (substr($msg, | ||
- | $variable=substr($msg, | ||
- | $response=$variable.":" | ||
- | } | ||
- | if (strpos($st, | ||
- | if (strpos($st," | ||
- | mqtt_publish("/ | ||
- | } else { | ||
- | if (strpos($st," | ||
- | print(" | ||
- | } | ||
- | } | ||
- | } | ||
- | ?> | ||
- | </ | ||
- | |||
- | ====Note===== | ||
- | On WattmonPRO & MINI the maximum packet size is 128 bytes. | ||
- | |||
- | ====See Also==== | ||
- | |||
- | [[mqtt_publish()]] - Publish to an MQTT channel | ||