ibeacons 基站模拟

之前有这么个事情,见下面链接

http://learn.adafruit.com/pibeacon-ibeacon-with-a-raspberry-pi/adding-ibeacon-data
其实就是在linux上是用usb蓝牙。装一些软件即可。
下面是使用到的三条命令:

打开BLE广播公告

sudo hciconfig hci0 leadv 3

关闭iBeacon公告

sudo hciconfig hci0 noleadv

广播数据
sudo tools/hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 00 00 00 00 C8 00

下面就广播数据进行分析。先上图。来自蓝牙spec
Ibeacons1.jpg
Ibeacons2.jpg

1E– length
FF– manufacturer
4c 00 – Apple, Inc
02 – SERVICE 
15 – SERVICE SOLICITATION
E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 – UUID (16 bytes) 
00 00 – major (2 bytes) 
00 00 – minor (2 bytes) 
C8 – tx power (1 byte) 
00 – status

基站其实就是0.2-1s间隔的发送广播,附件的蓝牙设备就能接受到。

下面再看看距离计算
Ibeacons3.jpg

关键代码:

// rssi – from Android’s BLE API 
// txPower – read from scan data byte array – see previous slides 
double ratio = (rssi *1.0) / txPower; 
double exponentMultiplier = 1.5; 
double multiplier = 12.0; 
double distanceInMeters = Math.pow(multiplier, ratio*exponentMultiplier)/Math.pow(multiplier, exponentMultiplier);

android ble api:

// Device scan callback. private BluetoothAdapter.LeScanCallback mLeScanCallback 
 = new BluetoothAdapter.LeScanCallback() { 
         @Override 
          public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
              // do something 
          } 
   }; 
Parameters 
device Identifies the remote device 
rssi The RSSI value for the remote device as reported by the Bluetooth hardware. 0 if no RSSI value is available. 
scanRecord The content of the advertisement record offered by the remote device.
https://www.bluetooth.org/en-us/specification/assigned-numbers

dBm是一个考征功率绝对值的值,计算公式为:10lgP(功率值/1mw)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值