deviceConnect4.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const app = getApp();
  2. import strings from '../../utils/strings.js';
  3. const {
  4. BleUtil
  5. } = require('../../utils/blue_ble/util');
  6. const {
  7. BtHelper
  8. } = require('../../devices/bt_helper');
  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. var name = options.name;
  40. var deviceId = options.deviceId;
  41. that.setData({
  42. name: name,
  43. connectedDeviceId: deviceId,
  44. });
  45. var device = {
  46. "deviceId": deviceId
  47. };
  48. console.log("gadsfasdfadfaf===000==" + JSON.stringify(device));
  49. BleUtil.getInstance().startConnect(device, function (changed) {
  50. console.log("gadsfasdfadfaf===111==" + changed);
  51. BleUtil.getInstance().sendData(device, "哈哈哈哈哈哈");
  52. });
  53. },
  54. })