ソースを参照

feature: 添加wifi发送主题、发送消息指令标注

Damon 7 ヶ月 前
コミット
3fe6b6c3c4
2 ファイル変更20 行追加9 行削除
  1. 19 9
      app.js
  2. 1 0
      pages/index/index.js

+ 19 - 9
app.js

@@ -151,10 +151,12 @@ App({
     });
   },
 
+  // topic
+  // /AIrSMArT_7cdfa1fd3af0/status/onoffline
+  // /AIrSMArT_7cdfa1fd3af0/user/pub_response
   // 订阅主题
   subscribe: function (topic, callback) {
     var that = this;
-    console.log("gasdfqwerqweqr===00==" + topic);
     if (that.globalData.client && that.globalData.client.connected) {
       //订阅主题
       that.globalData.client.subscribe(topic, function (err, granted) {
@@ -197,20 +199,28 @@ App({
       return;
     }
 
-    console.log("gasdfqwerqweqr===11==" + JSON.stringify(option));
-    console.log("gasdfqwerqweqr===22==" + option.type);
-    console.log("gasdfqwerqweqr===33==" + option.DstDeviceName);
-    console.log("gasdfqwerqweqr===44==" + `ALY_${that.globalData.userInfo.userId}`);
+    // {"type":"get_dev_info","DstDeviceName":"AIrSMArT_7cdfa1fd3af0"}
+    // get_dev_info
+    var type = option.type;
+    // AIrSMArT_7cdfa1fd3af0
+    var DstDeviceName = option.DstDeviceName;
+    // ALY_933625
+    var SrcDeviceName = `ALY_${that.globalData.userInfo.userId}`;
     if (that.globalData.client && that.globalData.client.connected) {
       const data = {
-        "type": option.type,
-        "DstDeviceName": option.DstDeviceName,
-        "SrcDeviceName": `ALY_${that.globalData.userInfo.userId}`,
+        "type": type,
+        "DstDeviceName": DstDeviceName,
+        "SrcDeviceName": SrcDeviceName,
       };
       if (option.other) {
         data.other = option.other;
       };
-      that.globalData.client.publish(`/${option.DstDeviceName}/user/sub_control`, `${JSON.stringify(data)}`, (err) => {
+
+      // /AIrSMArT_7cdfa1fd3af0/user/sub_control
+      var publish = `/${DstDeviceName}/user/sub_control`;
+      // {"type":"get_dev_info","DstDeviceName":"AIrSMArT_7cdfa1fd3af0","SrcDeviceName":"ALY_933625"}
+      var dataString = `${JSON.stringify(data)}`;
+      that.globalData.client.publish(publish, dataString, (err) => {
         if (err) {
           console.log("发布消息失败");
         }

+ 1 - 0
pages/index/index.js

@@ -413,6 +413,7 @@ Page({
       deviceList: deviceList,
     });
 
+    ///  /AIrSMArT_7cdfa1fd3af0/user/pub_response
     var topic = `/AIrSMArT_${tempDeviceId.split("BLUFI_")[1]}/user/pub_response`;
     app.subscribe(topic);