phpmqtt

    本文地址:http://tongxinmao.com/Article/Detail/id/158

    <?php
    
    require("phpMQTT.php");
    
    	
    $mqtt = new phpMQTT("xxx.com", 1883, "phpMQTT Pub Example"); //Change client name to something unique
    
    if ($mqtt->connect()) {
    	$mqtt->publish("gpio","Hello World! at ".date("r"),0);
    	$mqtt->publish("gpio",pack("C", 0xe1).pack("C", 0xff),0);
    	$mqtt->close();
    }
    
    ?>
    <?php
    
    require("phpMQTT.php");
    
    $mqtt = new phpMQTT("xxx.com", 1883, "phpMQTT Sub Example"); //Change client name to something unique
    
    if(!$mqtt->connect()){
    exit(1);
    }
    
    $topics['gpio'] = array("qos"=>0, "function"=>"procmsg");
    $mqtt->subscribe($topics,0);
    
    while($mqtt->proc()){
    }
    
    
    $mqtt->close();
    
    function procmsg($topic,$msg){
    echo "Msg Recieved: ".date("r")."\nTopic:{$topic}\n$msg\n";
    for($i=0;$i<strlen(msg);$i++)
          echo '0x'.bin2hex(msg[$i]).' ';
    }
    
    
    ?>


    上一篇:tanyu wenben
    下一篇:swoole知识点 常见问题