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

Receiving messages from bluetooth device #125

Open
ramacha7 opened this issue Feb 25, 2021 · 1 comment
Open

Receiving messages from bluetooth device #125

ramacha7 opened this issue Feb 25, 2021 · 1 comment

Comments

@ramacha7
Copy link

ramacha7 commented Feb 25, 2021

I wanted to know how I could receive a message from a Bluetooth device. Currently I am using a Bluetooth module that can be used to communicate between a microcontroller and an App I have created. I wanted to test sending a message from the microcontroller to the app. I was wondering how I could receive the message? I have seen in the RCTBluetoothSerialModule.java file you can read with events like BluetoothSerial.on("read"). I was wondering if there were any examples I could use to figure out how to actually implement reading data from a device

@akshay1788
Copy link

akshay1788 commented Mar 30, 2021

If 'msg' is your state that is going to hold received data, then add these lines in your UNSAFE_componentWillMount() -

BluetoothSerial.withDelimiter('\n').then(() => {
Promise.all([
BluetoothSerial.isEnabled(),
BluetoothSerial.list(),
]).then(values => {
const [isEnabled, devices] = values;
this.setState({ devices });
});
BluetoothSerial.on('read', data => {
this.setState({msg: data.data})
});
});

Make sure you use correct delimiter while sending data from microcontroller.

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

2 participants