Ver código fonte

feature: 实现mqtt,MW-X4(BZK)设备

332777428@qq.com 5 meses atrás
pai
commit
6e1c624620
4 arquivos alterados com 43 adições e 4 exclusões
  1. 16 2
      pages/index/index.js
  2. 0 2
      utils/blue_ble/util.js
  3. 7 0
      utils/lexin/subscribe.js
  4. 20 0
      utils/lexin/util.js

+ 16 - 2
pages/index/index.js

@@ -78,7 +78,13 @@ Page({
 
     deviceMacId: null,
     deviceListSelect: null,
-    deviceList: [],
+    deviceList: [{
+      "connectType": 3,
+      // "mac": "AIrSMArT_861210052356337",
+      // "deviceId": "D0:31:10:86:AC:9A"
+      "mac": "AIrSMArT_861210052356337",
+      "deviceId": "AIrSMArT_861210052356337"
+    }],
     _willConnectBle: null,
     _hasShowModal: null,
     // deviceList: [{
@@ -151,6 +157,14 @@ Page({
     that.onDeviceLoad();
     that.onUserInfoLoad();
     that.onBannerLoad();
+
+    // var device = {
+    //   "mac": "AIrSMArT_861210052356337",
+    //   "deviceId": "D0:31:10:86:AC:9A"
+    // };
+    // that.data.deviceList.unshift(device);
+    // that.data.deviceMacId = device.mac;
+    // that.actionDevice();
   },
 
   onShow() {
@@ -329,7 +343,7 @@ Page({
   },
   // 回调
   mqttCallback(type, option) {
-    // console.log("gadsfadsfadsfa==888===" + type);
+    console.log("gadsfadsfadsfa==888===" + type + "====" + JSON.stringify(option));
     var that = this;
     let payloads = null;
     if (option && option.payload) {

+ 0 - 2
utils/blue_ble/util.js

@@ -98,7 +98,6 @@ class BleUtil {
         onChanged(false);
       }, function (notifyCharaterId) {
         ///监听特征值变化
-        console.log("gadsfasdfadfaf===444444==");
         var isTrue = that.manager.monitorCharacteristicValueChange(device, serviceId, notifyCharaterId);
         if (!isTrue) {
           onChanged(false);
@@ -119,7 +118,6 @@ class BleUtil {
       },
       async function () {
           isWrited = true;
-          console.log("gadsfasdfadfaf===555==");
           if (isRead) {
             console.log("gadsfasdfadfaf===8888==");
             setTimeout(() => {

+ 7 - 0
utils/lexin/subscribe.js

@@ -33,6 +33,7 @@ function subscribeSingleDevice(device) {
 
 // 订阅在线设备
 function subscribeAllDevice() {
+  console.log("gadsfadsfadsfa==999===");
   const strings = require('../strings');
   var pages = getCurrentPages();
   var deviceList = pages[0].getDeviceList();
@@ -40,15 +41,21 @@ function subscribeAllDevice() {
     return;
   }
 
+  console.log("gadsfadsfadsfa==aaa===");
   const app = getApp();
   const lexin_util = require('../lexin/util');
   ///扫描所有在线Wifi设备
   for (var i = 0; i < deviceList.length; i++) {
     var device = deviceList[i];
+    console.log("gadsfadsfadsfa==bbb===" + JSON.stringify(device));
+    console.log("gadsfadsfadsfa==ffff==" + device.connectType);
+    // device.connectType = 3;
+    // device.deviceId = "AIrSMArT_861210052356337";
     if (device.connectType == 3) {
       var deviceId = device.deviceId;
       var mac = lexin_util.getMacByDeviceId(deviceId);
       var topic = `/AIrSMArT_${mac}/status/onoffline`;
+      console.log("gadsfadsfadsfa==ccc===" + mac + "===" + topic);
       app.subscribe(topic);
     }
   }

+ 20 - 0
utils/lexin/util.js

@@ -8,13 +8,16 @@ module.exports = {
 
 ///获取设备mac相关 macId: deviceId.split(lexin_devices.leXinÏ)[1]
 function getMacBySplitDeviceId(splitDeviceId) {
+  console.log("gadsfadsfadsfa==mmm===" + splitDeviceId);
   if (splitDeviceId.length < 12) {
     return splitDeviceId;
   }
+  console.log("gadsfadsfadsfa==nnn===" + splitDeviceId);
   return splitDeviceId.slice(-12);
 };
 
 function getMacByDeviceId(deviceId) {
+  console.log("gadsfadsfadsfa==xxx===" + deviceId);
   const lexin_devices = require('../lexin/devices');
   var deviceIdLeXin = deviceId.split(lexin_devices.leXin);
   var deviceIdJunZheng1 = deviceId.split(lexin_devices.junZheng1);
@@ -31,6 +34,7 @@ function getMacByDeviceId(deviceId) {
   if (isLeXin) {
     return getMacBySplitDeviceId(deviceIdLeXin[1]);
   } else if ((isJunZheng1 && !isJunZheng3)) {
+    console.log("gadsfadsfadsfa==yyy===" + deviceId);
     return getMacBySplitDeviceId(deviceIdJunZheng1[1]);
   } else if ((isJunZheng2 && !isJunZheng3)) {
     return getMacBySplitDeviceId(deviceIdJunZheng2[1]);
@@ -50,6 +54,22 @@ function getDeviceMacId(deviceId) {
   var isJunZheng1 = deviceIdJunZheng1.length == 2;
   var isJunZheng2 = deviceIdJunZheng2.length == 2;
   var isJunZheng3 = deviceIdJunZheng3.length == 2;
+  if (!isLeXin && !(isJunZheng1 && !isJunZheng3) && !(isJunZheng2 && !isJunZheng3)) {
+    return "";
+  }
+
+  if (isLeXin) {
+    var result = getMacBySplitDeviceId(deviceIdLeXin[1]);
+    return `${lexin_devices.junZheng1}${result}`;
+  } else if ((isJunZheng1 && !isJunZheng3)) {
+    var result = getMacBySplitDeviceId(deviceIdJunZheng1[1]);
+    return `${lexin_devices.junZheng1}${result}`;
+  } else if ((isJunZheng2 && !isJunZheng3)) {
+    var result = getMacBySplitDeviceId(deviceIdJunZheng2[1]);
+    return `${lexin_devices.junZheng1}${result}`;
+  } else {
+    return "";
+  }
   if (isLeXin) {
     return `${lexin_devices.junZheng1}${getMacBySplitDeviceId(deviceIdLeXin[1])}`
   } else if ((isJunZheng1 && !isJunZheng3)) {