Android NDK开发详解连接性之通过 RTT 确定 Wi-Fi 位置信息


您可以利用 Wi-Fi RTT(往返时间)API 提供的 Wi-Fi 位置功能测量距附近支持 RTT 的 Wi-Fi 接入点和 Wi-Fi 感知对等设备的距离。

如果您测量与三个或更多接入点的距离,可以使用多点定位算法来预估与这些测量值最相符的设备位置。结果通常可以精确到 1 至 2 米。

凭借这种精准度,您可以开发基于精确位置的服务,例如室内导航、无歧义语音控制(例如,“打开这盏灯”)以及基于位置的信息(例如,“此产品是否有特别优惠?”)。

请求发出设备无需连接到接入点即可通过 Wi-Fi RTT 测量距离。为了保护隐私,只有发出请求的设备能够确定距接入点的距离,接入点没有此类信息。前台应用执行 Wi-Fi RTT 操作不受限制,但后台应用执行此类操作时会受限。

Wi-Fi RTT 和相关精确时间测量 (FTM) 功能根据 IEEE 802.11mc 标准指定。Wi-Fi RTT 需要 FTM 提供的精确时间测量,因为前者通过测量数据包在设备之间往返所需的时间,并将该时间乘以光速来计算两个设备之间的距离。

实现差异因 Android 版本而异

Wi-Fi RTT 在 Android 9(API 级别 28)中引入。使用此协议在搭载 Android 9 的设备中使用多点定位来确定设备的位置时,您需要有权访问应用中预先确定的接入点 (AP) 位置数据。存储和检索此类数据的方式由您决定。

在搭载 Android 10(API 级别 29)及更高版本的设备上,AP 位置数据可以表示为 ResponderLocation 对象,其中包括纬度、经度和海拔高度。对于支持位置配置信息/位置城市报告(LCI/LCR 数据)的 Wi-Fi RTT AP,协议会在测距过程中返回 ResponderLocation 对象。

此功能支持应用查询 AP,以直接询问 AP 的位置,而无需提前存储此类信息。因此,即使之前不知道 AP(例如用户进入新建筑物时),您的应用也可以找到 AP 并确定其位置。

要求

测距请求发出设备的硬件必须实现 802.11mc FTM 标准。
测距请求发出设备必须搭载 Android 9(API 级别 28)或更高版本的操作系统。
测距请求发出设备必须启用位置信息服务并打开 WLAN 扫描(位于设置 > 位置信息下)。
测距请求发出设备必须拥有 ACCESS_FINE_LOCATION 权限。
当应用可见或在前台服务中时,应用必须查询接入点的范围。应用无法在后台访问位置信息。
接入点必须实现 IEEE 802.11mc FTM 标准。

设置

如需将应用设置为使用 Wi-Fi RTT,请执行以下步骤。

1.请求权限
在应用的清单中请求以下权限:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

ACCESS_FINE_LOCATION 权限属于危险权限,因此每次用户要执行 RTT 扫描操作时,您都需要在运行时请求该权限。如果尚未获得授权,应用需要向用户请求该权限。如需详细了解运行时权限,请参阅请求应用权限。

注意:如果用户在测距操作期间撤消必要权限,系统将会取消操作并报告失败。
2. 检查设备是否支持 Wi-Fi RTT
如需检查设备是否支持 Wi-Fi RTT,请使用 PackageManager API:

Kotlin

context.packageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_RTT)

Java

context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_RTT);
  1. 检查 Wi-Fi RTT 是否可用
    设备上可能存在 Wi-Fi RTT,但由于用户已停用 WLAN,该功能目前或不可用。如果 SoftAP 或网络共享处于使用状态,某些设备可能不支持 Wi-Fi RTT,具体视设备的硬件和固件功能而定。如需检查 Wi-Fi RTT 当前是否可用,请调用 isAvailable()。

Wi-Fi RTT 的可用性随时都可能发生变化。您的应用应注册 BroadcastReceiver 才能收到当可用性发生变化时发送的 ACTION_WIFI_RTT_STATE_CHANGED。应用收到该广播 intent 后,应检查可用性的当前状态并相应地调整其行为。

例如:

Kotlin

val filter = IntentFilter(WifiRttManager.ACTION_WIFI_RTT_STATE_CHANGED)
val myReceiver = object: BroadcastReceiver() {

    override fun onReceive(context: Context, intent: Intent) {
        if (wifiRttManager.isAvailable) {} else {}
    }
}

