尝试从GATT服务0x1818的循环功率测量GATT特征(0x2A63)访问数据,尝试读取由Assioma Duo踏板踩踏产生的功率。最初称为
device.monitorCharacteristicForService("00001818-0000-1000-8000-00805F9B34FB", "00002a63-0000-1000-8000-00805f9b34fb", (error, characteristic) => {
if (error) {
this.error(error.message)
return
}
this.updateValue(characteristic.uuid, characteristic.value)
})
但是this.state.value仍然为空。
决定测试该特性是否完全可读。这是相关的代码
import React, { Component } from 'react';
import { BleManager } from 'react-native-ble-plx';
import { StyleSheet, Text, View, Dimensions, Button, TouchableOpacity, TextInput, Alert, Image, Linking, Platform } from 'react-native';
export default class App extends React.Component {
constructor(){
super()
this.manager = new BleManager();
this.state = {info: "h", values: {}};
}
async testChar(device) {
const characteristics: [Characteristics] = await device.characteristicsForService("00001818-0000-1000-8000-00805F9B34FB");
for (let k = 0; k<characteristics.length;k++) {
const char: Characteristics = characteristics[k];
console.log(`Characteristics for service: ${char.isReadable}`);
}
}
scanAndConnect() {
this.manager.startDeviceScan(null,
null, (error, device) => {
this.info("Scanning...")
console.log(device)
if (error) {
this.error(error.message)
return
}
if (device.name === 'ASSIOMA22702U') {
this.info("Connecting to Assioma")
this.manager.stopDeviceScan()
device.connect()
.then((device) => {
return this.testChar(device)
})
}
});
}
登录.isReadable调用-
LOG Characteristics for service: false
LOG Characteristics for service: true
LOG Characteristics for service: false
LOG Characteristics for service: true
,特征0x2A63为第一个错误。为什么此特征不可读?