Advertisement
sspence65

mqtt publish

Aug 11th, 2017
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.49 KB | None | 0 0
  1. <?php
  2. //publish.php
  3.  
  4.  
  5.  
  6.   require("phpMQTT.php");
  7.  
  8.  
  9.  
  10.   $host = "10.0.99.94";
  11.   $port = "1883";
  12.   $username = "";
  13.   $password = "";
  14.   $message = "Hello CloudMQTT!";
  15.  
  16.   //MQTT client id to use for the device. "" will generate a client id automatically
  17.   $mqtt = new phpMQTT($host, $port, "testSub".rand());
  18.  
  19.   if ($mqtt->connect(true,NULL,$username,$password)) {
  20.     $mqtt->publish("debug",$message, 0);
  21.     $mqtt->close();
  22.   }else{
  23.     echo "Fail or time out<br />";
  24.   }
  25.   ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement