tongshanglei 1 month ago
parent
commit
c9e977789d
1 changed files with 22 additions and 14 deletions
  1. 22 14
      task_script/PUMP_MQTT_PUBLISH.php

+ 22 - 14
task_script/PUMP_MQTT_PUBLISH.php

@@ -4,14 +4,14 @@ use \PhpMqtt\Client\MqttClient;
 use \PhpMqtt\Client\ConnectionSettings;
 use \PhpMqtt\Client\ConnectionSettings;
 use think\facade\Cache;
 use think\facade\Cache;
 // date_default_timezone_set("America/Bahia");
 // date_default_timezone_set("America/Bahia");
-// define('HOST', '127.0.0.1');
-// define('PORT', '6379');
-// define('PASSWORD', '123456');
-// define('DATABASE', 2);
-define('HOST', 'r-bp1eebab79320044pd.redis.rds.aliyuncs.com');
+define('HOST', '127.0.0.1');
 define('PORT', '6379');
 define('PORT', '6379');
-define('PASSWORD', '7e2b5c91e438be3c!');
-define('DATABASE', 4);
+define('PASSWORD', '123456');
+define('DATABASE', 2);
+// define('HOST', 'r-bp1eebab79320044pd.redis.rds.aliyuncs.com');
+// define('PORT', '6379');
+// define('PASSWORD', '7e2b5c91e438be3c!');
+// define('DATABASE', 4);
 
 
 function app_redis()
 function app_redis()
 {
 {
@@ -61,7 +61,7 @@ function sendConfig($topic,$config)
 {
 {
     $server   = '116.62.220.88';
     $server   = '116.62.220.88';
     $port     = 1883;
     $port     = 1883;
-    $clientId = 'local_mqtt_pump_config';
+    $clientId = 'local_mqtt_pump_config0303';
     $username = 'rl517';
     $username = 'rl517';
     $password = "rlian2022";
     $password = "rlian2022";
     $clean_session = false;
     $clean_session = false;
@@ -94,8 +94,8 @@ function sendConfig($topic,$config)
     return $res;
     return $res;
 }
 }
 function updateSendResult($msgid){
 function updateSendResult($msgid){
-    $conn = new mysqli('rm-bp1h3uqkzy66ckt8y125010.mysql.rds.aliyuncs.com', 'dev', '711e7D69f9d0c3f1', 'catch_pump');
-    // $conn = new mysqli('127.0.0.1', 'root', 'root', 'catch_pump');
+    // $conn = new mysqli('rm-bp1h3uqkzy66ckt8y125010.mysql.rds.aliyuncs.com', 'dev', '711e7D69f9d0c3f1', 'catch_pump');
+    $conn = new mysqli('127.0.0.1', 'root', 'root', 'catch_pump');
     if ($conn -> connect_errno) {
     if ($conn -> connect_errno) {
         printf("Connect failed: %s\n", $conn->connect_error);
         printf("Connect failed: %s\n", $conn->connect_error);
         exit();
         exit();
@@ -486,7 +486,7 @@ while (1) {
     $topic="DEV/DATA/".$data['mac'];
     $topic="DEV/DATA/".$data['mac'];
     $config_json=$data['config'];
     $config_json=$data['config'];
     $sendData=false;
     $sendData=false;
-
+    $msgId=$config_json['msgId'];
     if($data['type']=='config'){
     if($data['type']=='config'){
         $sendData = buildMqttData(MQTT_TYPE::$SUB_ALARM, $config_json['msgId'], ['lower' =>$config_json['lower'], 'upper' =>$config_json['upper']]);
         $sendData = buildMqttData(MQTT_TYPE::$SUB_ALARM, $config_json['msgId'], ['lower' =>$config_json['lower'], 'upper' =>$config_json['upper']]);
     }elseif($data['type']=='alarm'){
     }elseif($data['type']=='alarm'){
@@ -501,13 +501,21 @@ while (1) {
         $sendData = buildMqttData(MQTT_TYPE::$SET_SAMPLE_PERIOD, $config_json['msgId'], $config_json['samplie_period']);
         $sendData = buildMqttData(MQTT_TYPE::$SET_SAMPLE_PERIOD, $config_json['msgId'], $config_json['samplie_period']);
     }elseif($data['type']=='get_samplie'){
     }elseif($data['type']=='get_samplie'){
         $sendData = buildMqttData(MQTT_TYPE::$GET_SAMPLE_PERIOD, $config_json['msgId'], null);
         $sendData = buildMqttData(MQTT_TYPE::$GET_SAMPLE_PERIOD, $config_json['msgId'], null);
+    }elseif($data['type']=='getNvsVal' || $data['type']=='reboot' || $data['type']=='start_report' || $data['type']=='stop_report'){
+        //{"mid":0,"mac":"24EC4A20383F","data":{"type":"getNvsVal","nvsType":"str","nvsName":"pt cal"."handle":1}}
+        //ESP/OTHER/24EC4A20383F
+        $topic="ESP/OTHER/".$data['mac'];
+        unset($config_json['msgId']);
+        $sendData = json_encode([
+            'mid'=>$msgId,
+            'mac'=>$data['mac'],
+            'data'=>$config_json,
+        ]);
     }else{
     }else{
 
 
     }
     }
-    var_dump($sendData);
-        
     if($sendData){
     if($sendData){
-        updateSendResult($config_json['msgId']);
+        updateSendResult($msgId);
         $res=sendConfig($topic,$sendData);
         $res=sendConfig($topic,$sendData);
     }
     }