静态网络配置
修改上传up的速度,采集周期设置2s
下载地址 http://www.jensd.de/apps/mqttfx/1.7.1/
publish:
/WG585OWAN20102200356/down
{"cmdId":91,"execmd":"wtbl_gostatus text"}
{"cmdId":87,"writeValue":"100","devId":1098,"varId":253}
{"cmdId":85,"devId":115,"varId":2566}
sub:
/sys/WG585OWAN20102200356/up
php代码如下:
<?php
require('../phpMQTT.php');
$server = '192.168.2.187'; // change if necessary
$port = 61613; // change if necessary
$username = 'admin'; // set your username
$password = 'password'; // set your password
$client_id = '6dd1bb3392b64e1982c1da5b34239c05'; // make sure this is unique for connecting to sever - you could use uniqid()
$mqtt = new Bluerhinos\phpMQTT($server, $port, $client_id);
if ($mqtt->connect(true, NULL, $username, $password)) {
$mqtt->publish('/WG585OWAN20102200356/down', '{"cmdId":87,"writeValue":"15","devId":1098,"varId":532}', 0, false);
$mqtt->close();
echo "success!!\n";
} else {
echo "Time out!\n";
}
<?php
require('../phpMQTT.php');
$server = '192.168.2.187'; // change if necessary
$port = 61613; // change if necessary
$username = 'admin'; // set your username
$password = 'password'; // set your password
$client_id = '6dd1bb3392b64e1982c1da5b34239c05'; // make sure this is unique for connecting to sever - you could use uniqid()
$mqtt = new Bluerhinos\phpMQTT($server, $port, $client_id);
if(!$mqtt->connect(true, NULL, $username, $password)) {
exit(1);
}
$mqtt->debug = true;
$topics['sys/WG585OWAN20102200356/up'] = array('qos' => 0, 'function' => 'procMsg');
$mqtt->subscribe($topics, 0);
$topics1['/sys/WG585OWAN20102200356/up'] = array('qos' => 0, 'function' => 'procMsg');
$mqtt->subscribe($topics1, 0);
while($mqtt->proc()) {
}
$mqtt->close();
function procMsg($topic, $msg){
echo 'Msg Recieved: ' . date('r') . "\n";
echo "Topic: {$topic}\n\n";
echo "\t$msg\n\n";
}