فهرست منبع

feature: 配网成功后数据处理

332777428@qq.com 5 ماه پیش
والد
کامیت
8847d68244
2فایلهای تغییر یافته به همراه57 افزوده شده و 21 حذف شده
  1. 0 1
      pages/deviceConnect3/deviceConnect3.js
  2. 57 20
      pages/deviceConnect4/deviceConnect4.js

+ 0 - 1
pages/deviceConnect3/deviceConnect3.js

@@ -76,7 +76,6 @@ Page({
       // {"type":"2","result":true,"data":{"deviceId":"7C:DF:A1:FD:3A:F2","serviceId":"0000FFFF-0000-1000-8000-00805F9B34FB",
       // "characteristicId":"0000FF01-0000-1000-8000-00805F9B34FB"}}
       case xBlufi.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT:
-        console.log("gadfqwerqwerqr==222==" + JSON.stringify(options.result));
         if (options.result) {
           console.log('初始化成功');
           that.OnClickStart();

+ 57 - 20
pages/deviceConnect4/deviceConnect4.js

@@ -7,6 +7,7 @@ const {
   BleUtil
 } = require('../../utils/blue_ble/util');
 
+let percentIn = null;
 Page({
   data: {
     nvabarData: {
@@ -56,37 +57,73 @@ Page({
       "mac": "MW_BLE",
       "deviceId": "CC:90:DD:88:C7:E8"
     };
-
     console.log("gadsfasdfadfaf===00==");
 
-    // BtHelper.getInstance().connect(device, function (isConnected, device) {
-    //   if (isConnected) {
-
-    //   }
-    // }, true, device);
+    percentIn = setInterval(() => {
+      if (that.data.percent === 100) {
+        clearInterval(percentIn);
+        ///失败
+        that.setData({
+          ruterStatus: 2
+        });
+        return;
+      };
+      that.data.percent++;
+      that.setData({
+        percent: that.data.percent
+      });
+    }, 600);
 
     BtHelper.getInstance().startScan(device,
       async function (b) {
-          if (b) {
-            setTimeout(function () {
-              BleUtil.getInstance().startConnect(device, function (changed) {
-                if (changed) {
-                  BleUtil.getInstance().sendData(device, app.globalData.ssid, app.globalData.pwdData);
-                }
-              });
-            }, 10 * 1000);
+
+          if (!b) {
+            that.setData({
+              connected: false
+            })
+            that.setData({
+              ruterStatus: 2
+            });
           }
 
+          setTimeout(function () {
+            BleUtil.getInstance().startConnect(device, function (changed) {
+              if (changed) {
+                BleUtil.getInstance().sendData(device, app.globalData.ssid, app.globalData.pwdData);
+              }
+            });
+          }, 10 * 1000);
         },
         async function (res) {
-          await BtHelper.getInstance().stopSearch();
-          BleUtil.getInstance().startConnect(device, function (changed) {
-            if (changed) {
-              BleUtil.getInstance().sendData(device, app.globalData.ssid, app.globalData.pwdData);
-            }
+          var deviceId = that.data.name;
+          var device = {
+            connectType: 3,
+            devName: "",
+            state: "online",
+            name: deviceId,
+            deviceId: deviceId,
+            mac: deviceId,
+            imageUrl: that.data.imageUrl,
+            // imageUrl: "./../../img/min.png",
+          }
+          getCurrentPages()[0].addWifiDevice(device);
+          // 记住密码
+          wx.setStorage({
+            key: "wifiInfo",
+            data: JSON.stringify({
+              "password": app.globalData.pwdData,
+              "ssid": app.globalData.ssid
+            }),
           });
+
+          setTimeout(() => {
+            clearInterval(percentIn);
+            that.setData({
+              percent: 100,
+              ruterStatus: 1,
+            });
+          }, 500);
         }
     );
-
   },
 })