收藏
回答

想问问蓝牙发送为何不能实现定时器发送数据?

  createBLEConnection(e) {

    const ds = e.currentTarget.dataset

    const deviceId = ds.deviceId

    const name = ds.name

    wx.createBLEConnection({

      deviceId,

      success: (res) => {

        this.setData({

          connected: true,

          name,

          deviceId,

        })

        this.getBLEDeviceServices(deviceId)

      }

    })

    this.stopBluetoothDevicesDiscovery()

    setInterval(function () {

      // writeBLECharacteristicValue(0xffff)

      console.log(this._deviceId,this._serviceId)

      let buffer = new ArrayBuffer(1)

      let dataView = new DataView(buffer)

      dataView.setUint16(0,0xffff)

      wx.writeBLECharacteristicValue({

        deviceId: this._deviceId,

        serviceId: this._serviceId,

        characteristicId: this._characteristicId,

        value: buffer,

      })


      }, 100)

  },


回答关注问题邀请回答
收藏
登录 后发表内容