User Tools

Site Tools


uphp:functions:mqtt_subscribe

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
uphp:functions:mqtt_subscribe [2017/09/27 11:05]
admin
uphp:functions:mqtt_subscribe [2017/09/27 11:13]
admin
Line 30: Line 30:
 <code php> <code php>
 <?  <? 
- 
 // Use the # as a wildcard so any messages to /cluster/1/ or its sub channels will be received // Use the # as a wildcard so any messages to /cluster/1/ or its sub channels will be received
  
Line 38: Line 37:
  
 ====Example Callback==== ====Example Callback====
-Callbacks can use the php://stdin file to read input.  Use fgets() to get the first line, which will be the full channel.  The following lines will be the data received.+Callbacks can use the ''stdin'' file to read input.  Use fgets() to get the first line, which will be the full channel.  The following lines will be the data received.
  
 <code php> <code php>
Line 44: Line 43:
 $f=fopen("php://stdin","r"); $f=fopen("php://stdin","r");
 $st=fgets($f); $st=fgets($f);
-    $msg=fgets($f); +$msg=fgets($f); 
-    $response=""; +$response=""; 
-    if (substr($msg,0,3)=='get') { +if (substr($msg,0,3)=='get') { 
-        $variable=substr($msg,4,strlen($msg)-3); + $variable=substr($msg,4,strlen($msg)-3); 
-        $response=$variable.":".$_GLOBALS[$variable]; + $response=$variable.":".$_GLOBALS[$variable]; 
-    }+}
 if (strpos($st,getmac()) || strpos($st,'/all')) { if (strpos($st,getmac()) || strpos($st,'/all')) {
-    if (strpos($st,"get")) {     + if (strpos($st,"get")) { 
- +        mqtt_publish("/cluster/1/ret/".getmac(),$response); 
-            mqtt_publish("/cluster/1/ret/".getmac(),$response); + } else { 
-    } else { + if (strpos($st,"ret")) {     
-        if (strpos($st,"ret")) {     + print("Notification was properly posted"); 
-            print("Notification was properly posted"); +
-        + }
-    }+
 } }
 ?> ?>
uphp/functions/mqtt_subscribe.txt · Last modified: 2021/09/13 05:57 (external edit)