【问题标题】:How to get BLE services (i.e. Battery level, Temperatue) from cordova-plugin-ble-central?如何从 cordova-plugin-ble-central 获取 BLE 服务(即电池电量、温度)?
【发布时间】:2016-11-27 04:02:47
【问题描述】:

我在英特尔 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 通信”。请问有什么建议吗?

【问题讨论】:

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


    【解决方案1】:

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

    对于初学者来说,根据定义,信标不可连接,因此连接性将是一个额外的用例。信标是广播器,而不是外围设备。

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多