React-Native with Expo and Bluetooth Low Energy for Beginners
ฝัง
- เผยแพร่เมื่อ 1 มิ.ย. 2024
- Finally! A tutorial on how to use Expo with Bluetooth Low Energy 🔥
Follow me on Twitter 🐦 / wa2goose
Subscribe to my Insta 📷 my handle is: dan.rnlab
Sample Project: github.com/friyiajr/BLESample...
Device:
* Android 13 Pixel 7
Also Tested On:
* Android 11 Moto G Play
* iOS 16 iPhone XR
=====================
Introduction 00:00
EAS Build Setup 01:56
Request Permissions 05:50
Device Scanning 10:37
Connect Device 12:23
Data Streaming 14:15
Disconnecting 17:32
Finished Product 18:44 - วิทยาศาสตร์และเทคโนโลยี
Looking to go deeper into IoT? Check out my video on connecting an Arduino Uno r4 to a web server
Connecting Arduino to the Internet - Fullstack Internet of Things ( IoT ) with Expo
th-cam.com/video/LEeJZCOS47I/w-d-xo.html
I watched your previous video, then I discover expo, I thought okay, maybe it's not supported, and now i find you again with a great video. Thank you very much! It helped me a lot with my final project at University
Happy to help 🙂
thanks you so much. I has found this cource for bluetooth low energy for a long time. It realy useful for me!
Perfect! Thanks for this video, this is exactly the use case I'd be interested in.
Happy to help! 😃
This was a life saver! Thank you.
In the requestPermissions method you return true in the else clause. Will it not be impossible to tell if an ios device has BLE permissions enabled or not then? I have used the onStateChange method from ble-plx library to check this but is there any better way?
Wonderful video. Ive been waiting for bluetooth with expo for some years now.
Happy you enjoyed it 🙂. Best of luck with your project!
H, Dan
I tired to connect and stream data from "O2Ring " which monitor heartrate,spo2,rtwave and pulse. but i am not able to get data. can you please help me out
hi
I have a question for you. When we close the app do we need to un-monitor the characteristic as well? if not, what will happen from hardware side. Will it keep sending the values on notification channel even the app is off?
Hello, thanks for this video !
I have a question, when i run the command npx expo run:android, i get this error:
Task :react-native-ble-plx:compileDebugJavaWithJavac FAILED
What went wrong:
Execution failed for task ':react-native-ble-plx:compileDebugJavaWithJavac'.
> Could not resolve all files for configuration ':react-native-ble-plx:androidJdkImage'.
> Failed to transform core-for-system-modules.jar to match attributes {artifactType=_internal_android_jdk_image, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for JdkImageTransform: C:\Users\K\AppData\Local\Android\Sdk\platforms\android-34\core-for-system-modules.jar.
> Error while executing process C:\Program Files\Java\jdk-21\bin\jlink.exe with arguments {--module-path C:\Users\K\.gradle\caches\transforms-3\6683fa48bcb440c054791c94c0688110\transformed\output\temp\jmod --add-modules java.base --output C:\Users\K\.gradle\caches\transforms-3\6683fa48bcb440c054791c94c0688110\transformed\output\jdkImage --disable-plugin system-modules}
Can you help me
Hi Dan, I have a question. Why you pass allDevices and connectToPeripheral function from useBLE() custom hook throught function components parameters (DeviceConnectionModal) instead of calling useBLE() in this function component? Can I call this custom hook anywhere?
I have this dubt because I have this use case and I want to use useBLE() in another function component and I'm getting null or undefined in everything data and functions.
Thanks in advance!
You can restructure it to work differently. Since allDevices happened to be in the state anyway I passed it in like that. You don’t need to do it that way.
Hey, Thanks for sharing.
I have a question. Once a device is subscribed with a service characteristics then after some time it is getting auto disconnect. Any clue why this is happening?
The error object is
{
"errorCode": 201,
"attErrorCode": null,
"iosErrorCode": 6,
"androidErrorCode": null,
"reason": "The connection has timed out unexpectedly.",
"deviceID": "6C2E6353-13CC-BD15-A46C-471BAA05F2DA",
"serviceUUID": null,
"characteristicUUID": null,
"descriptorUUID": null,
"internalMessage": null
}
Hi, i'm use "eas build --profile development --platform android" to prove it on my smartphone instead expo prebuild, that i understand serves the same purpose, but i have the exception of "Cannot read property 'createClient' of null" when BleManager() constructor is called, this could be due to use another method to build the app?
It sounds like possibly the config plugin isn’t run. Not sure why that would happen though
I keep getting build errors when running command "npx expo run:android". "BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 64".
I have double and triple checked that everything is installed and all the environment variables are set properly. Does anyone have any ideas or have seen this? Any help would be greatly appreciated.
Hi Dan! Does it have to be a eas-build or can it be a local build? I use the command `npx expo run:ios --devices` which allows me to run the app on my iPhone using the native code. Is this going to be a problem?
The local build should run no problem
Hi so I have a random question that kinda pertains to the video, So im looking to connect a bluetooth clicker to an app like you hit a button ( only one button) and it does something in the app. Is it the same process as the other videos you've done? Im new to react native and trying to figure this all out.
It’s certainly possible. It would depend on how you set up the clicker though. It would need to be an advertizer. My tutorials only deal with the client side
You are insane! Thank you very much.
Happy to help!
i'm a beginner to react and app dev but got a project to create a simple controller app to connect to raspberry pi through ssh, do you have a video or recommendation on how i can do it?
Hi Dan, thanks for the tutorial first of all! I found it only yesterday and it's already helped a lot, but I've been stuck just trying to build the application which seems impossible to me. Did you use an Android Studio emulator for this? I have been unable to get my emulator to work.
Hey, unfortunately simulators do not support Bluetooth at all. You need to use a physical Android or iPhone device.
Hi Dan, Thank you for the amazing tutorial. It is truly nice to have someone finally walk through how to make this work without ejecting from expo. I noticed there is no license specified in your Github project repository. Given that this is a tutorial, do we have permission to use your code as a foundation for our own projects?
Hey, no problem use it for whatever you want whether it’s a startup, personal project etc. Keep in mind though there is no warranty on this code and that I don’t guarantee it will work for medical applications or otherwise. It was meant to be a demo for a tutorial and nothing more.
@@DanRNLab Thank you so much, and again, outstanding work on the tutorial!
do we need to pay apple developer program ( 99$ ) to use ble on iphone? thanks you for answers all.
You don’t need to use EAS to build the app but I haven’t tried to do this without a developer account. I recommend asking this in the Expo discord
discord.com/invite/expo
Hi again! I hope you're well. I've been working a few weeks with the managed BLE + Expo project and need to automatically connect to the device when I open the app again, or even keep BLE connected and paired with the device. Do you have any idea how this could be possible with this tech stack that you use in the video?
I really appreciate your help, greetings!
Hey you can probably just store the device I’d in local storage and use it to reconnect every time the user reopens the app
I am facing with a problem but idk how to resolve It.
I have a service callback in my esp32 onConnect and onDisconnect and It works when I connect it and if I disconnect the Bluetooth from my phone but if I send the order from the library react-native-ble-plx It disconnects from the phone but onDisconnect from my esp32 does not trigger to advertice so if I Bluetooth scan again my esp32 does not show until I reboot.
Great video.
Hey Dan quick question, since @config-plugins/react-native-ble-plx itself sets up the plugin for us, do we still need to copy your plugin setup? Also @config-plugins/react-native-ble-plx itself is depreciated and it sets up everything itself. How does that change things?
I haven’t had time to test it myself but I have seen that there is an official plugin now. I recommend trying the updated official one first then falling back on what I use if it doesn’t work
Hi Dan, thank you for the video. I have some issues when I follow your old video. I use getServicesAndCharacteristics and monitorCharacteristicForService function and I use isDeviceConnected Function to make sure the Indicator device is connected. I want to get the weight value from the indicator device but the value return null. How can I do in this case? Thanks !!
Hey, unfortunately BLE devices all behave really differently. I think it’s best to consult your manual or Firmware engineer. In the past I’ve been in weird situations where some BLE devices require you to turn on Service streaming and things like that. Others require an extra step where you “unlock” the device through a challenge response protocol. That might be what’s happening in your case. The only real way to know is to get that information from the manufacturer.
Great video! 2 Questions
1. Was prebuild necessary since I assume npx expo run:android would run prebuild regardless
2. You can still build iOS Locally right? Thre should be no reason to use EAS Build if you have xcode setup
Yes you can run that command with the -device flag and build to any device you have hooked up to your machine
Hi Dan, I know I've asked you a lot of questions, but I have one last question left. I want to get the application I made as apk, but the apk I got from the "eas" page comes with an expo interface and works by communicating with a local server, that is, our terminal, but I want a pure apk directly.
Hey, it depends on your audience for this build. I recommend checking out the Expo documentation on this topic docs.expo.dev/build/introduction/
Hey Dan, Great Job!!!
I've extended my app to use your custom useBle hook across multiple components on multiple screens, and I have maybe a tricky question for you (or maybe it's more fundamental React):
I was building my first app with ble pxe library when I saw your useMemo approach (I was stuck on maintaining one instance of bleManager - THANK YOU), and it worked... until I added multiple components (particularly on different screens) calling APIs from the custom useBle hook... what seems to be happening is that each component (on its initial render) calls one of the APIs from the useBle custom hook, which seems to refresh/rerun/reinitialize the useBle custom hook (at least the initial time for each screen), which seems to (a) clear or (b) create an additional instance of bleManager (I"m not sure which one, but I'm thinking it reruns your useMemo, hence dropping the initial bleManager and replacing it with a new bleManger, possibly without properly closing the initial one, and losing the connection). As a specific example: I scan and auto-connect fine on the first screen (just like you did; everything including measurements work)... but I have a second screen (with a different component) that let's the user disconnect from that initially connected device, rescan and connect to another device manually... when I move to that second screen (note I'm already connected to a device), the app seems to recreate bleManager (or possibly create a second one; again, I'm not positive here), which causes the app to lose the connection to the device I was connected to (I have confirmed it loses connection as any action before I open the second screen works fine, and any action after I open the second screen gives me the error that the device is not connected). I wrote a workaround (basically uses isDeviceConnected to see if the device that my RTK state says is connected is in fact connected, and if not, it reconnects with connectToDevice), but that seems clunky and I'm guessing you might have a better way?
Note that I tried putting bleManager in my RTK state, which actually seems to work, but that too doesn't feel right (and I get nonSerializable errors from RTK, which I can suppress, but that doesn't seem right... I also tried serializing bleManager before putting it into my state to avoid the nonSerializable errors with JSON.stringify, then using JSON.parse to pull it back out, but I confirmed the result is not the same - maybe that's obvious, but it wasn't to me so I gave it a shot and wanted to let you know).
So, all that to ask as I'm sure others will run into this as well: any advice for creating a single, persistent bleManager that survives react native re-renders, multiple components calling useBle on multiple screens?
I don’t have access to your source code so I don’t really know what is going on. I think putting BLEmanager as a variable global to the app might be another approach you can try. Something like this: github.com/friyiajr/BluetoothLowEnergySample/blob/main/useBLE.tsx#L18
@@DanRNLab Thanks Dan, I think you're probably right on the approach (I've been so trained not to use globals I didn't think of that), but I don't see a global for bleManager in the example you provided... instead, it looks like the same way you called it before adding useMemo: const bleManager = new BleManager()... maybe I'm missing it?
I declare it outside the hook in that example and not inside the hook
Also interested in this, did you make any headway @msg144? I've been chasing down all sorts of rabbit holes with redux+saga etc, but wondering if it really needs to be that complex...
Hey Dan great video btw but I wanted to know that in order to build do we need Android studio like for sdk stuff configured on our system or just it expo will build it online?
If you want to run your builds locally you need the full setup. If not you can just use EAS
@@DanRNLab thank you
Hey Dan! Thanks for the tutorial! How exactly did you get your project running on your real Android device? I am trying to do this so I can test the Bluetooth functionality. It seems that Android Studio does not support Bluetooth.
Hey, so yes Android Simulators do. It support Bluetooth. You should just be able to plug in your phone and run the same commands I did. adb should detect your device
Hello Dan, I was able to establish a connection with my device using your video and successfully send and receive data in the "connectToDevice" section. However, it doesn't make sense to work in that section, so after making the necessary changes in the "startStreamingData" section, I made a few modifications to the "onHeartRateUpdate" section according to my needs, but I'm not receiving any data at all, and the program doesn't even pass through the "onHeartRateUpdate" section. Can you please help me? I'm very desperate. :(
Hey so there are a couple things to try here. First make sure you are calling subscribeToAllServicesAndCharacteristics before you try and stream any data. This is key nothing will work without it.
If you are already doing this the problem may be with the device. You may have to send it some signal to start streaming. I have no way of knowing what that would be though. You’d need to use your manual or contact the device manufacturer
@@DanRNLab Thank you for your response. Could it be because there is no service definition for a subscription process in my device's services? In other words, even if your code is actually working, there may not be such a definition for the service that is running in the background.
I haven’t had to work at the hardware side at all so I am not sure how to debug that part. I usually just get the information on what I need to do from the Firmware engineer and consume their data as a client.
I'm having difficulty running unit tests with React Native BLE Manager. Every time I try to execute the command 'yarn test,' it fails, and I can't find any relevant content on it either. Do you know how to do it?
I am not aware of any content on it. I think you would need to create a sophisticated mock for it unfortunately
Hey Dan thanks for this brotha. Just subscribed. If I am using an eeg headset how would I go about creating 5 different wave type values? I have done this in MAX and am trying to transfer it to this and make it an app. I really need some help at this point. ~ dnt
Great video! grats! i am having some issues when i am trying to deploy it, can u please tell me wich version of SDK and java are u using? It is necessary install gradle? thanks!
Hey you are right. To do this you need to install some native tooling to build locally. I recommend installing Android studio and any Java version 8 or above
@@DanRNLab Thanks! works using expo start --android because it was showing an error with the build, greetings from colombia and thanks again 👍
Hello Dan, I propose that you make an update by adding a local push notification when the hert rate rise above a certain value, for example 120bpm. The cool thing is that it could be done while the app is in the background, you could teach a lot about this topic that there is much more ignorance on the part of the community, at least I speak for myself.
I wait your answer!
I may do that for some other type of BLE application. It would be too dangerously close to do it with the Heart Rate Monitor since it’s getting close to a medical device at this point 😅. But with the iOS BLE Server simulator I created something with Real-time data should eventually be possible 🤔
Hi Dan, thanks for these videos, you help a lot! I need to use this in a project but I need to communicate with the device (asking things - using write()). In your case, for example, it would ask you what battery level your Heart Rate Device has, or make it beep to find the device.
I have looked at the documentation a bit but BLE is something very new for me, if you could confirm that it really is possible, you would help me a lot! Or even if you could make a quick video on how to do this.
Greetings, I appreciate you man!
th-cam.com/video/jeH2QmZ8T14/w-d-xo.html
In this video I do writes. It uses CLI and not Expo but the steps are very similar and should mostly translate. You just need a different library for Base64 I think
@@DanRNLab I just used the same and works 😉
Hey , Dan i am using and esp32 module to connect it with mmy react native app to deliver heart rate with a heartrate sensor will this code work for it??
If you are using BLE you should be able to do something similar
In this video I connect to an Arduino Uno R4 Wifi which has a built in ESP 32 - Bluetooth Low Energy ( BLE ) Peripherals with Arduino for Beginners
th-cam.com/video/siIS2clfvU8/w-d-xo.html
Hello, i have a problem after "npx expo prebuild" i dont see any phone on my screen and after "npx expo run:android" i get error "CommandError: No Android connected device found, and no emulators could be started automatically."
Did i misss something or it was explained in your other video?
Usually that means your computer can’t find your phone. You should make sure your Android phone is in developer mode and adb is configured correctly
nice video....do i have to do the eas-build setup if clone and run the project?
You can also use
npx expo run:android
npx expo run:ios
Assuming you have Android Studio and Xcode set up. Remember that this tutorial must be done on a physical device and not an emulator.
You also cannot use expo go you need to use the custom version of Expo that prebuild or EAS builds for you
Hi Dan, thank you and congratulations on your videos, I found them a few weeks ago. I started a personal project and bought some Beacon Proximity devices (Estimote). I'm stuck at the beginning because they don't provide a React Native library, so I'm trying to create a bridge between the native SDKs (Android and iOS) and Expo or React Native. It's proving to be very difficult because I can't find a clear guide that explains how to do it, and my knowledge of Java/Kotlin and Swift is almost non-existent. I have a question for you, does the library you mention in the project work for proximity devices with BLE technology? I found this more up-to-date library, react-native-ble-manager, do you think it's better? Thanks!!!
I think you can follow this tutorial and avoid making native stuffs. I talk about CLI here but it should be no different in Expo. They use the same BLE library
How to use Bluetooth Low Energy ( BLE ) Beacons with React-Native
th-cam.com/video/1hYM_sdQcBU/w-d-xo.html
@@DanRNLab You mean to following that other tutorial, trying to use the same library (react-native-ble-plx) while ignoring the native code and utilizing Expo (prebuild), as you explain in this tutorial?
Yeah you’ll need to combine the two. This one shows you how to set up BLE with Expo. The next one shows you how to set up beacons with RN BLE. They all use the same library though. react-native-ble-plx
@@DanRNLab Thank you very much. I really appreciate it!!!
@@DanRNLab Hi dan! Do you have any idea why i am getting this error: [BleError: Cannot start scanning operation]?
Hello Dan, thank you for the great video. I have a question for you. How can we run this project on our own physical device? Normally, I can run my expo projects on my own phone, but it didn't work for this project. However, it works on a virtual device.
Hey, you need to follow the steps I used in the video for using EAS Build. You can’t use Expo GO.
Hi Furkan, I am just a beginner with expo and React Native, so maybe the way I'll tell you right now it's wrong, but at least it worked for me. I executed the command expo start --localhost --android and in expo go I selected the development build option! I hope it works for you as well!
Hi Dan. I love your videos! Please keep'em rolling.
Everyone asked you for a demonstration in Expo, and so you did. You previously used react-native vanilla in some of your videos. Which would you recommend using? Are there exceptions like for freelance one is better than the other, but then if used professionally the other is recommended, and for hobbyists, etc...?
A couple years ago I would have said Vanilla RN is better but in the last year Expo has majorly upped their game. I would recommend using Expo for new projects. With EAS Build it’s way way way more flexible then it used to be. They also manage a lot of the annoying stuff with deployment for you. I think Expo might be the new default for React-Native in the near future
@@DanRNLab well you were right now expo is recommend by react native official.. see docs but can you tell me i develop app in cli should i switch to expo ?
@@saim4556 - it shouldn't be hard to switch. I think you just need to install the expo package into your app
I am stuck where to get service ID and characteristic ID? can you help me out.
Hey Dan, thank you so much for this video! I found it extremely useful and easy to follow. I have been looking for this sort of breakdown of implementing BLE in react native for a while. While following the tutorial I did come across an error I wanted to ask you about. I am receiving a render error with the message " Cannot read property 'createClient' of null". Is this something you have come across before or do you have any tips on where I may look to fix this error? Thanks again for you help and for the great tutorial!
TypeError: Cannot read property 'createClient' of null
This error is located at:
in App (created by withDevTools(App))
in withDevTools(App)
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent), js engine: hermes
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:102:17 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:148:19 in handleException
- ... 7 more stack frames from framework internals
When I’ve had this before it’s usually a problem with permission. You should look into double checking that you did them correctly
@@DanRNLab Thanks I will go and check. I appreciate your response!
@@rileymorgan8845 did you got how to solve?
@@DanRNLab I'm receiving the same error message after doing your tutorial even with the sample project... Do you have any ideas of how to solve this?
Hey dan, amazing video first of all! Second, i have a question in regards to this…will this still work if i change from a managed workflow to a bare using npx expo pre build? Im also using Expo Go at the moment
Also, would i need the EAS build?
Thanks happy to help!
So this does use the bare workflow not the managed workflow so you should already be OK.
You don’t need to use EAS, I haven’t done it before but the Expo team does say you can just build and deploy locally. You don’t need their service it just makes things easier as your team gets larger and your application scales.
For a small solo team you probably don’t need EAS.
thank you so much@@DanRNLab! One other thing, transitioning to a bareworkflow yet using Expo Go should allow me to use react-native-ble-plx right? and bypass the obstacle of not being able to use it? (My project requires me to use Expo Go)
Unfortunately no, you can’t use Expo Go with this library. It is a native dependency that isn’t built into Expo Go. You can’t access BLE without the Bare Workflow.
You might be able to use custom dev clients if distribution is your concern
thank you so much!@@DanRNLab
Hello, Dan! This video was AMAZING!! Love it very much:) But can you make an app that connects to bluetooth headphones and disconects when you click?
Hey, unfortunately this tutorial won't work for headphones. Those use Bluetooth Classic which is different then Bluetooth Low Energy
awesome
Hi, i followed the video step by step but when i launch my application i get the following error. 'Cannot read property 'createClient' of null, js engine:Hermes, what Can i do ?
Same problem
Please see this issue: github.com/friyiajr/BLESampleExpo/issues/1 . You are probably using Expo GO when you should be using prebuild.
Can we publish or run a production version of such an app, since it cannot be ran on Expo Go?
You can certainly publish a production version using Expo Application Services or by making a release build locally and uploading it like you would for a native app.
@@DanRNLab Thanks a lot!
Do you know why i get this error?
ERROR TypeError: Cannot read property 'createClient' of null
This error is located at:
in App (created by withDevTools(App))
in withDevTools(App)
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent), js engine: hermes
I've tried downgrading SDK to 49, but without any success :/. Please help
I've sold the issue as you've explained somewhere in the comments below.
I had to prebuild the project using npx expo prebuild and then start npx expo run:android
I tried following the tutorial, but getting the error:
ERROR Invariant Violation: `new NativeEventEmitter()` requires a non-null argument.
Hello, How can i do if i want to build and app that read a serial data from a sensor, it is a microcontroller build it by me, thanks for the info.
You should be able to adapt this tutorial to read data from services and characteristics that you program into your BLE device. As for how to make the firmware, I don’t know how to do that. I’ve only worked on the Client side of BLE and have never had to build the BLE Broadcasters myself.
Hi Dan, first of all, excellent video, it is very helpful, the second thing is that I'm trying to create something similar to what you show here, but the BPM data read them with the app so this is closed and then send this data to a backend and then treat them for features such as sms or emergency calls according to the data, do you see it viable? do you know how I could guide me? I would appreciate any help. its for my thesis:D
I think it depends on what you mean by closed. Does the device close it? Or do you mean you just don’t want to show it to the user?
Also do you want this to run when the app is backgrounded or the screen is locked?
when it is not running, as the last two options you mention, both the application in the background and the cell phone is locked. Basically the user does not have to be with the app open, something portable for common use.@@DanRNLab
@@DanRNLab when it is not running, as the last two options you mention, both the application in the background and the cell phone is locked. Basically the user does not have to be with the app open, something portable for common use.
I haven’t tried to use this library with the screen locked or the app backgrounded. You’ll need to experiment with that I think
Hey Dan, thanks for the video! Trying to set up the application for ios. Logged in to my Apple account, however I get such error: "Authentication with Apple Developer Portal failed!
You have no team associated with your Apple account, cannot proceed.
(Do you have a paid Apple Developer account?)" Do I need paid membership in order to run for ios?
Hey, if you have Xcode installed you should also be able to use this command to build locally:
Npx expo run-ios -device
@@DanRNLab I have Xcode installed. When I tried to run 'npx expo run-ios -device' command I receive 0.6.2 as an output. How can I get the QR code to run the app?
If you use that command you shouldn’t need the QR code. If you have your iPhone plugged in and wait a bit it should just install on the phone you selected from the menu.
@@DanRNLab So, as I understood I have to plug my iPhone into mac, open project in Xcode, select the device from the Xcode menu and after running 'npx expo run-ios -device' command I should be able to run the app?
I have my iPhone plugged in. Should I open the expo-ble-sample folder in Xcode? I am unable to do it. When I tried opening ios folder, it has an endless loading.
Not quite, you just need Xcode so that expo has access to the binaries to build your app. The steps would just be this:
1. In the terminal go to the root directory of your project
2. Plugin in your iPhone
3. Run the command which will list a bunch of simulators and your physical device
4. Choose your device from this list
5. Let it compile and wait a minute or so. The binary should install and open on your phone automatically
Hi dan can you mention the java sdk version, Gradle version, that ble supports that would be a grate help.
Hey you can just clone the repo, run the prebuild and look at the gradle file
hey, thanks for the video, will help me a lot. I am stuck with this error: TypeError: null is not an object (evaluating '_BleModule'), double checked permissions, followed exactly what you did, no success...
Hey @Gabrel Franco I tried in a variety of ways to reproduce this on my end but had no luck. Might be best for you to clone the sample project in the description and compare the code I wrote to yours
nice
Hi Dan im confused when i start to run in video part 10:27 im getting this error
This error is located at:
in App (created by withDevTools(App))
in withDevTools(App)
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent), js engine: hermes
ERROR TypeError: Cannot read property 'createClient' of null
Hey this often happens if you are doing one of these things:
1) using an emulator and not physical hardware
2) using Expo Go instead of the custom dev client
@@DanRNLab oh i see but this is also may work for smartwatch device right? thats what im trying to connect now china smartwatch E600
@@MHonRomero It will only work if the Smart watch is Bluetooth Low Energy. It will not work if it uses Bluetooth Classic
Hi Dan and thanks for the helpful videos! Could you show how to scan for BLEs when the app is off and the screen is off. As I undestood after android 11 this task is quite challanging and there is almost no info that I can find on that topic.... thanks in advance
Hi Dan , could you please just give a sign if such functionality is possible using react native. I'm really stuck... I'm trying to get notification when the beacon is in range and the screen is locked.
I am not really sure if it is possible or not. I haven’t tried this with the screen locked before
@@user-bt3xd8fd8v @DanRNLab Hello ! thanks a lot for the tutorial. Have you found more information during the last monthes, concerning a way to scan BLE when app is OFF or in the background ?
Hi Dan, thank you for this great tutorial. i get error cannot read property 'useMemo' of null, any idea to fix it?
That is a strange one since useMemo is part of React. You make have forgot to do yarn install or import useMemo from React
Hey@@DanRNLab , I am getting the same issue but it is not the useMemo, it seems to be on the new BleManager(), inside the useMemo. Any advice?
If you want to avoid this problem you should use a full state manager. This video was just meant to show the basics. Here is a tutorial on the full setup:
Redux-Toolkit ( RTK ) and Bluetooth Low Energy ( BLE ) in React-Native
th-cam.com/video/IWEAepFC0eo/w-d-xo.html
Is there any way to do this for iOs without having to pay the $100 for an Apple Professional Developer account?
It might be possible, unfortunately I am not aware of a way.
can i use this method for bluetooth printing with expo?
Only if the printer is Bluetooth Low Energy and not Bluetooth Classic
Hello, I have a Xoss heart belt, it has the same uuid, I cloned your git and it still doesn't appear on Bluetooth, could you give me any tips on how it can appear?
You probably need to change the name of the filtered devices when scanning. I have it set to filter for CorSense or something
@@DanRNLab Thank you very much, that was it
@@DanRNLab If I update to SDK 50 will it break the application?
Happy to help. I don’t know about updating. I haven’t tried.
Can I use this on two different pages? I have tried and it gives me an error, it always closes the application
more expo, please 🙏
💯 planning to do more Expo stuff
Hi Dan. Thank you for your list tutorial videos I have a question My Device have password for Unlock. Now, I unlock it to click on button and it unlock immediately but if I do not have password so can I looping from 000 - 999 to find out correct password of devices is it possible ?
I don’t really know about this. Some devices will just lock you out after 3 or so attempts. I don’t think it’s will work
@@DanRNLab tks for your advice
I did step by step, but on Android it gives me the message:
"Render Error
null is not an object (evaluating '_BleModule.BleModule.createClient')"
Maybe someone has any suggestions?
There are a few things to try. First, make sure Bluetooth is on on your device. Sometimes I forget it’s not on and can’t connect. Second, delete the app and reinstall. Make sure all the permissions are requested when you try and connect again after reinstalling.
If that doesn’t work then clone my version of the project in the description and see if you can find the differences in the useBLE.ts File
Please see this issue: github.com/friyiajr/BLESampleExpo/issues/1. You are probably using Expo GO when you should be using prebuild
What can I do about event emitter warning?
It’s a bug with the library. Doesn’t do anything harmful though so you can just silence it or ignore.
hey dan, can this work for android platform?
Yes it does, in fact I am using a Pixel 7 in that video
why does not `npx expo run:ios` work for you ?
That command will work fine if you want to use it. Just remember the -device flag. This tutorial will not work on simulator since they don’t support Bluetooth.
@@DanRNLab oh i see , thanx just trying to figure this expo thing
Can react-native-ble-plx send modbus data ???
I don’t think so. It doesn’t look like that protocol uses BLE but it something different. There may be a way to make them compatible but I am unaware of it
@@DanRNLab Thanks
@@DanRNLab it is possible !! I did it !!
That is does not working at all
Ill use expo and even if I download your code that is not working
What is this VS Code theme?
It is poimandres. You can find it here:
marketplace.visualstudio.com/items?itemName=pmndrs.pmndrs
So you have to prebuild? It sucks because on windows you can only prebuild for android and not ios ...
You can use EAS Build free Tier if you want to build for iOS
@@DanRNLab ah that works there too? good to know thanks ^^
how I can get UUID and characteristic UUID
You need to get them from a Data Sheet or your Firmware Engineer.
@@DanRNLab I connect with my usb ble device but after that I got null of serviceUUIDs
Unfortunately I am not sure why. It probably has something to do with how your BLE device works. Without it tho I can’t give much advise
@@DanRNLab thanks
is there no way to test this in the IOS simulator?
Bluetooth Low Energy cannot be tested on any Simulator iOS or Android
@@DanRNLab how are you doing it in this tutorial when you are showing the results in the simulator?
I am hooking up my physical mobile device to QuickTime (iOS) or Vysor (Android) so you can see the changes I am making. I don’t use Simulators in this tutorial
@@DanRNLab Thank you very much I appreciate the clarification. So you are running the app on your phone using Expo then the bluetooth is working? I am getting issues with initializing BleManager?
Usually when that happens it’s because you are using Expo Go and not the app that ‘npx expo run:android-device’ generates for your phone. You can’t use Expo Go here
When I type this command:
npx expo install react-native-ble-plx @config-plugins/react-native-ble-plx
I get this error:
---
› Installing 2 other packages using npm
npm install --save react-native-ble-plx @config-plugins/react-native-ble-plx
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: expo-ble-app@1.0.0
npm ERR! Found: expo@50.0.14
npm ERR! node_modules/expo
npm ERR! expo@"~50.0.14" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer expo@"^49" from @config-plugins/react-native-ble-plx@7.0.0
npm ERR! node_modules/@config-plugins/react-native-ble-plx
npm ERR! @config-plugins/react-native-ble-plx@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
---
Do I need to downgrade the Expo version or should it work for the newest version?
There is now an official plugin for BLE PLX. Please try this one
github.com/dotintent/react-native-ble-plx?tab=readme-ov-file#expo-sdk-43
What I tried was omit the part after @config and just add config to the app.json in docs Dan mentioned:
[
"react-native-ble-plx",
{
"isBackgroundEnabled": true,
"modes": ["peripheral", "central"],
"bluetoothAlwaysPermission": "Allow $(PRODUCT_NAME) to connect to bluetooth devices"
}
]
So just the npx expo install react-native-ble-plx
I also had to remove the @config part from the app.json and eas.json