收藏
回答

writeBLECharacteristicValue写入数据返回成功后,硬件内信息查询未存储?

使用writeBLECharacteristicValue写入数据返回成功后,对硬件内的信息进行查询,实际没有信息存储

const addWifi = () => {
  const command = `at+wifi_add=${state.wifiPwd}@${state.wifiName}\r\n`
  const buffer = stringToAsciiCodes(command)
  Taro.writeBLECharacteristicValue({
    deviceId: getStorageSync(CUR_USER_TEACHING_ASSISTANT).macAddress,
    serviceId: serviceId,
    characteristicId: characteristicId,
    value: buffer,
    success(res) {
      console.log('增加wifi成功', res)
      toggleWifi(true)
      const wifiBuffer = stringToAsciiCodes('at+wifi?\r\n')
      Taro.writeBLECharacteristicValue({
        deviceId: getStorageSync(CUR_USER_TEACHING_ASSISTANT).macAddress,
        serviceId: serviceId,
        characteristicId: characteristicId,
        value: wifiBuffer,
        success(writeRes) {
          console.log('指令发送成功', writeRes)
        },
        fail(err) {
          console.error('指令发送失败:', err)
        }
      })
      routeBack({ delta: 3 })
    },
    fail(err) {
      console.log('增加wifi失败', err)
      if (err.errMsg.includes('no connection')) {
        // connectToDevice()
      }
    }
  })
}


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