SHARE
TWEET

mqtt publish

sspence65 Aug 11th, 2017 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.   ?>
RAW Paste Data
Top