tongshanglei 1 ano atrás
pai
commit
a42ad135eb
1 arquivos alterados com 21 adições e 2 exclusões
  1. 21 2
      task_script/LIVESTOCK_MQTT_PUBLISH.php

+ 21 - 2
task_script/LIVESTOCK_MQTT_PUBLISH.php

@@ -4,6 +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('PORT', '6379');
+// define('PASSWORD', '123456');
+// define('DATABASE', 2);
 define('HOST', 'r-bp1eebab79320044pd.redis.rds.aliyuncs.com');
 define('PORT', '6379');
 define('PASSWORD', '7e2b5c91e438be3c!');
@@ -86,7 +90,21 @@ function sendConfig($topic,$config)
     $mqtt->disconnect();
     return $res;
 }
+function updateSendResult($msgid){
+    $conn = new mysqli('rm-bp1h3uqkzy66ckt8yro.mysql.rds.aliyuncs.com', 'dev', '711e7D69f9d0c3f1', 'smart_livestock');
+    // $conn = new mysqli('127.0.0.1', 'root', 'root', 'smart_livestock');
+    if ($conn -> connect_errno) {
+        printf("Connect failed: %s\n", $conn->connect_error);
+        exit();
+    }
+    $sql = "UPDATE send_config_log SET result='1' WHERE id=".$msgid;
+    if ($conn->query($sql) === TRUE) {
+        echo "send_config_log update success";
+    } else {
+        echo "更新失败: " . $conn->error;
+    }
 
+}
 
 $redis=app_redis();
 while (1) {
@@ -112,9 +130,10 @@ while (1) {
    
     $config_json=json_encode($config);
     var_dump($config_json);
-    $res=sendConfig($topic,$config_json);
+    // $res=sendConfig($topic,$config_json);
+    updateSendResult($data['msgid']);
     // if($res){
-        Db::table('send_config_log')->where('id',$data['msgid'])->update(['result'=>'1']);
+        // Db::table('send_config_log')->where('id',$data['msgid'])->update(['result'=>'1']);
     // }
     // var_dump($res);
 }