Using react-native-ble-plx to send data to a raspberry pi RFCOMM server

1.1k views Asked by At

My goal is to setup my Raspberry Pi 4 to be able to run scripts when a button is clicked in an app I am making with React Native. I need to be able to do it so that they can connect without wifi, which is why I have decided to use Bluetooth.

So far I have an RFCOMM server set up on the Pi, and have installed the react-native-ble-plx module to be able to handle bluetooth communications, but I'm not sure how to get React Native to connect to this server.

I'd really appreciate it if anyone can tell me how to connect them and send data to the Pi to get it to run terminal commands, and return the result.

1

There are 1 answers

0
ukBaz On BEST ANSWER

There are two types of Bluetooth that are not compatible with each other. RFCOMM and BLE will not work together.

On the Raspberry Pi you need to create a GATT server. RPi uses the BlueZ stack and they have an example in their source tree: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/example-gatt-server

You will also need to have an advertisement so that your phone can find the gatt server. There is also an example of that: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/example-advertisement

Another suggestion is not to try and develop both ends of the Bluetooth link at the same time as that is tricky. Use a generic BLE tool to check you have the server working correctly before you develop the react app.