deviceConnect4.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. if (b) {
  62. setTimeout(function () {
  63. BleUtil.getInstance().startConnect(device, function (changed) {
  64. if (changed) {
  65. BleUtil.getInstance().sendData(device, app.globalData.ssid, app.globalData.pwdData);
  66. }
  67. });
  68. }, 10 * 1000);
  69. }
  70. },
  71. async function (res) {
  72. await BtHelper.getInstance().stopSearch();
  73. BleUtil.getInstance().startConnect(device, function (changed) {
  74. if (changed) {
  75. BleUtil.getInstance().sendData(device, app.globalData.ssid, app.globalData.pwdData);
  76. }
  77. });
  78. }
  79. );
  80. },
  81. })