|
@@ -4,10 +4,10 @@ use \PhpMqtt\Client\MqttClient;
|
|
|
use \PhpMqtt\Client\ConnectionSettings;
|
|
|
use think\facade\Cache;
|
|
|
date_default_timezone_set("PRC");
|
|
|
-define('HOST', '127.0.0.1');
|
|
|
+define('HOST', 'r-bp1eebab79320044pd.redis.rds.aliyuncs.com');
|
|
|
define('PORT', '6379');
|
|
|
-define('PASSWORD', '123456');
|
|
|
-define('DATABASE', 2);
|
|
|
+define('PASSWORD', '7e2b5c91e438be3c!');
|
|
|
+define('DATABASE', 4);
|
|
|
|
|
|
|
|
|
function app_redis()
|
|
@@ -242,43 +242,28 @@ function loop()
|
|
|
// }, 0);
|
|
|
//终端上报系统信息数据
|
|
|
$mqtt->subscribe('earings/+/reportData', function ($topic, $message) use($mqtt) {
|
|
|
-
|
|
|
rlog("reportData", 'recv', $topic, $message);
|
|
|
$topicArr=explode('/',$topic);
|
|
|
$data=json_decode($message,true);
|
|
|
$data['deviceId']=$topicArr[1];
|
|
|
- // var_dump($message);
|
|
|
- // if((!empty($message))&&(!empty($data['cnt']))){
|
|
|
+ $data['data_type']='reportData';
|
|
|
mqttToRedis(json_encode($data));
|
|
|
- // }
|
|
|
- // $mqtt->publish(
|
|
|
- // $val['topic'],
|
|
|
- // $val['config'],
|
|
|
- // 0
|
|
|
- // );
|
|
|
- //var_dump($message);
|
|
|
}, 1);
|
|
|
$mqtt->subscribe('earings/+/coludResp', function ($topic, $message) use($mqtt) {
|
|
|
-
|
|
|
rlog("coludResp", 'recv', $topic, $message);
|
|
|
- // $topicArr=explode('/',$topic);
|
|
|
- // $data=json_decode($message,true);
|
|
|
- // $data['deviceId']=$topicArr[1];
|
|
|
- // // var_dump($message);
|
|
|
- // // if((!empty($message))&&(!empty($data['cnt']))){
|
|
|
- // mqttToRedis(json_encode($data));
|
|
|
- // }
|
|
|
+ $topicArr=explode('/',$topic);
|
|
|
+ $data=json_decode($message,true);
|
|
|
+ $data['deviceId']=$topicArr[1];
|
|
|
+ $data['data_type']='coludResp';
|
|
|
+ mqttToRedis(json_encode($data));
|
|
|
}, 1);
|
|
|
$mqtt->subscribe('earings/+/coludControl', function ($topic, $message) use($mqtt) {
|
|
|
-
|
|
|
rlog("coludControl", 'recv', $topic, $message);
|
|
|
- // $topicArr=explode('/',$topic);
|
|
|
- // $data=json_decode($message,true);
|
|
|
- // $data['deviceId']=$topicArr[1];
|
|
|
- // // var_dump($message);
|
|
|
- // // if((!empty($message))&&(!empty($data['cnt']))){
|
|
|
- // mqttToRedis(json_encode($data));
|
|
|
- // }
|
|
|
+ $topicArr=explode('/',$topic);
|
|
|
+ $data=json_decode($message,true);
|
|
|
+ $data['deviceId']=$topicArr[1];
|
|
|
+ $data['data_type']='coludControl';
|
|
|
+ mqttToRedis(json_encode($data));
|
|
|
}, 1);
|
|
|
$mqtt->loop(true);
|
|
|
}
|