Преглед изворни кода

feature: 2AXD搜索与配网成功

332777428@qq.com пре 4 месеци
родитељ
комит
d4af57a5a6

+ 1 - 0
devices/bluetooth/bt_parse.js

@@ -37,6 +37,7 @@ class BtParse {
 
     // 解析命令
     static parseTLV(cmd) {
+      console.log("gadsfasdfadfaf===惺惺相惜==" + cmd);
         BtCmd.printTLV(cmd, false);
         // todo 在线
         // if (!PlayDevice.isOnline) {

+ 0 - 1
pages/deviceConnect3/deviceConnect3.js

@@ -94,7 +94,6 @@ Page({
         // {"type":"4","result":true,"data":{"progress":100,"ssid":"muzen\u0000"}}
         ///连接结果
       case xBlufi.XBLUFI_TYPE.TYPE_CONNECT_ROUTER_RESULT:
-        console.log("gadfqwerqwerqr==2222==" + JSON.stringify(options.result));
         if (!options.result) {
           errTi = setTimeout(() => {
             that.setData({

+ 59 - 49
pages/deviceConnect4/deviceConnect4.js

@@ -57,7 +57,6 @@ Page({
     //   "mac": "MW_BLE",
     //   "deviceId": "CC:90:DD:88:C7:E8"
     // };
-    console.log("gadsfasdfadfaf===00==");
 
     percentIn = setInterval(() => {
       if (that.data.percent === 100) {
@@ -74,55 +73,66 @@ Page({
       });
     }, 600);
 
-    BtHelper.getInstance().startScan(device,
-      async function (b) {
-          if (!b) {
-            that.setData({
-              connected: false
-            })
-            that.setData({
-              ruterStatus: 2
-            });
-          }
+    BleUtil.getInstance().startConnect(device, function (changed) {
+      if (changed) {
+        BleUtil.getInstance().sendData(device, app.globalData.ssid, app.globalData.pwdData);
+      } else {
+        that.setData({
+          ruterStatus: 2
+        });
+        clearInterval(percentIn);
+      }
+    });
+
+    // BtHelper.getInstance().startScan(device,
+    //   async function (b) {
+    //       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) {
-          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(function () {
+    //         BleUtil.getInstance().startConnect(device, function (changed) {
+    //           if (changed) {
+    //             BleUtil.getInstance().sendData(device, app.globalData.ssid, app.globalData.pwdData);
+    //           }
+    //         });
+    //       }, 10 * 1000);
+    //     },
+    //     async function (res) {
+    //       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);
-        }
-    );
+    //       setTimeout(() => {
+    //         clearInterval(percentIn);
+    //         that.setData({
+    //           percent: 100,
+    //           ruterStatus: 1,
+    //         });
+    //       }, 500);
+    //     }
+    // );
   },
 })

+ 11 - 32
utils/blue_ble/manager.js

@@ -424,7 +424,6 @@ class Manager {
     var that = this;
     const time_util = require('./../../utils/time_util');
     var characteristics = res.characteristics;
-    console.log("gadsfasdfadfaf===啊啊啊啊==" + JSON.stringify(characteristics));
     if (characteristics.length <= 0) {
       failed();
       return;
@@ -479,8 +478,6 @@ class Manager {
 
   // 监听特征值变化
   monitorCharacteristicValueChange(device, serviceId, notifyCharaterId) {
-    console.log("gadsfasdfadfaf===wwww==" + device.deviceId + "===" + serviceId +
-      "===" + notifyCharaterId);
     return new Promise((resolve, reject) => {
       var deviceId = device.deviceId;
       wx.notifyBLECharacteristicValueChange({
@@ -489,12 +486,10 @@ class Manager {
         serviceId: serviceId,
         characteristicId: notifyCharaterId,
         success: function (res) {
-          console.log("啊是的发生的发生等份===cccc==" + JSON.stringify(res));
           resolve(true);
         },
         ///{"errno":1500104,"errMsg":"notifyBLECharacteristicValueChange:fail:no descriptor"}
         fail: function (res) {
-          console.log("啊是的发生的发生等份===dddd==" + JSON.stringify(res));
           resolve(false);
         }
       });
@@ -504,15 +499,17 @@ class Manager {
   ///收取到的数据转换为文字
   onBLECharacteristicValueChange(callback) {
     wx.onBLECharacteristicValueChange(function (characteristic) {
-      console.log("gadsfasdfadfaf===666==" + JSON.stringify(r));
-      var receiveText = hex_util.buf2string(characteristic);
-      console.log("gadsfasdfadfaf===777==" + receiveText);
+      //characteristic: {"value":{},"deviceId":"22:10:14:95:F0:1E","serviceId":"0000FFE5-0000-1000-8000-00805F9B34FB","characteristicId":"0000FFE5-0001-1000-8000-00805F9B34FB"}
+      // const hex_util = require('../hex_util');
+      // var receiveText = hex_util.buf2string(characteristic);
       let buffer = characteristic.value
       let dataView = new DataView(buffer)
       let dataResult = []
       for (let i = 0; i < dataView.byteLength; i++) {
         dataResult.push(dataView.getUint8(i))
       }
+      ///109,113,116,116
+      ///114,101,99,118,95,102,105,110,105,115,104
       callback(dataResult);
     });
   }
@@ -535,30 +532,17 @@ class Manager {
 
   ///发送数据
   sendData(device, data) {
+    var that = this;
     return new Promise((resolve, reject) => {
-      var that = this;
-      var length = data.length;
-      console.log("gadsfasdfadfaf===hhh==" + length + "===" + data);
-      var buffer = new ArrayBuffer(length);
+      var buffer = new ArrayBuffer(data.length);
       // 下面是赋值,不能删
       const dataView = new DataView(buffer);
-      for (var i = 0; i < length; i++) {
-        // console.log("gadsfasdfadfaf===iii==" + i + "===" + data[i]);
-        dataView.setUint8(i, data[i]);
-      }
-      // data.forEach((value, index) => {
-      //   dataView.setUint8(index, value); // 将每个16进制数值写入到 buffer 中
-      // });
-
-
-      console.log("gadsfasdfadfaf===ccc==" + that.writeServiceId);
-      console.log("gadsfasdfadfaf===ddd==" + that.writeCharaterId);
-      console.log("gadsfasdfadfaf===eee==" + buffer);
+      // 将每个16进制数值写入到 buffer 中
+      data.forEach((value, index) => {
+        dataView.setUint8(index, value);
+      });
 
-      // serviceId: that.publicDevice.serviceId, //服务通道,这里主要是notify
-      // characteristicId: characteristicId, //notify uuid
       var deviceId = device.deviceId;
-      console.log("gadsfasdfadfaf===bbb==" + deviceId);
       wx.writeBLECharacteristicValue({
         deviceId: deviceId,
         serviceId: that.writeServiceId,
@@ -589,7 +573,6 @@ module.exports = Manager;
 //       var notifyCharaterId = "";
 //       var notifyServiceId = "";
 
-//       console.log("gadsfasdfadfaf===xxxx==" + JSON.stringify(res.characteristics));
 //       for (var i = 0; i < res.characteristics.length; i++) {
 //         var properties = res.characteristics[i].properties;
 //         var charaterId = res.characteristics[i].uuid;
@@ -598,9 +581,6 @@ module.exports = Manager;
 //           if (properties.notify) {
 //             notifyCharaterId = charaterId;
 //             notifyServiceId = services[index].uuid;
-//             console.log("gadsfasdfadfaf===xxxx==" + properties.write);
-//             console.log("gadsfasdfadfaf===yyy==" + properties.writeWithoutResponse);
-//             console.log("gadsfasdfadfaf===zzz==" + JSON.stringify(res.characteristics[i]));
 //             notify = true;
 //           }
 //         }
@@ -626,7 +606,6 @@ module.exports = Manager;
 //         if (index == services.length) {
 //           fail();
 //         } else {
-//           console.log("gadsfasdfadfaf===yyy==");
 //           that.getCharacteristics(device, services, index, notify, write, read, succeed, fail);
 //         }
 //       } else {

+ 3 - 7
utils/blue_ble/util.js

@@ -73,7 +73,6 @@ class BleUtil {
 
     const strings = require('./../../utils/strings');
     var services = await that.manager.getNotifyServices(device);
-    console.log("gadsfasdfadfaf===333==" + JSON.stringify(services));
     if (strings.isEmpty(services)) {
       that.disconnect(device);
       onChanged(false);
@@ -107,7 +106,6 @@ class BleUtil {
           BtParse.parseTLV(value);
         });
 
-        console.log("gadsfasdfadfaf===7777==");
         setTimeout(() => {
           onChanged(true);
         }, 300);
@@ -117,10 +115,8 @@ class BleUtil {
   ///发送数据
   async sendData(device, wifiName, pwd) {
     var that = this;
-    var text = that.sendWiFiInfo(wifiName, pwd);
-    console.log("gadsfasdfadfaf===888==" + text);
-    var isTrue = await that.manager.sendData(device, text);
-    console.log("gadsfasdfadfaf===999==" + isTrue);
+    var list = that.sendWiFiInfo(wifiName, pwd);
+    var isTrue = await that.manager.sendData(device, list);
     ///发送数据成功
     if (isTrue) {
 
@@ -161,7 +157,7 @@ class BleUtil {
     }
     ///[34, 22, 51, 5, 109, 117, 122, 101, 110, 68, 11, 109, 117, 122, 101, 110, 111, 102, 102, 105, 99, 101]
     console.log("发送wifi账号密码:", result.toString());
-    return result.toString();
+    return result;
   }
 
   ///断开设备连接