Open esutton opened 8 years ago
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
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.
@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
I'm on hold right now. I will know more next week.
On Sep 9, 2016 2:18 PM, "Jakub" notifications@github.com 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 https://github.com/rusel1989/react-native-bluetooth-serial/issues/2#issuecomment-246012233, or mute the thread https://github.com/notifications/unsubscribe-auth/AAElJoGJ8OsVVD0kwJb4n6L_yYSqUkUDks5qobEJgaJpZM4Jdxkq .
@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
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 notifications@github.com 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 https://github.com/rusel1989/react-native-bluetooth-serial/issues/2#issuecomment-246024667, or mute the thread https://github.com/notifications/unsubscribe-auth/AAElJm6Gterx9QAXz7Qm5ssY65S_8EIFks5qobwggaJpZM4Jdxkq .
@jcteague i need to do that as well. Did you use this library or developed something your own?
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 notifications@github.com 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 https://github.com/rusel1989/react-native-bluetooth-serial/issues/2#issuecomment-247642138, or mute the thread https://github.com/notifications/unsubscribe-auth/AAElJuyVMGseGSATuexzvXh9YJkVAEvOks5qqsBPgaJpZM4Jdxkq .
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.
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?
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.
@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 ...
@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?
@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
.
@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?
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).
@Searingfang - Ah ha! That makes sense. Great work! I'll try that ASAP.
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?
@storerjeremy It does work. I did what @Searingfang said to do and it worked without issue.
@jlucier Awesome, thanks for the confirmation it works. I'll give it a shot. Cheers
@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?
@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.
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
@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
@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)
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); }) })
Any updates on doing this without setInterval
would be sweet
anyone have subscribe function example ? please share. tks!
@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.
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
Any update? BluetoothSerial.withDelmiter(...
doesn't seem to work
I want to connect to a Bluetooth Classic SPP device ( not an Arduino device ).
Use Case1:
Use Case2:
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.