ble_manager.js 22 KB

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