Java

IntentFilter filter =
    new IntentFilter(WifiRttManager.ACTION_WIFI_RTT_STATE_CHANGED);
BroadcastReceiver myReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (wifiRttManager.isAvailable()) {} else {}
    }
};
context.registerReceiver(myReceiver, filter);

context.registerReceiver(myReceiver, filter)
注意:确保您在检查可用性之前注册广播接收器。否则,在一段时间内,应用可能会认为 Wi-Fi RTT 可用,但在可用性发生变化时不会收到通知。
如需了解详情,请参阅广播。

创建测距请求

通过指定请求范围的 AP 或 Wi-Fi 感知对等设备的列表,即可创建测距请求 (RangingRequest)。您可以在单个测距请求中指定多个接入点或 Wi-Fi 感知对等设备,然后测量并返回与所有设备的距离。

例如,请求可以使用 addAccessPoint() 方法指定要测量距离的接入点:

Kotlin

val req: RangingRequest = RangingRequest.Builder().run {
    addAccessPoint(ap1ScanResult)
    addAccessPoint(ap2ScanResult)
    build()
}

Java

RangingRequest.Builder builder = new RangingRequest.Builder();
builder.addAccessPoint(ap1ScanResult);
builder.addAccessPoint(ap2ScanResult);

RangingRequest req = builder.build();

接入点由其 ScanResult 对象标识,该对象可通过调用 WifiManager.getScanResults() 获得。您可以使用 addAccessPoints(List) 批量添加多个接入点。

同样,测距请求可以通过以下两种途径添加 Wi-Fi 感知对等设备:使用 addWifiAwarePeer(MacAddress peer) 方法利用相应设备的 MAC 地址,或者使用 addWifiAwarePeer(PeerHandle peer) 方法利用相应设备的 PeerHandle。如需详细了解如何发现 Wi-Fi 感知对等设备,请参阅 Wi-Fi 感知文档。

请求测距

应用使用 WifiRttManager.startRanging() 方法发出测距请求,并提供以下内容:用于指定操作的 RangingRequest、用于指定回调上下文的 Executor,以及用于接收结果的 RangingResultCallback。

例如:

Kotlin

val mgr = context.getSystemService(Context.WIFI_RTT_RANGING_SERVICE) as WifiRttManager
val request: RangingRequest = myRequest
mgr.startRanging(request, executor, object : RangingResultCallback() {

    override fun onRangingResults(results: List<RangingResult>) {}

    override fun onRangingFailure(code: Int) {}
})

Java

WifiRttManager mgr =
      (WifiRttManager) Context.getSystemService(Context.WIFI_RTT_RANGING_SERVICE);

RangingRequest request ...;
mgr.startRanging(request, executor, new RangingResultCallback() {

  @Override
  public void onRangingFailure(int code) {}

  @Override
  public void onRangingResults(List<RangingResult> results) {}
});

测距操作以异步方式执行;测距结果在 RangingResultCallback 的某个回调中返回:

如果整个测距操作失败,将会触发 onRangingFailure 回调,并返回 RangingResultCallback 中描述的状态代码。如果该服务当时出于某些原因(例如 WLAN 已停用、应用请求的测距操作过多并受到限制,或者存在权限问题)无法执行测距操作,可能会发生此类失败。
测距操作完成后,会触发 onRangingResults 回调,并返回与请求列表匹配的结果列表(每个请求对应一个结果)。结果的顺序不一定与请求的顺序一致。请注意,测距操作可能已经完成,但每个结果仍有可能提示该特定测量失败。

解读测距结果

onRangingResults 回调返回的每个结果均由 RangingResult 对象指定。请对每个请求执行以下操作。

  1. 识别请求
    根据创建 RangingRequest 时提供的信息识别请求:此类信息通常是在用于识别接入点的 ScanResult 中提供的 MAC 地址。您可以使用 getMacAddress() 方法从测距结果中获取 MAC 地址。

测距结果列表的顺序可能与测距请求中指定的对等设备(接入点)的顺序不同,因此您应使用 MAC 地址而非结果的顺序来识别对等设备。

  1. 确定每个测量是否成功
    如需确定测量是否成功,请使用 getStatus() 方法。STATUS_SUCCESS 以外的任何值都表示失败。失败意味着此结果的所有其他字段(上述请求标识除外)均为无效字段,相应的 get* 方法也将失败,并出现 IllegalStateException 异常。

  2. 获取每个成功测量的结果
    对于每个成功的测量,您可以使用相应的 get 方法检索结果值:

距离(单位为毫米)和测量的标准偏差:

getDistanceMm()

getDistanceStdDevMm()

用于测量的数据包的 RSSI:

getRssi()

测量所用时间(以毫秒为单位;表示自启动以来的时间):

getRangingTimestampMillis()

尝试的测量次数和成功的测量次数(以及距离测量的依据):

getNumAttemptedMeasurements()

getNumSuccessfulMeasurements()

支持 Wi-Fi RTT 的 Android 设备

以下表格列出了支持 Wi-Fi RTT 的一些手机和接入点。这些远远不够全面。建议您与我们联系,以便在此列出您提供的支持 RTT 的产品。

手机

在这里插入图片描述

接入点

在这里插入图片描述

本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。

最后更新时间 (UTC):2020-06-23。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
室内定位算法,有助于研究者认清研究方向,给定位算法一个准确的描述,是很好的参考教材。the possibility for the user to be notified by visible and Waveformof Distance audible warnings using buzzer and led ar to Very close to al 1903 Tme「 samples Fig 4 Distance measurement using the RSSi signal The system is used to determine the distance between Fig. 2. Tag4M Data Acquisition System tags and 2, 3, 4 or more APs. The tag scans after the aps ⅣV. EXPERIMENTS and sends the rssi values for each ap to the ap which is associated The system presented above can be used for objects or In order to read the corresponding rSsi values of all people localization in an indoor enviro found access points, a""operation is implemented at Let's suppose a building where several objects are Tag4M level. The time to scan is smaller than few distributed all over milliseconds, because the tag doesnt associate with the all For a better understanding of the system, it is showed an APs. These values are sent to a pC where the localization experiment where the objects are placed only at one floor. algorithm is implemented in LabVIFW20 10 (see Fig. 5) Each of these objects has attached a tag. The devices are Table I presents a scan operation result. In this case used to determine the location of the objects in the four APs(which are placed in the floor building)named building and the distance between tags and APs. To Hawk, Helicopter, Tag4M and WitagServer are detected measure the distance, the RSSI is processed. This method The corresponding rSSi values(in dBm) measured by the is not very accurate and is strong depended to the Tag4M are reported for every AP environment, but is very easy to implement with the TABLE 1. A SEQUENCE OF RESULTS FOR THE SCANOPERATION The Fig 3 presents the experiment environment for one EXFCUTED ON THE TAG4M DEVICE oor where the colored circles represents the APs and the rectangles represents the objects intended to be located This floor is divided in six rooms separated by walls RSSI Scan results: 4 Time Ssid Ch ad-Iloc Sec wps mac Address erp WMM SSI Supported Rates(Mbits, Mandatory) Crypto Suites CW Max/min AP SCAN. llawk. -57 dBm AP SCAN, Helicopter, -50 dBm, AP SCAN, Tag4M.-68 dBm AP SCAN. WitagServer. -45 dBm The Rssi values are converted to distance values using formula(1) The value of the received signal strength is a function of the transmitted power and the distance between the Fig 3. The Experiment Environment sender and the receiver. The received signal strength will decrease when the distance increases as the following First step in finding the location is distance equation shows [23] measurement using the RSSI signal. The experiment for computing the distance is presented in Fig. 4. The RSSI(IOn- logo+A)(1) experimental precisions of measurements are less than 5 meters Where: lal propagation constant al d propagation exponent. d represents the distance from sender, A represents the received signal strength at a distance of one meter worn even by people. The system runs on batterie w sSID having a characteristic life time of a couple of years and 回H offers a platform for sensor measurements. Thus, the system can use any existent infrastructure, with significant decrease of implementation costs REFERENCES [1] H. Liu, H. Darabi, P. Banerjee and J. Liu, ""Survey of wireless Distance 2 Tn] aRch Indoor Positioning Techniques and SystemS", IEEE TRANSACTIONS ON SYSTEMS. MAN. AND CYBERNETICS-PART C: APPLICATIONS AND REVIEWS VOL 37, NO 6, NOVEMBER 2007, pp. 1067-10801 Distance 3[] [2 Want, A. Hopper, V. FalcaO, J. Gibbons, "The Active Budge 4MDastDct v Location System, ACM Transactions on Information Systems vol. 10, no l, January 1992, pp 91-102. Fig. 5. Block Diagram of the localization program [3] Firefly Motion Tracking System User's guide", vcrsion 2.2 December 1999 http://www.gesturecentral.com/firefly/fireflyuserguide.pdf The application compute the distances between the Wi- [4] Northen Digilal Inc. Website, Oplotrak PROseries, 2011 Fi Tags placed on targets and the APs placed in indoor http:/www.ndigital.com/industrial/optotrakproseries-family.php [5] E. Aitenbichler, M. Mhlhuser, An /R Local Positioning System for environment. For this case, three APs are enough but the Smart Items and Devices Proc. 23rd IEEE Internationa number of Aps can be increased for obtaining more Conference on Distributed Computing Systems Workshops accurate position estimation. The distances between the TWSAWC03), 2003 Wi-fiTagsandeachAparerepresentedascirclesasit[6]topaz,2004,http:/www.tadlys.co.il/pAges/productcontent.asp?igi bald=2 can be seen in Fig. 6, having the centre in the AP locations [7 A. Kotanen, M. Hannikainen, H. Leppakoski, and T. D which have previously known coordinates. The target's Hamalaincn, E.cperiments on local positioning with Bluetoothin position is given by the point at the intersection of the Proc. IEEE Int Conf. Inf. Technol. Comput. Commun., Apr 2003 three circles PP.297-303 [8 J. Hallberg, M. Nilsson, and k. Synnes, "Positioning with Bluetooth"in Proc. Ieee 10th Int Conf. Telecommun. Mar. 2003 ol.2,pp.954958 9 Active bat website. 2008 http:/www.cl.cam.ac.uk/research!dtg/attarchive/bat/ [10] Hazas, M, Hopper, A, "A Novel Brucdbund Ultrasonic Locution System for Improved Indoor Positioning IEEE Transactions on mobile Computing. Vol 5, No 5, May 2006 [11 N B Priyantha, The Cricket Indoor Location System", PhD thes MIT.2005 2]SonitorSystemWebsite2011,http://www.sonitor.com/ [13] Minami M, Fukuju Y, Hirasawa K, Yokoyama S, Mizumachi M Aoyama T ,"Dolphin. A practical approach for implementing a fully distributed indoor ultrasonic positioning system", Ubicomp, 2004, 347-365 Fig. 6. Front Panel of the localization program 14]J. Ilightower, R. Want, and G. borriello, SpotON: An indoor 3D cation sensing technology hased on RF signal strength"Univ The simplicity and cost efficiency of the rssi based Washington, Seattle, Tech Rep UW CSE 2000-02-02, Feb. 2000 localization make the proposed system a desired candidate 15]L. M. Ni, Y. Liu, Y. C. Lau, and A. P. Patil,"LANDMARC: Indoor location sensing using active RFID Wireless Netw., vol 10, no 6 for specific applications like tracking and positioning svstems hP.701-70.N0v.200 Zebra Technologies Corporation eb sit http://www.7ebra.com/id/zebra/na/en/index/products/location/isoie c 24730 2html V. CONCLUSION [17 P. Bahl and V. Padmanabhan, "RADAR: An in-building rf based user location and tracking system, Proc. IEEE INFOCOM, voL 2 In this paper, an indoor localization system based on March200,pp.775784 ultra-low power Wi-Fi technology and designed to 18Ekahau2011,http://www.ekahau.com: [19] T. King, S. Kopf, T. Haenselmann, C. Lubberger and w determine location of objects in a closed environment is Effelsberg, "COMPASS: A Probabilistic Indoor Positioning System proposed gILo rOC In the first part of this paper a survey of existing indoor Workshop on Wireless Network Testbeds, Experimental evaluation and Cllaracterization (WiNTECID), Los Angeles, CA, USA positioning systems was made In the second part was presented the way in which an [20] Convert sensor data to web pages using a Cloud Instrument, june object can be localized by using access points and Tag 4M 2011.http://www.tag4m.com devices which may read the rssi values [21Tag4mDatasheet2010,http://test.tag4m.com/wp- content/uploads/20/03/Tag4M Prod Datasheet Revised3. pdf The importance of the proposed system lies in ultra-low [22] Aamodt, K.(2006). CC2431 Location Engine, Application Note power and Wi-Fi transmission capabilities that are An042,fromhttp://focus.tii.co.ip/ip/lit/an/swra095/swra095.pdf embedded in a very small package, why they are suitable 320
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

五一编程

程序之路有我与你同行

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值