Ionic framework 您可以随时阅读信息
我想一直通过蓝牙从传感器读取数据。我遵循文档,但我无法设置手机通过蓝牙从传感器读取数据。首先,我将手机与传感器连接,然后通过以下方式添加通知:Ionic framework 您可以随时阅读信息,ionic-framework,bluetooth,bluetooth-lowenergy,sensors,Ionic Framework,Bluetooth,Bluetooth Lowenergy,Sensors,我想一直通过蓝牙从传感器读取数据。我遵循文档,但我无法设置手机通过蓝牙从传感器读取数据。首先,我将手机与传感器连接,然后通过以下方式添加通知: this.ble.startNotification(peripheral.id,SERVICE_UUID, CHARACTERISTIC_UUID).subscribe( data => {this.onChange(data);} ) 其中onChane(数
this.ble.startNotification(peripheral.id,SERVICE_UUID,
CHARACTERISTIC_UUID).subscribe(
data => {this.onChange(data);}
)
其中onChane(数据)为:
接下来我
this.ble.read(peripheral.id,SERVICE_UUID,CHARACTERISTIC_UUID).then(
(data) => {this.onChange(data);},
(err) => {console.log(err);}
)
我这次读不及格。特征标识和服务标识是常量。怎么了?我怎样才能纠正我的手机一直接收数据的错误?如果使用通知,则无需读取特征值。订阅通知后,每当值发生更改时,外围设备将以新值通知您。看起来您的onChange函数就是这样做的 如果特征支持read属性,则可以选择读取该值。查看返回到connectsuccess回调的属性以查看特征属性 看看我的眼睛。连接到外围设备,订阅通知,并一次性读取值,以便IU可以使用当前值更新UI。看
this.ble.read(peripheral.id,SERVICE_UUID,CHARACTERISTIC_UUID).then(
(data) => {this.onChange(data);},
(err) => {console.log(err);}
)