Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is polling required to receive data? #2

Open
esutton opened this issue Aug 5, 2016 · 31 comments
Open

Is polling required to receive data? #2

esutton opened this issue Aug 5, 2016 · 31 comments

Comments

@esutton
Copy link

esutton commented Aug 5, 2016

I want to connect to a Bluetooth Classic SPP device ( not an Arduino device ).

Use Case1:

  1. Send a command to device from Android.
  2. Process response from device when it is received.

Use Case2:

  1. Connect to an external Bluetooth GPS.
  2. GPS constantly streams NMEA text data
  3. Receive and process NMEA text data as it arrives and update location information.

Is there an API event or something that can be used to asynchronously handle data reception from the Bluetooth device?

Thanks for sharing your work. Any advice is appreciated.

@rusel1989
Copy link
Owner

Hey,
Both use cases will need some fixes/updates ... I just came back from vacation so i will start working on it ... but you know Pull Requests are welcome

@jcteague
Copy link

jcteague commented Aug 24, 2016

I'm needing this functionality too. I'm checking to see if the product owners want me to contribute to this project to make it work. If they do, do you have general idea of the work. Feel free to dm me if that's easier. P.S. I'm currently targeting Android.

@rusel1989
Copy link
Owner

@jcteague how does it look ? I currently have some free time so if you are not going to do it, i will start working on it

@jcteague
Copy link

jcteague commented Sep 9, 2016

I'm on hold right now. I will know more next week.

On Sep 9, 2016 2:18 PM, "Jakub" [email protected] wrote:

@jcteague https://github.com/jcteague how does it look ? I currently
have some free time so if you are not going to do it, i will start working
on it


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#2 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAElJoGJ8OsVVD0kwJb4n6L_yYSqUkUDks5qobEJgaJpZM4Jdxkq
.

@rusel1989
Copy link
Owner

@jcteague okay so i will start working on it, i just checked it and it seems that there shoudn't be much work on making it work

@jcteague
Copy link

jcteague commented Sep 9, 2016

rgr. I'll check in with you next week and see if there is anything I can
do to help.

FYI, my use case. I'm connecting to a bluetooth device connected a
vehicle. I can send an $AT command that will respond with info about the
vehicle (gps, rpms, etc..)

On Fri, Sep 9, 2016 at 3:05 PM, Jakub [email protected] wrote:

@jcteague https://github.com/jcteague okay so i will start working on
it, i just checked it and it seems that there shoudn't be much work on
making it work


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#2 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAElJm6Gterx9QAXz7Qm5ssY65S_8EIFks5qobwggaJpZM4Jdxkq
.

@jcrjaci
Copy link

jcrjaci commented Sep 16, 2016

@jcteague i need to do that as well. Did you use this library or developed something your own?

@jcteague
Copy link

we've punted on this for now, focusing on other requirements. We will need
to address it at some point.

On Fri, Sep 16, 2016 at 11:14 AM, jcrjaci [email protected] wrote:

@jcteague https://github.com/jcteague i need to do that as well. Did
you use this library or developed something your own?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#2 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAElJuyVMGseGSATuexzvXh9YJkVAEvOks5qqsBPgaJpZM4Jdxkq
.

@arvindpdmn
Copy link

The BTSerial API is documented here: https://github.com/derektu/react-native-bluetooth-serial
This may help in reading data on app when received from device. I think setDataAvailableCallback() may help.

@timscott
Copy link

timscott commented Dec 6, 2016

I'm taking over for @jcteague. Any progress on this?

By the way, I can't find a way to receive data from the connected device through polling or any other means. When I write, the resolved response is true which I'm guessing means the write succeeded; it's not a response from the device.

I guessing I will need to extend this package to implement at least the read function and perhaps subscribe. Is that correct?

@timscott
Copy link

timscott commented Dec 6, 2016

After some digging I have discovered that read and subscribe (and many other functions) are already implemented. They are just not documented nor used in the sample app.

In regards to the original question, it would appear that subscribe does the job. However, I have not been able to test that yet.

@rusel1989
Copy link
Owner

@timscott yep you're right, i didn't test these, so i don't know if they're working correctly ... I don't have much time lately ...

@jlucier
Copy link

jlucier commented Jan 9, 2017

@timscott @rusel1989
I'm trying to do read/write operations similar to what has been discussed here. Any update on whether or not read and subscribe are functional?

@timscott
Copy link

timscott commented Jan 10, 2017

