فهرست منبع

feature: 解决切换连接不能连接的问题

Damon 7 ماه پیش
والد
کامیت
82f6f5e14d
8فایلهای تغییر یافته به همراه6904 افزوده شده و 108 حذف شده
  1. 4 2
      app.js
  2. 1 2
      pages/deviceConnect3/deviceConnect3.js
  3. 36 27
      pages/deviceList/deviceList.js
  4. 60 54
      pages/deviceWake/deviceWake.js
  5. 11 6
      pages/index/index.js
  6. 1 1
      utils/lexin/devices.js
  7. 13 15
      utils/lexin/message.js
  8. 6778 1
      utils/mqtt.js

+ 4 - 2
app.js

@@ -21,7 +21,7 @@ App({
     ssid: "",
     pwdData: "",
     userData: null,
-    is_debug: 1, // 1 测试环境 // 2正式环境
+    is_debug: 2, // 1 测试环境 // 2正式环境
     client: null,
     oneInitBluetooth: true,
 
@@ -59,6 +59,7 @@ App({
     wx.onAppShow(() => {
       if (that.globalData.userInfo !== null) {
         if (!(that.globalData.client && that.globalData.client.connected)) {
+          console.log("开始连接=00=")
           that.connect();
         }
       }
@@ -99,6 +100,7 @@ App({
 
     // 设备连接
     that.globalData.client.on('connect', () => {
+      console.log("connect的回调==")
       var pages = getCurrentPages();
       var length = pages.length;
       var currentPage = pages[length - 1];
@@ -204,7 +206,7 @@ App({
           if (callback) {
             callback();
           }
-          console.log("订阅成功");
+          console.log("订阅成功===" + topic);
         } else {
           console.log('订阅主题失败');
         }

+ 1 - 2
pages/deviceConnect3/deviceConnect3.js

@@ -121,8 +121,7 @@ Page({
                 percent: 100,
                 ruterStatus: 1,
               });
-            }, 200);
-
+            }, 500);
           }
         }
         break;

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 36 - 27
pages/deviceList/deviceList.js


+ 60 - 54
pages/deviceWake/deviceWake.js

@@ -7,6 +7,7 @@ const {
   deviceWakedetail
 } = require('./../../utils/api.js');
 import lexin_devices from '../../utils/lexin/devices';
+import lexin_util from '../../utils/lexin/util.js';
 
 let _this = null
 Page({
@@ -76,9 +77,13 @@ Page({
   onLoad(options) {
     _this = this;
 
+    var clientType = options.clientType;
+    var deviceId = options.deviceId;
+    var deviceMac = lexin_util.getDeviceMacId(deviceId);
+    // var deviceMac = `AIrSMArT_${deviceId.split(lexin_devices.leXin)[1]}`;
     deviceWakedetail({
-      clientType: options.clientType,
-      deviceMac: `AIrSMArT_${options.deviceId.split(lexin_devices.leXin)[1]}`,
+      clientType: clientType,
+      deviceMac: deviceMac,
     }).then((res) => {
       if (res && res.length > 0) {
         this.setData({
@@ -87,7 +92,8 @@ Page({
       }
     })
     this.data.clientType = options.clientType
-    this.data.deviceMac = `AIrSMArT_${options.deviceId.split(lexin_devices.leXin)[1]}`;
+    this.data.deviceMac = lexin_util.getDeviceMacId(options.deviceId);
+    // this.data.deviceMac = `AIrSMArT_${options.deviceId.split(lexin_devices.leXin)[1]}`;
     app.PubMsg({
       type: "get_dev_info",
       DstDeviceName: this.data.deviceMac
@@ -241,7 +247,7 @@ Page({
       other.on_off_timestamp = _this.data.alarm_id_0_time;
 
       // 有重复
-      if (other.week_actives.filter((v) => v === 1).length > 0) {
+      if (other.week_actives && other.week_actives.filter((v) => v === 1).length > 0) {
         // other.week_actives = [0,1,1,1,1,1,0],
         other.weekly_repeat = "1";
       } else {
@@ -285,67 +291,67 @@ Page({
       if (!other) {
         wx.showToast({
           title: '设备已断开连接',
-          icon:"none"
+          icon: "none"
         })
         return
       }
       other.on_off_timestamp = _this.data.time;
-          other = this.setOther(other, 1);
-          let week_actives = other.week_actives ?? []
-          if (week_actives.filter((v) => v === 1).length > 0) {
-            // other.week_actives = [0,1,1,1,1,1,0],
-            other.weekly_repeat = "1";
-          } else {
-            other.weekly_repeat = "0";
-          };
-          app.PubMsg({
-            type: "alert_set",
-            DstDeviceName: _this.data.deviceMac,
-            other
-          });
+      other = this.setOther(other, 1);
+      let week_actives = other.week_actives ?? []
+      if (week_actives.filter((v) => v === 1).length > 0) {
+        // other.week_actives = [0,1,1,1,1,1,0],
+        other.weekly_repeat = "1";
+      } else {
+        other.weekly_repeat = "0";
+      };
+      app.PubMsg({
+        type: "alert_set",
+        DstDeviceName: _this.data.deviceMac,
+        other
+      });
 
-        // 不要循环发送,也不要改alarm_id_0.enable
+      // 不要循环发送,也不要改alarm_id_0.enable
       // 循环查询
       // const Interval = setInterval(() => {
       //   if (_this.data.updataDeviceInfo) {
       //     clearInterval(Interval);
-          // other.on_off_timestamp = _this.data.time;
-          // other = this.setOther(other, 1);
-          // if (other.week_actives.filter((v) => v === 1).length > 0) {
-          //   // other.week_actives = [0,1,1,1,1,1,0],
-          //   other.weekly_repeat = "1";
-          // } else {
-          //   other.weekly_repeat = "0";
-          // };
-          // app.PubMsg({
-          //   type: "alert_set",
-          //   DstDeviceName: _this.data.deviceMac,
-          //   other
-          // });
-          // 需打开休眠
-          // if (_this.data.alarm_id_0.enable === "0") {
+      // other.on_off_timestamp = _this.data.time;
+      // other = this.setOther(other, 1);
+      // if (other.week_actives.filter((v) => v === 1).length > 0) {
+      //   // other.week_actives = [0,1,1,1,1,1,0],
+      //   other.weekly_repeat = "1";
+      // } else {
+      //   other.weekly_repeat = "0";
+      // };
+      // app.PubMsg({
+      //   type: "alert_set",
+      //   DstDeviceName: _this.data.deviceMac,
+      //   other
+      // });
+      // 需打开休眠
+      // if (_this.data.alarm_id_0.enable === "0") {
 
-          //   const thisTime = Math.round(new Date() / 1000);
-          //   const alarm_id_0 = this.setOther(_this.data.alarm_id_0, 1);
-          //   alarm_id_0.on_off_timestamp = _this.data.alarm_id_0_time;
+      //   const thisTime = Math.round(new Date() / 1000);
+      //   const alarm_id_0 = this.setOther(_this.data.alarm_id_0, 1);
+      //   alarm_id_0.on_off_timestamp = _this.data.alarm_id_0_time;
 
-          //   // 有重复
-          //   if (alarm_id_0.week_actives.filter((v) => v === 1).length > 0) {
-          //     alarm_id_0.weekly_repeat = "1";
-          //   } else {
-          //     alarm_id_0.weekly_repeat = "0";
-          //   };;
-          //   // 如果跨天了
-          //   if (!this.compareDate(_this.data.alarm_id_0_time, this.formatTime(thisTime, "h:m:s"))) {
-          //     const date = new Date((_this.formatTime(thisTime, "Y-M-D") + " 00:00:00").replace(/-/g, '/'));
-          //     alarm_id_0.current_timestamp = this.formatTime(date.getTime() / 1000 + 86400, "Y-M-D h:m:s");
-          //   };
-          //   app.PubMsg({
-          //     type: "alert_set",
-          //     DstDeviceName: _this.data.deviceMac,
-          //     other: alarm_id_0
-          //   });
-          // }
+      //   // 有重复
+      //   if (alarm_id_0.week_actives.filter((v) => v === 1).length > 0) {
+      //     alarm_id_0.weekly_repeat = "1";
+      //   } else {
+      //     alarm_id_0.weekly_repeat = "0";
+      //   };;
+      //   // 如果跨天了
+      //   if (!this.compareDate(_this.data.alarm_id_0_time, this.formatTime(thisTime, "h:m:s"))) {
+      //     const date = new Date((_this.formatTime(thisTime, "Y-M-D") + " 00:00:00").replace(/-/g, '/'));
+      //     alarm_id_0.current_timestamp = this.formatTime(date.getTime() / 1000 + 86400, "Y-M-D h:m:s");
+      //   };
+      //   app.PubMsg({
+      //     type: "alert_set",
+      //     DstDeviceName: _this.data.deviceMac,
+      //     other: alarm_id_0
+      //   });
+      // }
 
       //   }
       // }, 500);

+ 11 - 6
pages/index/index.js

@@ -34,11 +34,11 @@ Page({
     isLogin: false,
     greeting: "",
     bannerList: [{
-      "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20241028142233669038262.png"
-    },
-    {
-      "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20240823145816541223911.png"
-    }
+        "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20241028142233669038262.png"
+      },
+      {
+        "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20240823145816541223911.png"
+      }
     ],
     autoplay: true,
     interval: 3000, // 切换时间间隔
@@ -177,7 +177,7 @@ Page({
       case "connect":
         lexin_subscribe.subscribeAllDevice();
         break;
-      ///再走有在线
+        ///再走有在线
       case "message_onoffline":
         lexin_connect.searchOnlineDevice(payloads, function (list) {
           that.updateDeviceList(list, false, false);
@@ -588,6 +588,8 @@ Page({
   addWifiDevice(device) {
     var that = this;
     var isOK = app.globalData.client && app.globalData.client.connected;
+    console.log("gadsfqwerqwr==00==" + app.globalData.client);
+    console.log("gadsfqwerqwr==aaa==" + app.globalData.client.connected);
     if (!isOK) {
       app.connect();
       setTimeout(() => {
@@ -596,9 +598,12 @@ Page({
       return;
     };
 
+    console.log("gadsfqwerqwr==11==" + isOK);
     var deviceId = device.deviceId;
     var addDeviceList = lexin_add.addWifiDevice(device);
+    console.log("gadsfqwerqwr==22==" + addDeviceList.length);
     that.updateDeviceList(addDeviceList, false, false);
+    console.log("gadsfqwerqwr==333==" + that.data.deviceList.length);
 
     var indexPage = that.data.indexPage;
     that.setData({

+ 1 - 1
utils/lexin/devices.js

@@ -3,7 +3,7 @@ const leXin = "BLUFI_";
 const clientTypes = ["MW-2AX(WIFI)", "MW-2AX(WIFI-N)", "MW-2AX(A)",
   "MW-SR1(4G_WIFI)",
   "MW-SR1(4G_WIFI_MEIZU01)",
-  "MW-Mate X(4G_WIF)",
+  "MW-Mate X(4G_WIFI)",
 ];
 
 module.exports = {

+ 13 - 15
utils/lexin/message.js

@@ -56,25 +56,23 @@ function getDeviceInfo(payloads) {
             device.devName = devName;
           }
 
+          if (device.ProdModel != ProdModel) {
+            device.ProdModel = ProdModel;
+          }
+
           ///设置图片
-          if (!strings.isEmpty(ProdModel)) {
-            var classifyProducts = app.globalData.classifyProducts;
-            if (!strings.isEmpty(classifyProducts)) {
-              for (var i = 0; i < classifyProducts.length; i++) {
-                var productItem = classifyProducts[i];
-                if (productItem.clientType == ProdModel) {
-                  if (!strings.isEmpty(productItem.img) && device.imageUrl != productItem.img) {
-                    device.imageUrl = productItem.img;
-                  }
-                  break;
-                }
+          var classifyProducts = app.globalData.classifyProducts;
+          if (!strings.isEmpty(classifyProducts)) {
+            for (var i = 0; i < classifyProducts.length; i++) {
+              var productItem = classifyProducts[i];
+              if (productItem.clientType == ProdModel) {
+                device.imageUrl = productItem.img;
+                device.offlineImg = productItem.offlineImg;
+                device.offlineImg = productItem.offlineImg;
+                break;
               }
             }
           }
-
-          if (device.ProdModel != ProdModel) {
-            device.ProdModel = ProdModel;
-          }
           break;
         }
       }

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 6778 - 1
utils/mqtt.js