无法弄清楚如何向蓝牙设备发送命令

时间:2019-11-07 15:03:42

标签: react-native bluetooth bluetooth-lowenergy

因此,我一直在努力实现从速卖通获得的蓝牙指纹读取器。我已经花了两天的时间进行操作,目前处于可以连接和发送内容的阶段。但是我不知道如果没有适当的UUID和服务怎么办。这是外围设备信息

{
    "characteristics":[
        {
            "properties":{
                "Read":"Read"
            },
            "characteristic":"2a00",
            "service":"1800"
        },
        {
            "properties":{
                "Read":"Read"
            },
            "characteristic":"2a01",
            "service":"1800"
        },
        {
            "properties":{
                "Read":"Read"
            },
            "characteristic":"2a04",
            "service":"1800"
        },
        {
            "properties":{
                "Read":"Read"
            },
            "characteristic":"2a29",
            "service":"180a"
        },
        {
            "properties":{
                "Read":"Read"
            },
            "characteristic":"2a24",
            "service":"180a"
        },
        {
            "properties":{
                "Read":"Read"
            },
            "characteristic":"2a25",
            "service":"180a"
        },
        {
            "properties":{
                "Read":"Read"
            },
            "characteristic":"2a27",
            "service":"180a"
        },
        {
            "properties":{
                "Read":"Read"
            },
            "characteristic":"2a26",
            "service":"180a"
        },
        {
            "properties":{
                "Read":"Read"
            },
            "characteristic":"2a28",
            "service":"180a"
        },
        {
            "properties":{
                "Read":"Read"
            },
            "characteristic":"2a23",
            "service":"180a"
        },
        {
            "properties":{
                "Read":"Read"
            },
            "characteristic":"2a2a",
            "service":"180a"
        },
        {
            "properties":{
                "Write":"Write",
                "Read":"Read"
            },
            "characteristic":"49535343-6daa-4d02-abf6-19569aca69fe",
            "service":"49535343-fe7d-4ae5-8fa9-9fafd205e455"
        },
        {
            "descriptors":[
                {
                    "value":null,
                    "uuid":"2902"
                }
            ],
            "properties":{
                "Notify":"Notify",
                "Write":"Write"
            },
            "characteristic":"49535343-aca3-481c-91ec-d85e28a60318",
            "service":"49535343-fe7d-4ae5-8fa9-9fafd205e455"
        },
        {
            "descriptors":[
                {
                    "value":null,
                    "uuid":"2902"
                }
            ],
            "properties":{
                "Indicate":"Indicate",
                "Notify":"Notify"
            },
            "characteristic":"fff1",
            "service":"fff0"
        },
        {
            "properties":{
                "Write":"Write",
                "WriteWithoutResponse":"WriteWithoutResponse"
            },
            "characteristic":"fff2",
            "service":"fff0"
        }
    ],
    "services":[
        {
            "uuid":"1800"
        },
        {
            "uuid":"180a"
        },
        {
            "uuid":"49535343-fe7d-4ae5-8fa9-9fafd205e455"
        },
        {
            "uuid":"fff0"
        }
    ],
    "advertising":{
        "txPowerLevel":2,
        "serviceData":{

        },
        "serviceUUIDs":[
            "fff0"
        ],
        "localName":"FGT19100003",
        "isConnectable":true,
        "manufacturerData":{
            "bytes":[
                2,
                1,
                2,
                12,
                9,
                70,
                71,
                84,
                49,
                57,
                49,
                48,
                48,
                48,
                48,
                51,
                3,
                3,
                240,
                255,
                2,
                10,
                2,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0
            ],
            "data":"AgECDAlGR1QxOTEwMDAwMwMD8P8CCgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
            "CDVType":"ArrayBuffer"
        }
    },
    "rssi":-48,
    "id":"88:1B:99:25:AD:54",
    "name":"FGT19100003"

但是我看到只有4个字符的特征。据我所知,它们的格式为XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX。我已经在JAVA中获得了一些源代码,如果有人想看一下,我可以上载(我安装了它,它可以扫描指纹并将其BitMatrix返回给我。)(src java项目:{{ 3}})

这是我在RN中使用的功能的代码。

    test(peripheral: { connected: any; id: string; }) {
        if (peripheral) {
            if (peripheral.connected) {
                BleManager.disconnect(peripheral.id);
            } else {
                BleManager.connect(peripheral.id).then(() => {
                    let peripherals = this.state.peripherals;
                    let p = peripherals.get(peripheral.id);
                    if (p) {
                        p.connected = true;
                        peripherals.set(peripheral.id, p);
                        this.setState({ peripherals });
                    }
                    console.log('Connected to ' + peripheral.id);


                    setTimeout(() => {
                        BleManager.retrieveServices(peripheral.id).then((peripheralInfo) => {
                            console.log(JSON.stringify(peripheralInfo))
                            var service = '49535343-6daa-4d02-abf6-19569aca69fe';
                            var crustCharacteristic = '49535343-fe7d-4ae5-8fa9-9fafd205e455';

                            setTimeout(() => {
                                BleManager.startNotification(peripheral.id, service, crustCharacteristic).then(() => {
                                    console.log('Started notification on ' + peripheral.id);
                                    setTimeout(() => {
                                        BleManager.write(peripheral.id, service, crustCharacteristic, [0]).then(() => {
                                            console.log('write succes');
                                        });

                                    }, 500);
                                }).catch((error) => {
                                    console.log('Notification error', error);
                                });
                            }, 200);
                        });

                    }, 900);
                }).catch((error) => {
                    console.log('Connection error', error);
                });
            }
        }
    }

有人有经验吗?我还得到一张表,该表指出我认为其中包含所有可能的命令(https://filebin.net/7jeo1o0lkgd8x2oy)。

1 个答案:

答案 0 :(得分:1)

仅具有16位UUID的

BLE服务和特征是Bluetooth SIG设置的标准服务。可以分别在herehere中找到它们。该列表中的大多数特性都是标准特性,我敢打赌唯一具有128位UUID(0x49535343-fe7d-4ae5-8fa9-9fafd205e455)的特性是指纹数据的自定义服务,即0xFFF0服务。它们每个都有一些带有指示/通知的特征,所以我想这些将具有数据。 0xFFF0不是标准的UUID,但通常在示例代码和实现示例中使用,但通常不应该在运输产品中使用,但它具有与其他产品相同的正确性。我会尝试制作一个超大的数据缓冲区,并设置特征以在两种服务中进行通知/指示,然后进行指纹测试,然后看看您得到了什么。

或者,您可以使用Nordic(NRFconnect)或Cypress(CySmart)的手机BLE调试应用程序之一进行相同的测试,并通过使用手机执行相同的测试来了解正确的特性。< / p>