Android 2.1:如何轮询现有蓝牙连接的 RSSI 值? [英] Android 2.1: How do I poll the RSSI value of an existing Bluetooth connection?

查看:20
本文介绍了Android 2.1:如何轮询现有蓝牙连接的 RSSI 值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道与我使用 Android 2.1 手机建立的远程设备的蓝牙连接的信号强度.从 SDK 中可以看出,我可以在发现远程设备时确定 RSSI.但我不知道如何随时间更新该 RSSI 值.

I need to know the signal strength of a Bluetooth connection to a remote device that I make with my Android 2.1 phone. From the SDK, I can see that I can determine the RSSI at the time I discover the remote device. But I can't see how to update that RSSI value over time.

有人可以帮我吗?谢谢!!

Can someone give me a hand? Thanks!!

推荐答案

从 SDK 获取 RSSI 的唯一途径.这有点不方便,因为如果您只想定期监视配对设备的信号强度,它就没有用.

From the SDK it is the only way to obtain RSSI. It is a little bit inconvenient, since it is not useful if you only want to periodically monitor the strength of the signal of a paired device.

不过有一种方法,但是脱离了SDK.您可以使用原生 API(通过 NDK)并调用 Bluez API 提供的函数,Bluez API 是Android(以及几乎所有的 linux 系统).有问题的函数是 libbluetooth.so(Bluez 堆栈的一部分)提供的 hci_read_rssi().为了学习如何使用它,您可以查看 Hcidump 工具源(随附蓝兹).您可以为您的函数编写 JNI 包装器代码,这样您就可以获得配对设备的信号强度.

However there is a way, but out of SDK. You can use native API (by means of NDK) and call functions provided by Bluez API, the underlying bluetooth framework in Android (and almost any linux system). The function in question is hci_read_rssi() provided by libbluetooth.so (part of Bluez stack). In order to learn how to use it, you can take a look at Hcidump tool sources (that comes with Bluez). You could write a JNI wrapper code to your function, so you could get the signal strength of paired device.

使用这种方法有两个缺点:

There are two drawbacks of using this method:

  • 要测量 RSSI,您必须首先连接到远程设备,至少在低级别(此连接不需要身份验证)并在调用 hci_read_rssi() 后释放连接.这比仅通过信标测量 RSSI 慢,因为其他无线通信方式提供(GSM 或 WIFI)
  • 与远程蓝牙设备的低级别连接需要 Android 超级用户权限.因此,忘掉可以在未遭黑客入侵的手机上运行的编写和应用程序(它们通常没有根访问权限,有些像摩托罗拉 Droid/Milestone 甚至在您尝试获得它时也会使保修无效).
  • To measure RSSI you must first connect to remote device, at least at low level (no authentication is required for this connection) and release connection after calling hci_read_rssi(). This is slower than just measuring RSSI from beacons, as other wireless communication means provide (GSM or WIFI)
  • Low level connection to remote bluetooth devices requires on Android superuser rights. So forget about writing and application that can be run on non hacked phones (they usually come with no root access, and some like Motorola Droid/Milestone even void warranty if you try to gain it).

这篇关于Android 2.1:如何轮询现有蓝牙连接的 RSSI 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