const startNotice = (notify, serviceId) => {
uni.notifyBLECharacteristicValueChange({
characteristicId: notify,
deviceId: props.id,
serviceId: serviceId,
state: true,
success(res) {
console.log('返回', res);
// 监听低功耗蓝牙设备的特征值变化
uni.onBLECharacteristicValueChange(result => {
if (result.value) {
console.log('返回数据', result.value)
let view = new Uint16Array(result.value)
if (result.value.byteLength == 200) {
for (let i = 0; i <view.length; i++) {
state.alllistTwoYuan.push(view[i])
state.id = state.id + 1
state.xdataList.push(state.id)
state.alllist.push(view[i])
}
console.log('返回数据', state.alllistTwoYuan)
if (state.alllistTwoYuan.length == 2000) {
state.alllistTwoYuan.splice(0, 100)
state.xdataList.splice(0, 100)
}
// chart.value.init(echarts, chart => {
state.option.series[0].data = state.alllistTwoYuan
chart.value.setOption(state.option)
// });
emit('goData', {
voltage: state.alllist,
alllistTwoYuan: state.alllistTwoYuan,
time: state.xdataList.length - 1,
})
}
}
})
}
});
};
以上代码就是通过蓝牙传输过来的数据进行绘制实时折线图,
uni社区问问