Bluetooth
complete
Adrian Carolli
Similar to the API provided by https://github.com/Polidea/react-native-ble-plx
I work on a bluetooth connected medical device and have been using that library to do most of the bluetooth stuff. However, you must detach the expo app to get it working and the setup is non-trivial. It would be nice to have a bluetooth API built into the expo SDK.
Evan Bacon
complete
Today, we are pleased to announce that with the arrival of Expo SDK 42, you can now create custom development clients in the cloud using EAS Build, or locally with the new Expo run commands.
The upstream config plugin for
react-native-ble-plx
is still waiting to be merged. In the meantime, users can install an out-of-tree plugin @config-plugins/react-native-ble-plx (think of this like @types/*
for packages that don’t have TypeScript).You can try it out today:
- Create a new project: expo init
- Install the packages: expo add react-native-ble-plx @config-plugins/react-native-ble-plx expo-dev-client(can also use npm or yarn)
- Add @config-plugins/react-native-ble-plxto theexpo.pluginsarray in yourapp.json.
Build the native app:
- In the cloud with eas build -p all --profile development(expo build does not support custom builds)
- Or locally with expo run:ios -dandexpo run:android -d(-denables connected device selection, BLE doesn’t work on simulators).
These custom clients can be shared across teams, and even reused across projects (just like Expo Go).
To be clear,
react-native-ble-plx
has not
been added to the Expo Go app that you download from the App Store or Google Play Store. For now, this is the closest we can get to making BLE as easy to use as the rest of the Expo SDK.We still consider this feature to be completed because users can now:
- Create a custom client app without needing to write any native code.
- Build the iOS project without having access to an Apple computer.
We hope you enjoy, and we have big plans to continue improving this workflow going forward!
Victor Rodrigues
I look forward to this new library fully managed by the expo in 2024. A technology as old and widely used as bluetooth should have been available for a long time, thank you.
S
Spencer Harrison
Does anyone know using the ble-plx library, if there is a way to send wifi crediential via ble to provision a device?
orome
Evan Bacon I'm a bit confused about the current status of all this and am wondering what's currently involved in getting Bluetooth working in my Expo project (and whether, perhaps with a Bluetooth emulator like
react-native-blemulator
I can get around having to leave Expo Go / iOS Simulator behind).João Mello Ferrari
orome: So am I. Would really appreciate an update on that!
Wodin
João Mello Ferrari: Yes, you should be able to add Bluetooth support to your app. Check the thread on the forums that orome linked to above. But apparently,
react-native-blemulator
doesn't work.R
Raamiz Abbasi
Any update on this in terms of improving the workflow and making this an Expo API that we can just install without having to use EAS build?
Y
Yuri Mosh
App crashes on Android when enabling
Debug Remote JS
. Anyone knows if there is a fix for that?
Y
Yuri Mosh
Has anyone tried building with
expo run:ios
on Mac? I am getting an error value of optional type 'CBService?' must be unwrapped to a value of type 'CBService'
The project is fresh new, created by instructions of Evan Bacon's post.
expo run:android
works fine.Does anyone know what is wrong?
M
Muneeb Ahmed
Yuri Mosh: Have you found the solution for this?
Y
Yuri Mosh
Muneeb Ahmed: in
package.json
try to add react-native-ble-plx
like so:"react-native-ble-plx": "https://github.com/below/react-native-ble-plx"
.M
Muneeb Ahmed
Yuri Mosh: Thank you so much. I have solved this problem by updating the react-native-ble-plx package from 2.0.2 to 2.0.3 :)
Y
Yuri Mosh
Muneeb Ahmed: great! That's even better :)
I will do the same.
Evan Bacon
complete
Today, we are pleased to announce that with the arrival of Expo SDK 42, you can now create custom development clients in the cloud using EAS Build, or locally with the new Expo run commands.
The upstream config plugin for
react-native-ble-plx
is still waiting to be merged. In the meantime, users can install an out-of-tree plugin @config-plugins/react-native-ble-plx (think of this like @types/*
for packages that don’t have TypeScript).You can try it out today:
- Create a new project: expo init
- Install the packages: expo add react-native-ble-plx @config-plugins/react-native-ble-plx expo-dev-client(can also use npm or yarn)
- Add @config-plugins/react-native-ble-plxto theexpo.pluginsarray in yourapp.json.
Build the native app:
- In the cloud with eas build -p all --profile development(expo build does not support custom builds)
- Or locally with expo run:ios -dandexpo run:android -d(-denables connected device selection, BLE doesn’t work on simulators).
These custom clients can be shared across teams, and even reused across projects (just like Expo Go).
To be clear,
react-native-ble-plx
has not
been added to the Expo Go app that you download from the App Store or Google Play Store. For now, this is the closest we can get to making BLE as easy to use as the rest of the Expo SDK.We still consider this feature to be completed because users can now:
- Create a custom client app without needing to write any native code.
- Build the iOS project without having access to an Apple computer.
We hope you enjoy, and we have big plans to continue improving this workflow going forward!
Peter Elmered
Evan Bacon: Awesome! Thanks a lot!
Jof Arnold
Evan Bacon: Thank you all once again!
Taylor Moss
Evan Bacon: This isn't the feature we asked for, but it might be even better.
Preston Chaplin
Evan Bacon: trying to open on my usb-connected iphone X. expo run:ios -d does not list my usb-connected phone in the device list and QR Code scan finds no usable data. Any thoughts? Thanks very much for your work on this!
*Update: I solved my issue by updating xcode to 12.5.1 and restarting all devices. After opening xcode with my phone connected, xcode prepared my phone for development. 'expo run:ios -d' now finds my phone as expected. Apologies for the false alarm. Hope this helps someone else.
Evan Bacon
Preston Chaplin: please open an issue on expo-CLI with more info regarding your OS. We rely on Xcode tools to find connected devices.
B
Brett
Evan Bacon: Awesome, is there a plan in the future to add this to Expo Go app?
Wodin
Brett: I don't speak for Expo, but from what they have said before I don't believe so, because it would bloat the Expo Go app, even if you didn't want Bluetooth functionality. However, there are a couple of options:
* You can technically still use the Expo Go app, as long as you don't call any of the Bluetooth stuff when the app is running in development mode. i.e. you can still use Expo Go to test the non-bluetooth parts of the app. https://docs.expo.dev/bare/using-expo-client/
* Alternatively you can use a custom dev client, which is basically like Expo Go that's customised to include your dependencies, including things like Bluetooth that rely on native code. This requires EAS Build. You can build locally on your machine for free, <strike>or make use of their build service if you subscribe to the priority plan. (They have also said they plan to have a free tier available in future.)</strike>
EDIT: The free tier has been available for a few months already :)
Tim Bogaert
Make sure you also add the right permissions to your android to make this work.
{
"expo": {
"android": {
"permissions": [
"android.permission.BLUETOOTH",
"android.permission.BLUETOOTH_ADMIN",
"android.permission.BLUETOOTH_SCAN",
"android.permission.BLUETOOTH_CONNECT",
"android.permission.ACCESS_COARSE_LOCATION",
"android.permission.ACCESS_FINE_LOCATION"
]
}
"plugins": ["@config-plugins/react-native-ble-plx"]
}
}
Ruben Marques
Tim Bogaert: I can initialize the bluetooth manager with a custom expo client and open the app with success on my android device, but despite adding all those permissions, nothing is printed after calling this function:
scanAndConnect = () => {
_BleManager.startDeviceScan(null, null, (error, device) => {
if (error) {
// Handle error (scanning will be stopped automatically)
return
}
// Check if it is a device you are looking for based on advertisement data
// or other criteria.
if (device.name === 'TI BLE Sensor Tag' ||
device.name === 'SensorTag') {
// Stop scanning as it's not necessary if you are scanning for one device.
_BleManager.stopDeviceScan();
// Proceed with connection.
}
});
}
I added a console.log(error) below // Handle error (scanning will be stopped automatically) and it prints:
Device is not authorized to use BluetoothLE
Little help?
Wodin
Ruben Marques: The
permissions
array is a list of the permissions your app wants to use, but you often still need to ask the user to grant the permission. The list here says that you need to prompt for BLUETOOTH_CONNECT
, BLUETOOTH_SCAN
and BLUETOOTH_ADVERTISE
permissions:As far as I know there's no built-in functionality to do this in the Expo SDK, but you can use
PermissionsAndroid
to do it. See the example on the above page.There's a notice at the top of the page implying you can't use it with Expo, but it's out of date. It should work fine as long as you're building with EAS Build, which you are doing.
Tim Bogaert
Ruben Marques: As Michael said you'll need to ask permissions on the Android platform first.
if (Platform.OS === "android") {
console.log(`Android...making sure we have permission`);
let perm = PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION;
if (platformApiLevel !== null && platformApiLevel <= 28) {
perm = PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION;
}
const granted = await PermissionsAndroid.request(perm);
if (granted === "denied") {
console.log("denied");
return false;
}
await requestMultiple([
PERMISSIONS.ANDROID.BLUETOOTH_SCAN,
PERMISSIONS.ANDROID.BLUETOOTH_CONNECT,
]);
} else if (Platform.OS === "web") {
return false;
}
console.log("permissions ok");
return true;
Evan Bacon
in progress
Colin Grant
When will the Bluetooth feature be added to Expo???
Ivan Lukianchuk
yes, when?
Peter Elmered
Ivan Lukianchuk: NOW!!!
Evan Bacon
Update: I've opened a PR to add a prebuild config plugin to
react-native-ble-plx
. When merged, users will be able to add the package to Expo projects built on EAS build, or locally with expo run:ios
and expo run:android
(i.e. after running expo prebuild
to sync the plugin with the native project). We're also still working on the Expo dev client project, which will utilize this proposed config plugin to create a custom dev app that has BLE support.
Carlos Barilatti
Evan Bacon: The prebuild config plugin was merged in this PR.
Load More
→