douglasjunior / react-native-easybluetooth-classic

⚛ A Library for easy implementation of Serial Bluetooth Classic on React Native (Android Only).
https://www.npmjs.com/package/easy-bluetooth-classic
MIT License
43 stars 7 forks source link

How to read data? #28

Open bchaves2604 opened 5 years ago

bchaves2604 commented 5 years ago

I have the write and read methods and it seems to work as #expected.

EasyBluetooth.writeln("Works in React Native!") .then(() => { console.log("Writing...") }) .catch((ex) => { console.warn(ex); })

But I want to retrieve data from the device which is and OBD II, any ideas?

douglasjunior commented 5 years ago

You need to use the onDataReadListener.

bchaves2604 commented 5 years ago

I have it but when I log data it shows in the console "Works in React Native!" and what I actually want to do is receive something form the device

onDataRead(data) { console.log("onDataRead", data); }

componentWillMount() { this.onDeviceFoundEvent = EasyBluetooth.addOnDeviceFoundListener(this.onDeviceFound.bind(this)); this.onStatusChangeEvent = EasyBluetooth.addOnStatusChangeListener(this.onStatusChange.bind(this)); this.onDataReadEvent = EasyBluetooth.addOnDataReadListener(this.onDataRead.bind(this)); this.onDeviceNameEvent = EasyBluetooth.addOnDeviceNameListener(this.onDeviceName.bind(this)); }