当前,我有一个蓝牙应用程序,它将扫描所有可用的设备并能够连接到该设备。
我有listview,每次找到蓝牙设备时都会显示该列表。 但是,我能知道如何使应用程序每秒更新一次RSSI值吗?
这是我的代码。
doStartScanning(){
this.peripherals=[];
this.distance=[];
bluetooth.startScanning({
serviceUUIDs: [],
// seconds: 4, /*if this is not specify, user can manually stop the scanning by press button stop scan*/
onDiscovered: (peripheral) => {
this.zone.run(() => {
console.log("---UUID "+peripheral.UUID);
this.peripherals.push(peripheral);
this.distance.push(`${Math.round((Math.pow(10,(-62-(peripheral.RSSI+20))/20))*10)/10}`);
})
}
}
).then(function() {
console.log("scanning complete");
}, function (err) {
console.log("error while scanning: " + err);
});
}
/*user can stop scan the available bluetooth*/
doStopScanning(){
bluetooth.stopScanning().then(function() {
console.log("Scanning Stop!");
},
function (err) {
dialogs.alert({
title: "Whoops!",
message: err,
okButtonText: "OK, so be it"
});
});
}
<GridLayout rows="*">
<ListView [items]="peripherals" separatorColor="#90c3d4">
<ng-template let-peripherals="item" let-i="index" let-odd="odd" let-even="even">
<StackLayout orientation="horizontal" class="padded-label" >
<StackLayout class="padded-label-stack">
<Label horizontalAlignment="right" width="40" text="{{ peripherals.RSSI +20}} dBm" class="rssi-label" ></Label>
<Label horizontalAlignment="right" width="40" text="{{ distance[i] }} m" class="rssi-label" ></Label>
</StackLayout>
<StackLayout class="padded-label-stack" (tap)="onTapPeripheral(peripherals.UUID,peripherals.name, peripherals.state)">
<Label text="Name: {{ peripherals.name }}" class="title-label" textWrap="true" ></Label>
<Label text="UUID: {{ peripherals.UUID }}" class="uuid-label" textWrap="true" ></Label>
<Label text="State: {{ peripherals.state }}" class="uuid-label" textWrap="true" ></Label>
</StackLayout>
</StackLayout>
</ng-template>
</ListView>
</GridLayout>
答案 0 :(得分:0)
不幸的是,插件尚不支持阅读RSSI。您可能必须重写插件实现的CBPeripheralDelegate
/ BluetoothGattCallback
才能阅读。