微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

react-native-ble-plx错误监视器CharacteristicForDevice

如何解决react-native-ble-plx错误监视器CharacteristicForDevice

我需要帮助解决此问题,我使用react-native-ble-plx连接accu-chex。要检查一些人的葡萄糖酸盐,我已经阅读了一些文档,但无助于解决此问题,并且仍然无法监视CharacteristicForDevice

我已经在两个版本中进行了测试:

"react-native": "0.63.3","react-native-ble-plx": "^2.0.1"

"react-native": "0.59.5","react-native-ble-plx": "^1.1.1",

但是我有这样的错误

error

这是我在app.js文件中的代码

    /**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow strict-local
 */

import React,{
    Component
} from 'react';
import {
    SafeAreaView,StyleSheet,BackHandler,View,Text,StatusBar,Button,} from 'react-native';

import { BleManager } from 'react-native-ble-plx';
import base64 from 'react-native-base64'

export default class App extends Component {
    constructor(props) {
        super(props)
        this.manager = new BleManager()
        this.state = {
            isLoading: true,info: "",values: {}
        };
        this.prefixUUID = "cAHXIQABAAE="
        this.suffixUUID = "00001808-0000-1000-8000-00805f9b34fb"
        this.sensors = {
            0: "Temperature",1: "Accelerometer",2: "Humidity",3: "Magnetometer",4: "Barometer",5: "gyroscope"
        }

        this.scanAndConnect = this.scanAndConnect.bind(this)
    };

    componentDidMount() {
        this.manager = new BleManager()
        BackHandler.addEventListener('hardwareBackPress',this.handleBackButton);
        this.scanAndConnect()
    };

    componentwillUnmount() {
        BackHandler.removeEventListener('hardwareBackPress',this.handleBackButton);
    };

    serviceUUID(num) {
        return this.prefixUUID + num + "0" + this.suffixUUID
    }

    notifyUUID(num) {
        return this.prefixUUID + num + "1" + this.suffixUUID
    }

    writeUUID(num) {
        return this.prefixUUID + num + "2" + this.suffixUUID
    }

    info(message) {
        this.setState({ info: message })
    }

    updateValue(key,value) {
        this.setState({ values: { ...this.state.values,[key]: value } })
    }

    scanAndConnect() {
        this.manager.startDeviceScan(null,null,(error,device) => {
                this.info("Scanning...")
                console.log(device)

                if (error) {
                    this.error(error.message)
                    return
                }

                if (device.name === 'meter+00629446') {
                    this.info("Connecting to TI Sensor")
                    this.manager.stopDeviceScan()
                    this.manager.connectToDevice(device.id)
                        .then((device) => {
                            this.info("discovering services and characteristics")
                            return this.manager.discoverAllServicesAndcharacteristicsForDevice(device.id)
                        })
                        .then((device) => {
                            console.log(`connected ${device.id} ${device.name} mtu:${device.mtu}`);
                            device.cancelConnection()
                            this.info("Setting notifications")
                            return this.setupNotifications(device)
                        })
                        .then(() => {
                            this.info("Listening...")
                        },(error) => {
                            console.log(device)
                            this.error(error.message)
                        })
                }
            });
    }

    setupNotifications(device) {
        this.manager.monitorCharacteristicForDevice(device.id,'00001808-0000-1000-8000-00805f9b34fb','00002A18-0000-1000-8000-00805f9b34fb',characteristic) => {
            console.log("characteristic",characteristic)
            if (error) {
                this.error(error.message)
                return
            }
            // this.updateValue(characteristic.uuid,characteristic.value)
        })

        this.manager.writeCharacteristicWithResponseForDevice(device.id,'00002A52-0000-1000-8000-00805f9b34fb',base64.decode('0401'),see) => {
            if (error) {
                this.error(error.message)
                return
            }
            console.log(see.uuid,see)
        })
    }

    render() {
        return (
            <SafeAreaView style={{ flex: 1,backgroundColor: 'white' }}>
                <View style={{ padding: 10 }}>
                    <Text>{this.state.info}</Text>
                    {Object.keys(this.sensors).map((key) => {
                        return <Text key={key}>
                            {this.sensors[key] + ": " + (this.state.values[this.notifyUUID(key)] || "-")}
                        </Text>
                    })}
                    
                </View>
            </SafeAreaView>
        );
    }
}

我已经阅读了一些文档来解决此问题,但仍然无法正常工作。请帮忙... 谢谢:)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?