@jlucier - I've got read working. Realize that read will read what's written which might not be everything you want. If you need a request-response type implementation, as I do, you will need to read into a buffer (I just append to a string) in a tight synchronous loop until you reach a delimiter.

subscribe does not work for me at all. It's only ever called in response to a successful connect, returning true.

@jlucier
Copy link

jlucier commented Jan 10, 2017

@timscott
Sounds good. I was expecting to have to buffer the messages like that. Is read working on the most recent release (the version installed via npm) or something else?

@Searingfang
Copy link

Searingfang commented Jan 21, 2017

Subscribe does appear to work. You have to call Bluetooth.subscribe(delimiter).then(whateverfunction). That promise will always just return true but to get the data you need to make a listener with Bluetooth.on('data', dataHandler).

@timscott
Copy link

@Searingfang - Ah ha! That makes sense. Great work! I'll try that ASAP.

@storerjeremy
Copy link

It seems I am also working on something similar @timscott Did you manage to get subscribe working? It would be awesome if someone could update the example app to show how to use subscribe?

@jlucier
Copy link

jlucier commented Feb 10, 2017

@storerjeremy It does work. I did what @Searingfang said to do and it worked without issue.

@storerjeremy
Copy link

@jlucier Awesome, thanks for the confirmation it works. I'll give it a shot. Cheers

@storerjeremy
Copy link

@jlucier @Searingfang I tried using BluetoothSerial.subscribe('\n').then(whateverfunction) and BluetoothSerial.on('data', dataHandler) in the example app, however when the subscribe method is called it brings up an error "TypeError: _reactNativeBluetoothSerial2.default.subscribe is not a function". Any idea whats going on?

@Searingfang
Copy link

@storerjeremy Based on the package.json in the example app it uses the version of the bluetooth serial library on github. This is actually a different version than you would get from npm install. The version on github doesn't have the subscribe feature for some reason.

So probably all you have to do is change the package.json dependancy for react-native-bluetooth-serial from "file:../" to "^0.1.6". If that doesn't work make a small app from scratch. Cards on the table, I wasn't able to get the example working when I first tried.

@jorge627
Copy link

jorge627 commented Apr 6, 2017

Hi
I want confirm that with subscribe it works, but I have a question, Do you know what is the limit time between data for receive it ?, I mean if my app is paired with a bluetooth device that is constantly sending data, what is the maximum frequency to send data from device to the app and obviously that the app can read each data properly ?, for example if the bluetooth device sends data each 10ms the app is in capacity to read each data properly ?

Thanks in advance

@pewh
Copy link

pewh commented Apr 8, 2017

@Searingfang I'm trying to use subscribe, but I don't have any idea how to send command. What I'm trying is: after connect to device, send request 'ATI' like this. Thanks

@Searingfang
Copy link

@pewh sending a command uses the write command. What you receive is dependent on the device. If you are trying to use subscribe then you have to know the device is delimiting its messages with something. For instance mine uses a newline \r\n. So if you subscribe('\r\n') then whenever you get a newline from your device Bluetooth serial will dispatch a data event that you can handle with on('data', dataHandler)

@babyinthesky
Copy link

for the latest github version, 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);
})
})

@arrygoo
Copy link

arrygoo commented Oct 23, 2017

Any updates on doing this without setInterval would be sweet

@hungtm84
Copy link

anyone have subscribe function example ? please share.
tks!

@jorge627
Copy link

jorge627 commented Sep 10, 2019

@hungtm84 I created a small project with bluetooth using the subscribe function ( it also use redux ) you can check it here, it is still a work in progress but the bluetooth is working, may be it can help you.

https://github.com/jorge627/react-native-redux-bluetooth

@ichbinvinh
Copy link

for the latest github version, 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);
})
})

Hi @babyinthesky ,

i placed your code in componentWillMount() but no events was catched when my scanner read barcode.

BluetoothSerial.withDelimiter('\r\n').then(() => { // BluetoothSerial.on('read', (data) => { // Toast.showShortBottom('DATA FROM BLUETOOTH 2:'+JSON.stringify(data)) // }); // })

I use this version : "react-native-bluetooth-serial": "^1.0.0-rc1"

Thanks in advance

@WhaSukGO
Copy link

Any update? BluetoothSerial.withDelmiter(... doesn't seem to work

70mmy pushed a commit to 70mmy/react-native-bluetooth-serial that referenced this issue Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests