如何连续的测量蓝牙的RSSI

Radio Propagation Models



基于蓝牙的RSSI可以有很多应用,要获得蓝牙的RSSI无外乎两种方法,一种就是基于扫瞄的方法,优点是android本身支持,缺点是scan的时间比较长,并且中间过程不受控制,为了连续的测量,需要不断的scan;第二种就是,基于连接的方法,前提是要建立两个蓝牙设备的连接后,再测量RSSI,优点是后期测量比较方便,间隔时间也较短。

  实现的方法,我就抛砖引玉了,有赶兴趣的再交流吧。

转自:http://techtitude.blogspot.com/2013/01/tutorial-to-continuously-measure.html

Tutorial to continuously measure the Bluetooth RSSI of a connected Android device (Java)

Bluetooth RSSI - Nexus7 & Nokia Xpress Music
At the time of this writing, there is no Android API available to continuously retrieve the RSSI of an existing bluetooth connection even though API exists for getting WiFi RSSI. The current API will get the Bluetooth RSSI only during the initial connection setup process. In this article we will find out how to continuously get the Bluetooth RSSI of an Android device and a Nokia Mobile Phone from a computer running Linux.

The RSSI of any device connected to the computer can be determined by using the hcitool in Linux. But this may not be possible with commercial Android devices as root access is required in order to call any functions from the Bluetooth HCI layer using the Android NDK. For experimental purposes, in order to exploit the bluetooth equipment onboard commercial handheld devices, we shall measure the RSSI of these devices by connecting them to a computer or a laptop.

In this experiment the RSSI is being measured continuously in motion from an Android Device (Nexus 7 Tablet) and a Nokia Mobile Phone (Xpress Music) from a computer based on Ubuntu. The source code uses the Bluecove bluetooth library to extract the RSSI information from these connected devices. The Android device and the Nokia device acts like a server and the computer acts like a client.

At the computer, we need to write the client code that will continuously poll the RSSI from our known devices. In order to do this we need to first checkout the bluecove bluetooth libraries from here (http://bluecove.org/source-repository.html). Then we can make use of the BluetoothRSSIPollingClient.java to get the RSSI readings. We can filter out the other discovered devices using the Bluetooth MAC address of our known devices. We can obtain the Bluetooth MAC address of a device from the Preferences Tab of the Bluetooth Menu in Ubuntu after connecting the device with the computer.

Client:

public void PollRSSI()
{
try {
while(true)
                 {
          try {
          System.out.println();
          if(Android_Device != null)
          System.out.println("Android RSSI = " + RemoteDeviceHelper.readRSSI(Android_Device));
     } catch (Exception e) { System.out.println("Android RSSI = Connection Error"); }
          try {
          if(Nokia != null)
          System.out.println("Nokia RSSI = " + RemoteDeviceHelper.readRSSI(Nokia));
      } catch (Exception e) { System.out.println("Nokia RSSI = Connection Error"); }   
          Thread.sleep(2000);
                }
     } catch (Exception e){ e.printStackTrace(); }
}


For the Android device we need to write our own server code in order to overcome the [13] Permission denied error. We might need to run more than one server thread (AcceptThread.java) on the Android device so the incoming connection request will be finally accepted after an initial permission denied error. We will also specify the RFCOMM UUID and a Service name which the client can search and connect to. The entire server has to be implemented as a Service in Android (BluetoothRSSIService.java) so that the connection is not lost if the display screen is timed out.

Server:

public AcceptThread()
{
                   BluetoothServerSocket tmp = null;
                   mBluetooth = BluetoothAdapter.getDefaultAdapter();
                   mUuid = UUID.fromString("00000003-0000-1000-8000-00805F9B34FB");
        try {
                tmp = mBluetooth.listenUsingInsecureRfcommWithServiceRecord("BluetoothCustomService",      mUuid);          
             } catch (IOException e) { }
                myServerSocket = tmp;
         }

public void onCreate()
{
super.onCreate();

thread1 = new Thread(new AcceptThread());
thread1.start(); //First thread will often be denied
thread2 = new Thread(new AcceptThread());
thread2.start(); //Most probably be accepted

}


For the Nokia device there is no explicit server necessary and we can simply connect using the Bluetooth Serial Port Profile connection url. Once the connection is establish we can continuously poll the RSSI from both the devices periodically.

Note: RSSI of Bluetooth may not be an efficient and reliable parameter for applications such as indoor positioning

Source Code:

BluetoothRSSIPollingClient.java       AcceptThread.java       BluetoothRSSIService.java

References:

"A Bluetooth Based Supermarket Navigation System" - Pearl Manoharan, Vignesh Subramanian & Anusha Vutukuri - Course Project - Mobile Systems 16:332:559:02 F12 (Rutgers Fall 2012)  -->
http://developer.android.com/guide/topics/connectivity/bluetooth.html
http://stackoverflow.com/questions/12251785/android-bluetooth-read-rssi-signal-strength
http://bluecove.org/bluecove-examples/bluecove-tester/index.html

有TX问到,为什么RSSI=0,解释如下文,简单点就是这个值是设备相关的。



RSSI is an 8-bit signed integer that denotes whether the re-
ceived (RX) power level is within or above/below the Golden
Receiver Power Range (GRPR), which is regarded as the ideal
RX power range. Fig. 1 illustrates the relationship between
GRPR and RSSI, as defined in Bluetooth specification. A pos-
itive or negative RSSI (in dB) means the RX power level is
above or below the GRPR, respectively, while a zero implies
that it is ideal (i.e., within GRPR). The lower and upper thresh-
olds of GRPR are loosely bound, leaving them to be device-
specific. This, in turn, affects the RSSI, since it is merely a
relative parameter. In fact, its absolute accuracy is not man-
dated in the specification; the only requirement is to be able to
indicate whether it is within, above, or below the GRPR. The
RSSI status parameter of Bluetooth is particularly intended to
be used for power control purpose [6]. The receiver sends “in-
crease” or “decrease” TPL request to the transmitting side, de-
pending on whether the perceived RSSI at its side is negative
or positive, respectively.
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
通过蓝牙RSSI(Received Signal Strength Indication)可以大致估算蓝牙设备之间的距离。RSSI是一种表示无线信号强度的度量指标,其值与设备之间的距离呈反比关系,即距离越远,RSSI值越低。 首先,需要收集一定距离范围内蓝牙设备的RSSI数据。可以使用专门的蓝牙信号强度测量工具或者利用手机等设备自带的蓝牙调试工具进行测量。在不同距离和不同位置进行一系列的测量,并记录下相应的RSSI值。 接下来,将测量得到的RSSI数据整理至Excel表格中。Excel中的一列用于记录距离(单位可以是米),另一列用于记录对应距离下的平均RSSI值。可以通过计算多次测量数据的平均值来获得相对准确的RSSI值。 然后,需要进行一定的数据处理和分析。可以通过绘制距离与RSSI之间的关系曲线,并进行趋势线拟合,从而建立距离和RSSI之间的数学模型。这个模型将帮助我们在未知距离下根据测得的RSSI值进行距离估算。 最后,根据建立的数学模型,通过输入已知的RSSI值,可以通过该模型得出对应的距离估计结果。需要注意的是,距离估算的准确性受到环境的影响,比如物理障碍物或其他无线设备的干扰等。 总的来说,通过蓝牙RSSI计算距离的方法是一种相对简单的估算方法。虽然准确度存在一定的偏差,但在一定程度上可以满足一些基本定位和距离估算的需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值