使用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()
}
}
})
}