如何从cordova-plugin-ble-central获得BLE服务(即电池电量,温度)?

时间:2016-07-23 09:25:52

标签: android cordova bluetooth intel-xdk bluetooth-lowenergy

我在英特尔XDK中使用蓝牙低功耗(BLE)概念创建了一个应用程序,使用了cordova-plugin-ble-central插件来获取他们的信息。现在只得到deviceID,RSSI值。

我正在尝试使用cordova插件(https://github.com/don/cordova-plugin-ble-central)从Beacon设备获得电池电量,温度和一些相关服务。但我无法连接我的设备。

当我在设备中运行我的应用程序时,它返回"未找到外围设备ID"只要。我的代码是

 onConnect = function() {
            alert('onconnect start');
            // TODO check if we have the battery service
            // TODO check if the battery service can notify us
            //ble.startNotification(deviceId, battery.service,battery.level, app.onBatteryLevelChange, app.onError);
            batteryStateButton.dataset.deviceId = deviceId;
            disconnectButton.dataset.deviceId = deviceId;
            app.showDetailPage();
            alert('onconnect end');
        };    
  ble.connect(deviceId, onConnect, app.onError);

当我使用上面的代码时,没有得到“onconnect start'警报。 在我的插件代码中

 connect: function (device_id, success, failure) {
    alert(device_id);
    var successWrapper = function(peripheral) {
        alert('successWrapper');
        convertToNativeJS(peripheral);
        success(peripheral);
    };
    cordova.exec(successWrapper, failure, 'BLE', 'connect', [device_id]);
},

仅从插件获取设备ID警报。此外,我试图从我的手机配对设备,得到一些错误"无法与deviceid"进行通信。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您正在使用哪种信标设备?你知道设备是否实现了这些服务吗?

首先,根据定义,信标是不可连接的,因此连接将是一个额外的用例。信标是广播公司,而不是外围设备。

设备ID和RSSI是预期的,这是您从广告数据获得的,而不是从GATT服务获得的。

相关问题