蓝牙RSSI计算距离
2015-07-21 09:54
393 查看
利用CoreLocation.framework很容易扫描获得周边蓝牙设备,苹果开源代码AirLocate有具体实现,下载地址:
https://developer.apple.com/library/ios/samplecode/AirLocate/Introduction/Intro.html
所获得的iBeacon在CoreLocation里以CLBeacon表示,其中有RSSI值(接收信号强度),可以用来计算发射端和接收端间距离。
计算公式:
d = 10^((abs(RSSI) - A) / (10 * n))
其中:
d - 计算所得距离
RSSI - 接收信号强度(负值)
A - 发射端和接收端相隔1米时的信号强度
n - 环境衰减因子
计算公式的代码实现
传入RSSI值,返回距离(单位:米)。其中,A参数赋了59,n赋了2.0。
由于所处环境不同,每台发射源(蓝牙设备)对应参数值都不一样。按道理,公式里的每项参数都应该做实验(校准)获得。
当你不知道周围蓝牙设备准确位置时,只能给A和n赋经验值(如本例)。
修改AirLocate的APLRangingViewController.m展现部分代码,输出计算距离
扫描结果
![](http://img.blog.csdn.net/20150304144112125?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hhZGVsdHU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
展现了每台蓝牙设备的Acc(精度)、Rssi(信号强度)和Dis(距离)。
https://developer.apple.com/library/ios/samplecode/AirLocate/Introduction/Intro.html
所获得的iBeacon在CoreLocation里以CLBeacon表示,其中有RSSI值(接收信号强度),可以用来计算发射端和接收端间距离。
计算公式:
d = 10^((abs(RSSI) - A) / (10 * n))
其中:
d - 计算所得距离
RSSI - 接收信号强度(负值)
A - 发射端和接收端相隔1米时的信号强度
n - 环境衰减因子
计算公式的代码实现
- (float)calcDistByRSSI:(int)rssi { int iRssi = abs(rssi); float power = (iRssi-59)/(10*2.0); return pow(10, power); }
传入RSSI值,返回距离(单位:米)。其中,A参数赋了59,n赋了2.0。
由于所处环境不同,每台发射源(蓝牙设备)对应参数值都不一样。按道理,公式里的每项参数都应该做实验(校准)获得。
当你不知道周围蓝牙设备准确位置时,只能给A和n赋经验值(如本例)。
修改AirLocate的APLRangingViewController.m展现部分代码,输出计算距离
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; // Display the UUID, major, minor and accuracy for each beacon. NSNumber *sectionKey = [self.beacons allKeys][indexPath.section]; CLBeacon *beacon = self.beacons[sectionKey][indexPath.row]; cell.textLabel.text = [beacon.proximityUUID UUIDString]; // NSLog(@"%@", [beacon.proximityUUID UUIDString]); // NSString *formatString = NSLocalizedString(@"Major: %@, Minor: %@, Acc: %.2fm, Rssi: %d, Dis: %.2f", @"Format string for ranging table cells."); // cell.detailTextLabel.text = [NSString stringWithFormat:formatString, beacon.major, beacon.minor, beacon.accuracy, beacon.rssi, [self calcDistByRSSI:beacon.rssi]]; NSString *formatString = NSLocalizedString(@"Acc: %.2fm, Rssi: %d, Dis: %.2fm", @"Format string for ranging table cells."); cell.detailTextLabel.text = [NSString stringWithFormat:formatString, beacon.accuracy, beacon.rssi, [self calcDistByRSSI:beacon.rssi]]; return cell; }
扫描结果
展现了每台蓝牙设备的Acc(精度)、Rssi(信号强度)和Dis(距离)。
相关文章推荐
- HDOJ 1002 A + B Problem II(大数)
- sublime text2 注册码
- CactiPhone: 移动设备上查看Cacti
- 用日志记录Linux用户执行的每一条命令(history)
- [iOS]获取iOS UI框架中最上层的UIViewController对象
- javascript 对象创建,操作
- 网络安全发草案出炉 CHINASSL构建网络信息安全2.0时代
- 数据库分库分表方案
- iOS UILabel自适应高度的简单实现
- 黑马程序员_C语言基础_关键字、printf函数、scanf函数
- Android中View的绘制过程 onMeasure方法简述 附有自定义View例子
- [Android]使用draw9patch制作可拉伸图片
- Unity AssetBundle爬坑手记
- android通过Location API显示地址信息的实现方法
- 一个 Excel 窗口冻结效果的实现
- 为布尔方法命名
- 计蒜客430同一个节目的不同期竟然可以同时录制
- 细雨学习笔记:Jmeter集合点
- poj 3349 Snowflake Snow Snowflakes
- Android开发者学习必备:10个优质的源码供大家学习