AltBeacon 忽略了我的信标包的 pdu 类型

AltBeacon ignores pdu type of my beacon packages

我正在使用 AltBeacon 库来处理我的信标(由 Shenzhen Minew Technologies Co., Ltd. 提供)。 我使用以下

beaconManager.getBeaconParsers().add(new BeaconParser().
            setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));

设置布局。在我的 logcat 中,我看到 RSSI 值来自我的信标,例如:

06-21 01:50:27.091  13496-13507/com.example.tkobilov.minewtestapp D/BluetoothAdapter﹕ onScanResult() - Device=CD:A6:29:2F:08:26 RSSI=-73
06-21 01:50:27.503  13496-13508/com.example.tkobilov.minewtestapp D/BluetoothAdapter﹕ onScanResult() - Device=D3:EB:21:87:9D:7E RSSI=-58
06-21 01:50:27.508  13496-13582/com.example.tkobilov.minewtestapp D/BluetoothAdapter﹕ onScanResult() - Device=D3:EB:21:87:9D:7E RSSI=-59

然而在

protected Beacon fromScanData(byte[] bytesToProcess, int rssi, BluetoothDevice device, Beacon beacon) {

    BleAdvertisement advert = new BleAdvertisement(bytesToProcess);
    Pdu pduToParse = null;
    for (Pdu pdu: advert.getPdus()) {
        if (pdu.getType() == Pdu.GATT_SERVICE_UUID_PDU_TYPE ||
                pdu.getType() == Pdu.MANUFACTURER_DATA_PDU_TYPE) {
            pduToParse = pdu;
            if (LogManager.isVerboseLoggingEnabled()) {
                LogManager.d(TAG, "Processing pdu type %02X: %s with startIndex: %d, endIndex: %d", pdu.getType(), bytesToHex(bytesToProcess), pdu.getStartIndex(), pdu.getEndIndex());
            }
            break;
        }
        else {
            if (LogManager.isVerboseLoggingEnabled()) {
                LogManager.d(TAG, "Ignoring pdu type %02X", pdu.getType());
            }
        }

我每次都来"Ignoring pdu type..."。 我检查了 bytesToProcess 数组。每次它只有第一个和第二个非零值。其他值为零。 Minew 推荐的 BeaconCFG 应用程序可以毫无问题地找到这些信标,但我的项目需要 AltBeacon。这可能是什么原因?

我的LogCat输出:

D/BluetoothDevice﹕ mAddress: EE:74:8B:CA:DB:F1 D/BluetoothAdapter﹕ onScanResult() - Device=EE:74:8B:CA:DB:F1 RSSI=-52 D/CycledLeScannerForJellyBeanMr2﹕ got record D/BluetoothDevice﹕ mAddress: EE:74:8B:CA:DB:F1 D/BeaconParser﹕ Ignoring pdu type 01 D/BeaconParser﹕ Ignoring pdu type 0A D/BeaconParser﹕ No PDUs to process in this packet. D/BeaconParser﹕ No PDUs to process in this packet. D/BeaconParser﹕ Ignoring pdu type 0A D/BeaconParser﹕ Ignoring pdu type 01 D/BeaconParser﹕ No PDUs to process in this packet. D/BeaconParser﹕ No PDUs to process in this packet. D/BluetoothAdapter﹕ onScanResult() - Device=ED:EE:AD:02:1B:30 RSSI=-62 D/CycledLeScannerForJellyBeanMr2﹕ got record D/BluetoothDevice﹕ mAddress: ED:EE:AD:02:1B:30 D/BluetoothAdapter﹕ onScanResult() - Device=ED:EE:AD:02:1B:30 RSSI=-62 D/CycledLeScannerForJellyBeanMr2﹕ got record D/BluetoothDevice﹕ mAddress: ED:EE:AD:02:1B:30 D/BeaconParser﹕ Ignoring pdu type 01 D/BeaconParser﹕ No PDUs to process in this packet. D/BeaconParser﹕ Ignoring pdu type 01 D/BeaconParser﹕ No PDUs to process in this packet. D/BeaconParser﹕ Ignoring pdu type 0A D/BeaconParser﹕ No PDUs to process in this packet. D/BeaconParser﹕ Ignoring pdu type 0A D/BeaconParser﹕ No PDUs to process in this packet. D/CycledLeScanner﹕ Waiting to stop scan cycle for another 98 milliseconds D/CycledLeScanner﹕ Done with scan cycle D/BluetoothAdapter﹕ isEnabled D/CycledLeScanner﹕ stopping bluetooth le scan D/BluetoothAdapter﹕ stopLeScan() D/CycledLeScanner﹕ starting a new scan cycle D/BluetoothAdapter﹕ isEnabled D/CycledLeScanner﹕ starting a new bluetooth le scan D/BluetoothAdapter﹕ startLeScan(): null D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=1 D/CycledLeScanner﹕ Waiting to stop scan cycle for another 1100 milliseconds

我的 PDU 的内容

D/CycledLeScanner﹕ Waiting to stop scan cycle for another 1100 milliseconds D/CycledLeScanner﹕ Scan started D/BluetoothAdapter﹕ onScanResult() - Device=EE:74:8B:CA:DB:F1 RSSI=-63 D/CycledLeScannerForJellyBeanMr2﹕ got record D/BluetoothDevice﹕ mAddress: EE:74:8B:CA:DB:F1 D/BeaconParser﹕ Ignoring pdu type 01 D/BeaconParser﹕ No PDUs to process in this packet -- 02 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 seen D/BeaconParser﹕ Ignoring pdu type 01 D/BeaconParser﹕ No PDUs to process in this packet -- 02 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 seen D/BluetoothAdapter﹕ onScanResult() - Device=EE:74:8B:CA:DB:F1 RSSI=-63

从蓝牙 LE 信标读取标识符的主要方法有两种:

  1. Android Beacon Library 和类似的 SDK 通过查看低功耗蓝牙广告数据包来检测信标,而无需与信标设备建立低功耗蓝牙连接——这是检测蓝牙信标的标准机制一个应用程序。

  2. 像 iBeaconCFG 这样的配置应用程序通常会与设备建立蓝牙 LE 连接,以使用 GATT 读取和设置信标标识符和其他配置参数。这种配置机制是非标准的,实际上会在建立连接时停止发送信标。因此,这种检测信标的辅助方法不适合应用程序使用。它仅对信标的初始配置有用。

根据问题和评论中报告的信息,飞利浦 v387 Android 设备的蓝牙堆栈似乎存在问题,无法使用第一种机制检测到信标。 (它错误地报告它读取的广告数据包包含全零。)这意味着该设备将根本无法 运行 检测信标的应用程序。据报道,它与配置应用程序一起使用的事实可能意味着它可以成功建立 GATT 连接来配置信标。

飞利浦 v387 Android 设备不能用于检测通用应用程序中的信标。但是,它可以用于配置可使用 GATT 接口连接的信标。

最后,作为一种解决方法,我看到了一种检查 PDU 并在 adv 包错误的情况下使用真实 MAC、RSSI 和信标名称生成假信标对象的方法。在这种情况下,我不能使用 Major、Minor 和 TxPower,但可以使用 RSSI 和信标名称。