简体   繁体   English

BLE on tinyB java 特性没有通知

[英]BLE on tinyB java characteristic has no notify

i`m trying to connect simple device(AB Shutter3) to java application on PC, but get no notification till connect.我正在尝试将简单设备 (AB Shutter3) 连接到 PC 上的 java 应用程序,但在连接之前没有收到通知。 For test try测试尝试

BluetoothDevice currentDev = (BluetoothDevice) container.getDevice();

        currentDev.setTrusted(true);
        if(!currentDev.getConnected()) {
            currentDev.connect();
        }
        logger.info(currentDev.getName());

then get ALL services, descriptors and try to enable notifications like:然后获取所有服务、描述符并尝试启用通知,例如:

    public void findServiceAndCharacteristic(BlueToothDeviceContainer container, String serviceUid){
    for (BluetoothGattService service : container.getGattServices()) {
            if(service.getUUID().equals(CUSTOM_SHUTTER_SERVICE_2.value) ||
                    service.getUUID().equals(CUSTOM_SHUTTER_SERVICE.value) ||
                    service.getUUID().equals(GENERAL_DEVICE_INFORMATION.value)){
                List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
                for(BluetoothGattCharacteristic ch : characteristics){
                    logger.info(ch.getUUID());
                    try {

                        List<BluetoothGattDescriptor> descrs = ch.getDescriptors();
                        for(BluetoothGattDescriptor ds : descrs){
                            ds.enableValueNotifications(new BluetoothNotification<byte[]>() {
                                @Override
                                public void run(byte[] bytes) {
                                    logger.info(ds.getUUID() + "getted");
                                    logger.info("BUTTON WAS PUSHED!!!");
                                }
                            });
                        }
                    } catch (BluetoothException ex){
                        logger.warn(ch.getUUID() + " does not work.");
                    }
                    try{
                        BluetoothNotification btnm = new BluetoothNotification<byte[]>() {
                            @Override
                            public void run(byte[] bytes) {
                                logger.info(ch.getUUID() + "getted CH");
                                logger.info("BUTTON WAS PUSHED!!!");

                            }
                        };
                        ch.enableValueNotifications(btnm);
                } catch (BluetoothException ex){
                    logger.warn(ch.getUUID() + " does not work.");
                }
                    
                    }

but run method does not work.但运行方法不起作用。 What am i doing wrong, does anybody knows?我做错了什么,有人知道吗?

Problem was not at library.问题不在图书馆。 Problem at HID characteristic. HID 特性的问题。 It was not found on device, so there was no notifications from it.在设备上找不到它,因此没有来自它的通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM