tongshanglei 1 year ago
parent
commit
48200ff841
2 changed files with 17 additions and 32 deletions
  1. 14 29
      task_script/LIVESTOCK_MQTT_CLIENT.php
  2. 3 3
      task_script/LIVESTOCK_MQTT_PUBLISH.php

+ 14 - 29
task_script/LIVESTOCK_MQTT_CLIENT.php

@@ -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);
 }

+ 3 - 3
task_script/LIVESTOCK_MQTT_PUBLISH.php

@@ -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()