ble_manager.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. // 引入必要的微信小程序 API
  2. // const wx = require('wx');
  3. class bleManager {
  4. constructor() {
  5. var that = this;
  6. that.hasPermission = false;
  7. that.publicDevice = null;
  8. that.connectWillDevice = null;
  9. that.callBackConnect = null;
  10. that.requestBlueTime = 0;
  11. ///正在执行扫描中
  12. that.isAvailable = false;
  13. that.doStartScaning = false;
  14. that.compareList = [];
  15. that.dissmissDevice = [];
  16. }
  17. ///获取比较的数据
  18. getCompareList() {
  19. return this.compareList;
  20. }
  21. setCompareList(compareList) {
  22. this.compareList = compareList;
  23. }
  24. getDissmissDevice() {
  25. return this.dissmissDevice;
  26. }
  27. setConnectWillDevice(connectWillDevice) {
  28. this.connectWillDevice = connectWillDevice;
  29. }
  30. getCallBackConnect() {
  31. return this.callBackConnect;
  32. }
  33. setCallBackConnect(callBackConnect) {
  34. this.callBackConnect = callBackConnect;
  35. }
  36. /// 监控蓝牙打开状态
  37. initBluetoothAdapter() {
  38. var that = this;
  39. wx.onBluetoothAdapterStateChange(function (res) {
  40. that.isAvailable = res.available;
  41. if (!that.isAvailable) {
  42. that.compareList = [];
  43. that.dissmissDevice = [];
  44. getCurrentPages()[0].closeBlueResetOffline(false, true);
  45. }
  46. });
  47. }
  48. ///监听搜索设备列表
  49. getBluetoothDevices() {
  50. var that = this;
  51. wx.onBluetoothDeviceFound(function (res) {
  52. ///第一种情况
  53. if (res.deviceId) {
  54. if (that.callBackConnect != null) {
  55. if (that.connectWillDevice != null && res.name == that.connectWillDevice.clientType) {
  56. res.mac = res.advertisData ? that.buf2hex(res.advertisData) : '';
  57. // if (that.callBackConnect != null) {
  58. console.log("1111", res.mac);
  59. if (that.callBackConnect != null) {
  60. that.callBackConnect(res);
  61. }
  62. }
  63. } else {
  64. if (res.name != "") {
  65. if (that.compareList.length > 0) {
  66. var has = false;
  67. for (var i = 0; i < that.compareList.length; i++) {
  68. if (res.deviceId == that.compareList[i].deviceId) {
  69. has = true;
  70. break;
  71. }
  72. }
  73. if (!has) {
  74. that.compareList.push(res);
  75. }
  76. } else {
  77. that.compareList.push(res);
  78. }
  79. }
  80. }
  81. }
  82. ///第二种情况
  83. else if (res.devices) {
  84. if (that.callBackConnect != null) {
  85. for (var i = 0; i < res.devices.length; i++) {
  86. var temp = res.devices[i];
  87. // if (temp.name == "MW-SR1(4G_WIFI)") {
  88. // }
  89. // if (temp.name != null) {
  90. // console.log("2222", temp.name);
  91. // }
  92. if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
  93. temp.mac = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
  94. temp.mac2 = that.ab2hex(temp.advertisData ?? "")
  95. // if (that.callBackConnect != null) {
  96. console.log("2222:", temp.mac, ":", temp.mac2, ":", temp.deviceId, temp);
  97. if (that.callBackConnect != null) {
  98. that.callBackConnect(temp);
  99. }
  100. break;
  101. }
  102. }
  103. } else {
  104. for (var i = 0; i < res.devices.length; i++) {
  105. if (res.devices[i].name != "") {
  106. if (that.compareList.length > 0) {
  107. var has = false;
  108. for (var j = 0; j < that.compareList.length; j++) {
  109. if (res.devices[i].deviceId == that.compareList[j].deviceId) {
  110. has = true;
  111. break;
  112. }
  113. }
  114. if (!has) {
  115. that.compareList.push(res.devices[i]);
  116. }
  117. } else {
  118. that.compareList.push(res.devices[i]);
  119. }
  120. }
  121. }
  122. }
  123. }
  124. ///第三种情况
  125. else if (res[0]) {
  126. if (that.callBackConnect != null) {
  127. if (that.connectWillDevice != null && res[0].name == that.connectWillDevice.clientType) {
  128. res[0].mac = res[0].advertisData ? that.buf2hex(res[0].advertisData) : '';
  129. // if (that.callBackConnect != null) {
  130. console.log("3333", res.mac);
  131. if (that.callBackConnect != null) {
  132. that.callBackConnect(res[0]);
  133. }
  134. }
  135. } else {
  136. if (res[0].name != "") {
  137. if (that.compareList.length > 0) {
  138. var has = false;
  139. for (var i = 0; i < that.compareList.length; i++) {
  140. if (res[0].deviceId == that.compareList[i].deviceId) {
  141. has = true;
  142. break;
  143. }
  144. }
  145. if (!has) {
  146. that.compareList.push(res[0]);
  147. }
  148. } else {
  149. that.compareList.push(res[0]);
  150. }
  151. }
  152. }
  153. }
  154. });
  155. ///监听已连接或没有连接 连接和断开的时候会回调
  156. // {"deviceId":"E4:9F:80:09:40:EC","connected":false}
  157. wx.onBLEConnectionStateChange((result) => {
  158. if (result.connected) {
  159. for (var i = 0; i < that.dissmissDevice.length; i++) {
  160. if (result.deviceId == that.dissmissDevice[i].deviceId) {
  161. that.dissmissDevice.splice(i, 1);
  162. break;
  163. }
  164. }
  165. } else {
  166. var has = false;
  167. for (var i = 0; i < that.dissmissDevice.length; i++) {
  168. if (result.deviceId == that.dissmissDevice[i].deviceId) {
  169. has = true;
  170. break;
  171. }
  172. }
  173. if (!has) {
  174. that.dissmissDevice.push(result);
  175. }
  176. }
  177. // ///是否已配对
  178. // wx.isBluetoothDevicePaired({
  179. // deviceId: result.deviceId,
  180. // ///{"isPaired":false,"errno":0,"errMsg":"isBluetoothDevicePaired:ok"}
  181. // success: (res) => {
  182. // },
  183. // fail: (err) => {
  184. // }
  185. // })
  186. });
  187. }
  188. ///获取 所有搜索到的蓝牙设备
  189. getConnectedDevices() {
  190. var that = this;
  191. wx.getBluetoothDevices({
  192. success: (res) => {
  193. if (that.callBackConnect != null) {
  194. for (var i = 0; i < res.devices.length; i++) {
  195. var temp = res.devices[i];
  196. if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
  197. temp.mac = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
  198. if (temp.mac) {
  199. console.log("搜索到的" + JSON.stringify(temp));
  200. }
  201. // if (that.callBackConnect != null) {
  202. if (that.callBackConnect != null) {
  203. // if (that.callBackConnect != null && temp.mac.includes("CF:CA")) {
  204. that.callBackConnect(temp);
  205. }
  206. break;
  207. }
  208. }
  209. } else {
  210. for (var i = 0; i < res.devices.length; i++) {
  211. if (that.compareList.length > 0) {
  212. var has = false;
  213. for (var j = 0; j < that.compareList.length; j++) {
  214. if (res.devices[i].name != "") {
  215. // if (res.devices[i].name == "MW-SR1(4G_WIFI)") {
  216. // console.log("gadsfqewrqewrqwerqrqr==000==" + JSON.stringify(res.devices[i]));
  217. // }
  218. if (res.devices[i].deviceId == that.compareList[j].deviceId) {
  219. has = true;
  220. break;
  221. }
  222. }
  223. }
  224. if (!has) {
  225. that.compareList.push(res.devices[i]);
  226. }
  227. } else {
  228. that.compareList.push(res.devices[i]);
  229. }
  230. }
  231. }
  232. },
  233. fail: (err) => {
  234. console.error('获取蓝牙设备列表失败', err);
  235. }
  236. });
  237. }
  238. ///获取数据
  239. buf2hex(buffer) {
  240. return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
  241. }
  242. ///获取毫秒
  243. getCurrentMills() {
  244. var currentDate = new Date();
  245. var currentTimeMillis = currentDate.getTime();
  246. // return Math.floor(currentTimeMillis / 1000);
  247. return currentTimeMillis;
  248. }
  249. // 等待多少秒
  250. delay(ms) {
  251. return new Promise(resolve => setTimeout(resolve, ms));
  252. }
  253. // 开始搜索蓝牙设备
  254. async startScan(connectWillDevice, boolean, callBackConnect) {
  255. var that = this;
  256. ///限制搜索没有打开蓝牙一直询问打开蓝牙
  257. if (!that.isAvailable) {
  258. if (callBackConnect == null) {
  259. return;
  260. }
  261. ///连接设备
  262. var isAvailable = await that.openBluetoothAdapter();
  263. if (!isAvailable) {
  264. boolean(false);
  265. return;
  266. }
  267. }
  268. const route_util = require('../utils/route_util');
  269. const route_constant = require('../utils/route_constant');
  270. const indexRoot = route_constant.indexRoot;
  271. const connectBleRoot = route_constant.connectBleRoot;
  272. var lastPageRoute = route_util.getLastPageRoute();
  273. if (lastPageRoute != indexRoot && lastPageRoute != connectBleRoot) {
  274. console.log("搜索蓝牙设备失败,请返回首页0");
  275. return;
  276. }
  277. ///蓝牙连接 做限制
  278. if (lastPageRoute == indexRoot) {
  279. if (that.doStartScaning == true) {
  280. console.log("搜索蓝牙设备失败,请返回首页1");
  281. return;
  282. }
  283. }
  284. that.doStartScaning = true;
  285. var currentMill = that.getCurrentMills();
  286. var waitMills = 0;
  287. var reduce = currentMill - that.requestBlueTime;
  288. const delayMiliis = 6 * 1000;
  289. if (reduce > 0 && reduce < delayMiliis) {
  290. waitMills = delayMiliis - reduce;
  291. }
  292. if (waitMills > 0) {
  293. await that.delay(waitMills);
  294. }
  295. if (callBackConnect == null && lastPageRoute == connectBleRoot) {
  296. that.doStartScaning = false;
  297. return;
  298. }
  299. wx.stopBluetoothDevicesDiscovery({
  300. success: (res) => {
  301. console.log("停止搜索设备0", res);
  302. that.search(connectWillDevice, boolean, callBackConnect);
  303. },
  304. fail: (err) => {
  305. console.log("停止搜索设备1", err);
  306. that.doStartScaning = false;
  307. that.requestBlueTime = that.getCurrentMills();
  308. if (boolean != null) {
  309. boolean(false);
  310. }
  311. }
  312. });
  313. }
  314. ///打开蓝牙适配
  315. openBluetoothAdapter() {
  316. var that = this;
  317. return new Promise((resolve, reject) => {
  318. wx.openBluetoothAdapter({
  319. success: function (res) {
  320. that.isAvailable = res.available;
  321. console.log("sdfasdfadsf==00==" + that.isAvailable + "===" + JSON.stringify(res));
  322. resolve(that.isAvailable);
  323. },
  324. fail: function (res) {
  325. console.log("sdfasdfadsf==11==" + that.isAvailable + "===" + JSON.stringify(res));
  326. if (res.errno == 103) {
  327. wx.showModal({
  328. title: '提示',
  329. content: '需要您的蓝牙权限才能使用此功能,是否前往设置授权?',
  330. showCancel: true,
  331. success: (modalRes) => {
  332. if (modalRes.confirm) {
  333. wx.openSetting({
  334. success: (settingRes) => {
  335. console.log("sdfasdfadsf==222==" + that.isAvailable + "===" + JSON.stringify(settingRes));
  336. if (settingRes.authSetting['scope.bluetooth']) {
  337. that.isAvailable = true;
  338. resolve(that.isAvailable);
  339. } else {
  340. that.isAvailable = false;
  341. resolve(that.isAvailable);
  342. }
  343. }
  344. });
  345. } else if (modalRes.cancel) {
  346. that.isAvailable = false;
  347. resolve(that.isAvailable);
  348. }
  349. }
  350. });
  351. } else {
  352. that.isAvailable = false;
  353. resolve(that.isAvailable);
  354. }
  355. }
  356. })
  357. });
  358. }
  359. search(connectWillDevice, boolean, callBackConnect) {
  360. var that = this;
  361. wx.startBluetoothDevicesDiscovery({
  362. allowDuplicatesKey: true,
  363. success: function (res) {
  364. console.log("开始搜索设备", res);
  365. that.getConnectedDevices();
  366. that.doStartScaning = false;
  367. that.requestBlueTime = that.getCurrentMills();
  368. if (boolean != null) {
  369. boolean(true);
  370. }
  371. that.setConnectWillDevice(connectWillDevice);
  372. that.setCallBackConnect(callBackConnect);
  373. that.compareList = [];
  374. },
  375. fail(err) {
  376. console.log("开始搜索设备失败", res);
  377. that.doStartScaning = false;
  378. that.requestBlueTime = that.getCurrentMills();
  379. if (boolean != null) {
  380. boolean(false);
  381. }
  382. },
  383. })
  384. }
  385. // 停止搜索
  386. stopSearch() {
  387. var that = this;
  388. that.setCallBackConnect(null);
  389. that.setConnectWillDevice(null);
  390. return new Promise((resolve, reject) => {
  391. wx.stopBluetoothDevicesDiscovery({
  392. success: (res) => {
  393. resolve(res);
  394. },
  395. fail: (err) => {
  396. reject('停止搜索失败');
  397. }
  398. });
  399. });
  400. }
  401. closeBle() {
  402. console.log('关闭蓝牙了')
  403. closeBluetoothAdapter();
  404. }
  405. // 断开与指定设备的连接
  406. disconnect(mDevice) {
  407. var that = this;
  408. const strings = require('../utils/strings');
  409. let device = that.publicDevice;
  410. if (mDevice != null) {
  411. device = mDevice;
  412. }
  413. if (strings.isEmpty(device)) {
  414. return;
  415. }
  416. let deviceId = device.deviceId
  417. if (strings.isEmpty(deviceId)) {
  418. return;
  419. }
  420. console.log('断开连接', device);
  421. return new Promise((resolve, reject) => {
  422. wx.getConnectedBluetoothDevices({
  423. success: (res) => {
  424. if (res.devices.length > 0) {
  425. wx.closeBLEConnection({
  426. deviceId: deviceId,
  427. success: (res) => {
  428. that.publicDevice = null;
  429. resolve(res);
  430. },
  431. fail: (err) => {
  432. resolve(err);
  433. }
  434. });
  435. } else {
  436. resolve("暂无连接设备");
  437. }
  438. },
  439. fail: (err) => {
  440. resolve(err);
  441. }
  442. });
  443. });
  444. }
  445. // 连接到指定设备
  446. async connectToDevice(device) {
  447. var that = this;
  448. return new Promise((resolve, reject) => {
  449. console.log("开始连接蓝牙:", device.deviceId)
  450. wx.createBLEConnection({
  451. deviceId: device.deviceId,
  452. success: (res) => {
  453. that.publicDevice = device
  454. console.log('连接成功:', res);
  455. resolve(true);
  456. },
  457. fail: (err) => {
  458. that.publicDevice = null
  459. console.error('连接失败:', err);
  460. resolve(false);
  461. }
  462. });
  463. });
  464. }
  465. // 发送数据到指定设备
  466. async sendData(data, callback) {
  467. var that = this
  468. if (that.publicDevice == null) {
  469. console.log("没有连接设备");
  470. return;
  471. }
  472. return new Promise((resolve, reject) => {
  473. var buffer = null;
  474. // todo 判断是否是buffer
  475. // if (needChange) {
  476. // buffer = data;
  477. // } else {
  478. buffer = new ArrayBuffer(data.length);
  479. // 下面是赋值,不能删
  480. const dataView = new DataView(buffer);
  481. data.forEach((value, index) => {
  482. dataView.setUint8(index, value); // 将每个16进制数值写入到 buffer 中
  483. });
  484. // }
  485. let logData = new Uint8Array(buffer);
  486. console.log('开始发送数据:', logData);
  487. wx.writeBLECharacteristicValue({
  488. deviceId: that.publicDevice.deviceId,
  489. serviceId: that.publicDevice.serviceId,
  490. characteristicId: that.publicDevice.characteristicId,
  491. value: buffer,
  492. success: (res) => {
  493. if (callback) {
  494. callback(true)
  495. }
  496. resolve(true);
  497. },
  498. fail: (err) => {
  499. if (callback) {
  500. callback(false)
  501. }
  502. console.log('数据发送失败:', err);
  503. resolve(false);
  504. }
  505. });
  506. });
  507. }
  508. ab2hex(buffer) {
  509. var hexArr = Array.prototype.map.call(
  510. new Uint8Array(buffer),
  511. function (bit) {
  512. return ('00' + bit.toString(16)).slice(-2)
  513. }
  514. )
  515. return hexArr.join(':');
  516. }
  517. fiterDevice(res) {
  518. var that = this;
  519. var devices = res.devices.filter(device => {
  520. const name = device.name || '';
  521. const localName = device.localName || '';
  522. let isNot = that.isNotEmpty(name) || that.isNotEmpty(localName);
  523. if (isNot) {
  524. // console.log('是猫王设备名称:', device.advertisData, device.serviceData)
  525. let mac = that.ab2hex(device.advertisData)
  526. // console.log(mac)
  527. device.mac = mac
  528. }
  529. return isNot
  530. });
  531. let newDevices = devices.map((device) => {
  532. let uuid = device.advertisServiceUUIDs[0] ?? ""
  533. return {
  534. deviceId: device.deviceId,
  535. name: device.name,
  536. localName: device.localName,
  537. uuid: uuid,
  538. mac: device.mac,
  539. connectable: device.connectable
  540. }
  541. });
  542. return newDevices
  543. }
  544. isNotEmpty(name) {
  545. let isNot = (name !== '' &&
  546. (name.startsWith("MW_") ||
  547. name.startsWith("MW-") ||
  548. // name.startsWith("猫王") ||
  549. // name.startsWith("妙播") ||
  550. // name.startsWith("AirSmart") ||
  551. name === "le")
  552. )
  553. // if (!isNot && name !== '') {
  554. // console.log('不是猫王设备名称:', name)
  555. // }
  556. return isNot;
  557. }
  558. // 发现服务
  559. discoverServices(deviceId) {
  560. var that = this;
  561. console.log('发现服务:', deviceId);
  562. return new Promise((resolve, reject) => {
  563. wx.getBLEDeviceServices({
  564. deviceId: deviceId,
  565. success: (res) => {
  566. // that.publicDevice .services = res.services;
  567. let service_id = "";
  568. for (let i = 0; i < res.services.length; i++) {
  569. if (res.services[i].uuid.toUpperCase().indexOf("AB00") != -1 ||
  570. res.services[i].uuid.toUpperCase().indexOf("FFC0") != -1
  571. // res.services[i].uuid.toUpperCase().indexOf("ae800") != -1
  572. ) {
  573. service_id = res.services[i].uuid;
  574. break;
  575. }
  576. console.log('发现服务1:', service_id);
  577. service_id = res.services[i].uuid;
  578. }
  579. that.publicDevice.serviceId = service_id;
  580. console.log('发现服务2:', service_id);
  581. resolve(service_id);
  582. // resolve(res.services);
  583. },
  584. fail: (err) => {
  585. that.publicDevice.serviceId = null;
  586. console.error('发现服务失败:', err);
  587. reject([]);
  588. }
  589. });
  590. });
  591. }
  592. connect() {}
  593. // 发现特征值 read / write
  594. discoverCharacteristics(deviceId, serviceId) {
  595. var that = this;
  596. console.log('发现特征值:' + deviceId + " , " + serviceId);
  597. // if (deviceId !== that.publicDevice .deviceId) {
  598. // console.log('设备id不匹配')
  599. // return false
  600. // }
  601. return new Promise((resolve, reject) => {
  602. wx.getBLEDeviceCharacteristics({
  603. deviceId: deviceId,
  604. serviceId: serviceId,
  605. success: (res) => {
  606. // that.characteristics[serviceId] = res.characteristics;
  607. console.log('发现特征值2:', res);
  608. // that.publicDevice .characteristics = res.characteristics;
  609. resolve(res.characteristics);
  610. },
  611. fail: (err) => {
  612. that.publicDevice.characteristics = null;
  613. console.error('发现特征值失败:', err);
  614. reject("");
  615. }
  616. });
  617. });
  618. }
  619. // 读取特征值
  620. readCharacteristicValue(characteristicId) {
  621. var that = ths;
  622. console.log('开始读取特征值', characteristicId)
  623. return new Promise((resolve, reject) => {
  624. wx.readBLECharacteristicValue({
  625. deviceId: that.publicDevice.deviceId,
  626. serviceId: that.publicDevice.serviceId,
  627. characteristicId: characteristicId,
  628. success: (res) => {
  629. const name = that.parseBLEValue(res.value); // 解析读取到的值
  630. console.log('读取特征值成功:', name, res);
  631. resolve(res);
  632. },
  633. fail: (err) => {
  634. console.error('读取特征值失败:', err);
  635. reject("");
  636. }
  637. });
  638. });
  639. }
  640. // 解析读取到的设备名称
  641. parseBLEValue(buffer) {
  642. return String.fromCharCode.apply(null, new Uint8Array(buffer));
  643. }
  644. // 监听特征值变化
  645. notifyCharacteristicValueChange(characteristicId, callback) {
  646. var that = this;
  647. console.log('监听特征值变化:', characteristicId, that.publicDevice.deviceId, that.publicDevice.serviceId);
  648. wx.notifyBLECharacteristicValueChange({
  649. deviceId: that.publicDevice.deviceId, //设备mac IOS和安卓系统不一样
  650. serviceId: that.publicDevice.serviceId, //服务通道,这里主要是notify
  651. characteristicId: characteristicId, //notify uuid
  652. state: true,
  653. success: function (res) {
  654. console.log("开启notify 成功")
  655. //TODO onBLECharacteristicValueChange 监听特征值 设备的数据在这里获取到
  656. wx.onBLECharacteristicValueChange(function (characteristic) {
  657. let buffer = characteristic.value
  658. let dataView = new DataView(buffer)
  659. let dataResult = []
  660. for (let i = 0; i < dataView.byteLength; i++) {
  661. // console.log("0x" + dataView.getUint8(i).toString(16))
  662. // dataResult.push("0x" + dataView.getUint8(i).toString(16))
  663. dataResult.push(dataView.getUint8(i))
  664. }
  665. const result = dataResult
  666. // console.log("拿到的数据:", result)
  667. if (callback) {
  668. callback(result)
  669. }
  670. })
  671. },
  672. fail: function (res) {
  673. console.log("订阅特征失败:", res)
  674. }
  675. })
  676. }
  677. setWrite(wirte, characteristicId) {
  678. var that = this;
  679. console.log('写入特征值:', characteristicId)
  680. // that.publicDevice .wirte = wirte
  681. that.publicDevice.characteristicId = characteristicId;
  682. }
  683. }
  684. // const ble = new bleManager();
  685. // 导出 bleManager 类
  686. module.exports = bleManager;