我正在尝试捕捉 BLE 信号,并通过使用“BluetoothLeScanner”来测量两部手机之间的距离来获取 rssi vlue。
但是,我的程序检测到除了手机上的蓝牙信号之外的每个 BLE_signal。
以下是我在运行程序时使用 Log.e 打印的内容。
'''
2019-12-01 00:21:16.319 22089-22089/com.example.bluetooth E/get_RSSI:
name: null, addr: 33:DC:55:32:73:96, rssi: -88, distance: 8.912509381337454
2019-12-01 00:21:16.949 22089-22089/com.example.bluetooth E/get_RSSI:
name: null, addr: 33:DC:55:32:73:96, rssi: -92, distance: 14.12537544622754
2019-12-01 00:21:16.962 22089-22089/com.example.bluetooth E/get_RSSI:
name: null, addr: 22:32:AA:BF:25:16, rssi: -45, distance: 0.06309573444801933
2019-12-01 00:21:17.054 22089-22089/com.example.bluetooth E/get_RSSI:
name: null, addr: 33:DC:55:32:73:96, rssi: -92, distance: 14.12537544622754
2019-12-01 00:21:17.064 22089-22089/com.example.bluetooth E/get_RSSI:
name: null, addr: 22:32:AA:BF:25:16, rssi: -45, distance: 0.06309573444801933
2019-12-01 00:21:17.661 22089-22089/com.example.bluetooth E/get_RSSI:
name: null, addr: 22:32:AA:BF:25:16, rssi: -49, distance: 0.1
2019-12-01 00:21:18.408 22089-22089/com.example.bluetooth E/get_RSSI:
name: null, addr: 22:32:AA:BF:25:16, rssi: -42, distance: 0.04466835921509631
2019-12-01 00:21:18.425 22089-22089/com.example.bluetooth E/get_RSSI:
name: null, addr: 33:DC:55:32:73:96, rssi: -87, distance: 7.943282347242816
2019-12-01 00:21:19.148 22089-22089/com.example.bluetooth E/get_RSSI:
name: null, addr: 22:32:AA:BF:25:16, rssi: -48, distance: 0.08912509381337455
2019-12-01 00:21:19.779 22089-22089/com.example.bluetooth E/get_RSSI:
name: null, addr: 22:32:AA:BF:25:16, rssi: -46, distance: 0.0707945784384138
以下是 MainActivity、onResume() 和 Bluetooth2 类
override fun onResume() {
super.onResume()
val mBlueToothAdapter = BluetoothAdapter.getDefaultAdapter()
val mBLEScanner = mBlueToothAdapter.getBluetoothLeScanner()
Bluetooth2().initialize(mBLEScanner)
}
...
class Bluetooth2 {
val mScanCallback = object: ScanCallback(){
override fun onScanResult(callbackType: Int, result: ScanResult?) {
super.onScanResult(callbackType, result)
val RSSI = result?.rssi
val NAME = result?.device?.name
val ADDR = result?.device?.address
if(!BLE_DB().contains(ADDR)) {
val text = "$ADDR $RSSI"
BLE_DB().append(1, text)
BLE_DB().append(2, NAME)
}
Log.e("get_RSSI", " name: $NAME, addr: $ADDR, rssi: $RSSI, distance: ${rssiTodis(RSSI)}")
}
}
.
.
.
fun initialize(bluetoothLeScanner: BluetoothLeScanner){
BLE_DB().initialize()
bluetoothLeScanner.startScan(mScanCallback)
Log.e("Initialization", "Initialized")
}
...
'''
不知道为什么手机收不到信号...
请帮我...
图 1 是我运行蓝牙时蓝牙窗口的屏幕截图。图 2 是现有的 RSSI 分析仪应用程序。正如您在图片中看到的,我的手机可以扫描我的 Galaxy S7 手机并识别它,但我在我的程序日志中看不到它。我应该怎么办?