之前有这么个事情,见下面链接
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
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间隔的发送广播,附件的蓝牙设备就能接受到。
关键代码: // 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)