deviceConnect4.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const app = getApp();
  2. import strings from '../../utils/strings.js';
  3. const {
  4. BtHelper
  5. } = require('../../devices/bt_helper');
  6. const {
  7. BleUtil
  8. } = require('../../utils/blue_ble/util');
  9. Page({
  10. data: {
  11. nvabarData: {
  12. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  13. title: '连接配网', //导航栏 中间的标题
  14. },
  15. scopeBluetooth: app.globalData.scopeBluetooth,
  16. ssid: app.globalData.ssid,
  17. password: app.globalData.pwdData,
  18. version: '2.0',
  19. name: '',
  20. connectedDeviceId: '',
  21. connected: true,
  22. deviceInfo: null,
  23. isInitOK: false,
  24. customData: '',
  25. percent: 0,
  26. ruterStatus: 0, // 0 连接中 // 1 成功 // 2失败
  27. imageUrl: "./../../img/g.png",
  28. },
  29. onLoad: function (options) {
  30. var that = this;
  31. var param = options.param;
  32. if (!strings.isEmpty(param)) {
  33. param = JSON.parse(param);
  34. that.setData({
  35. imageUrl: param.img,
  36. });
  37. }
  38. // AIrSMArT_861210052356337===D0:31:10:86:AC:9A
  39. /// 纯蓝牙:MW_BLE CC:90:DD:88:C7:E8
  40. var name = options.name;
  41. var deviceId = options.deviceId;
  42. that.setData({
  43. name: name,
  44. connectedDeviceId: deviceId,
  45. });
  46. // var device = {
  47. // "mac": name,
  48. // "deviceId": deviceId
  49. // };
  50. var device = {
  51. "mac": "MW_BLE",
  52. "deviceId": "CC:90:DD:88:C7:E8"
  53. };
  54. console.log("gadsfasdfadfaf===00==");
  55. // BtHelper.getInstance().connect(device, function (isConnected, device) {
  56. // if (isConnected) {
  57. // }
  58. // }, true, device);
  59. BtHelper.getInstance().startScan(device,
  60. async function (b) {
  61. console.log("gadsfasdfadfaf===xxx==" + b);
  62. if (b) {
  63. setTimeout(function () {
  64. console.log("gadsfasdfadfaf===yyy==");
  65. BleUtil.getInstance().startConnect(device, function (changed) {
  66. if (changed) {
  67. BleUtil.getInstance().sendData(device, app.globalData.ssid, app.globalData.pwdData);
  68. }
  69. });
  70. }, 10 * 1000);
  71. }
  72. },
  73. async function (res) {
  74. console.log("gadsfasdfadfaf===yyy==");
  75. await BtHelper.getInstance().stopSearch();
  76. BleUtil.getInstance().startConnect(device, function (changed) {
  77. if (changed) {
  78. BleUtil.getInstance().sendData(device, app.globalData.ssid, app.globalData.pwdData);
  79. }
  80. });
  81. }
  82. );
  83. },
  84. })