react-native-bluetooth-serial icon indicating copy to clipboard operation
react-native-bluetooth-serial copied to clipboard

Listener for receiving data

Open happierco opened this issue 7 years ago • 9 comments

I need to read from a barcode scanner without using an input field. Is there a listener I can use?

happierco avatar Apr 24 '17 20:04 happierco

Hey @happierco , You can use BluetoothSerial.on('data', (data) => ...do something with data)

rusel1989 avatar Apr 25 '17 07:04 rusel1989

BluetoothSerial.on('data', (data) => { console.log(data); });

Can not receive data.

ibenben avatar May 05 '17 07:05 ibenben

Hao can I read the byte from device.I do not want the string result.

ibenben avatar May 05 '17 07:05 ibenben

I get the listener for receiving data working by the following way. Note that you have to replace the delimiter '\r\n' with the one upon your own case.

BluetoothSerial.withDelimiter('\r\n').then((res)=>{ console.log("delimiter setup",res); BluetoothSerial.on('read',(data)=>{ console.log('read',data); }) })

babyinthesky avatar Jun 19 '17 11:06 babyinthesky

I get the listener for receiving data working by the following way. Note that you have to replace the delimiter '\r\n' with the one upon your own case.

BluetoothSerial.withDelimiter('\r\n').then((res)=>{ console.log("delimiter setup",res); BluetoothSerial.on('read',(data)=>{ console.log('read',data); }) })

where should I put these codes?

goldfishinsky avatar Mar 04 '19 07:03 goldfishinsky

BluetoothSerial.withDelimiter('\r\n').then((res)=>{ console.log("delimiter setup",res); BluetoothSerial.on('read',(data)=>{ console.log('read',data); })

I have same question, did @goldfishinsky solve this problem ?

hungtm84 avatar Sep 10 '19 03:09 hungtm84

I get the listener for receiving data working by the following way. Note that you have to replace the delimiter '\r\n' with the one upon your own case.

BluetoothSerial.withDelimiter('\r\n').then((res)=>{ console.log("delimiter setup",res); BluetoothSerial.on('read',(data)=>{ console.log('read',data); }) })

I know this issue is a little old but, Should we place on("read") listener in "withDelimiter" method

All I want actually, listening constantly for data from HC05 module to app. Only thing I can do is checking module manually with readFromDevice method.

yalcinozer avatar Oct 08 '20 13:10 yalcinozer

@yalcinozer Have been able to figure out how to do it. I actually have the same application goal. I need to constantly listen for data from a HC05 module.

ramacha7 avatar Feb 25 '21 01:02 ramacha7

@ramacha7 using delimiters is a must be. You also should call functions repeatedly to read data. If you have any option use "BLE" devices. At some point I just gave up checking if data received or not.

yalcinozer avatar Feb 25 '21 17:02 yalcinozer