如何从离子安卓应用中的Mi Floral BLE传感器获取实时数据

时间:2017-06-16 05:48:43

标签: angularjs ionic-framework

我正在使用BLE cordova插件,我可以使用具有以下功能的设备ID连接到它后获得设备(Mi Floral传感器)

ble.connect(
        $stateParams.device_id,
        function(res){
            alert('Response '+JSON.stringify(res));
            $scope.response = JSON.stringify(res);
            //$state.go('device', { 'device_id': device_id });
        }
    );
gives below as response:

`{"characteristics":[{"characteristic":"2a00","service":"1800","properties":["Read"]},{"characteristic":"2a01","service":"1800","properties":["Read"]},{"characteristic":"2a02","service":"1800","properties":["Read","Write"]},{"characteristic":"2a04","service":"1800","properties":["Read"]},{"descriptors":[{"uuid":"2902"}],"characteristic":"2a05","service":"1801","properties":["Read","Indicate"]},{"descriptors":[{"uuid":"2902"}],"characteristic":"0001","service":"fe95","properties":["Read","Write","Notify"]},{"characteristic":"0002","service":"fe95","properties":["Read"]},{"characteristic":"0004","service":"fe95","properties":["Read","Notify"]},{"characteristic":"0007","service":"fe95","properties":["Write"]},{"characteristic":"0010","service":"fe95","properties":["Write"]},{"characteristic":"0013","service":"fe95","properties":["Read","Write"]},{"characteristic":"0014","service":"fe95","properties":["Read"]},{"descriptors":[{"uuid":"2902"}],"characteristic":"1001","service":"fe95","properties":["Notify"]},{"characteristic":"8082caa8-41a6-4021-91c6-56f9b954cc34","service":"fef5","properties":["Read","Write"]},{"characteristic":"724249f0-5ec3-4b5f-8804-42345af08651","service":"fef5","properties":["Read","Write"]},{"characteristic":"6c53db25-47a1-45fe-a022-7c92fb334fd4","service":"fef5","properties":["Read"]},{"characteristic":"9d84b9a3-000c-49d8-9183-855b673fda31","service":"fef5","properties":["Read","Write"]},{"characteristic":"457871e8-d516-4ca1-9116-57d0b17b9cb2","service":"fef5","properties":["Read","WriteWithoutResponse","Write"]},{"descriptors":[{"uuid":"2902"}],"characteristic":"5f78df94-798c-46f5-990a-b3eb6a065c88","service":"fef5","properties":["Read","Notify"]},{"characteristic":"1a00","service":"1204","properties":["Read","Write"]},{"descriptors":[{"uuid":"2902"}],"characteristic":"1a01","service":"1204","properties":["Read","Write","Notify"]},{"descriptors":[{"uuid":"1a02"}],"characteristic":"1a02","service":"1204","properties":["Read"]},{"characteristic":"1a11","service":"1206","properties":["Read"]},{"descriptors":[{"uuid":"2902"}],"characteristic":"1a10","service":"1206","properties":["Read","Write","Notify"]},{"descriptors":[{"uuid":"1a12"}],"characteristic":"1a12","service":"1206","properties":["Read"]}],"advertising":{},"id":"C4:7C:8D:63:81:E2","services":["1800","1801","fe95","fef5","1204","1206"],"rssi":-55,"name":"Flower care"}`

它必须显示温度,湿度,水分和肥力数据。 我正在使用以下功能来读取数据

ble.read(
        $stateParams.device_id,
        $scope.ReadData.service,
        $scope.ReadData.char
    ),
    function(response){
        $ionicLoading.hide();

        var data = String.fromCharCode.apply(null, new Uint8Array(response));
        //$scope.values = data;
        alert(JSON.stringify(data));
    }


but unable to get that. Can anyone tell how do this .

0 个答案:

没有答案