This is a outstanding tutorial well done, I am having problems with the BLE reading and no call back is been triggered. I added your example code, odd in the logcat there is no debug commands for any ble read. I have similar code running in Java and I can see the BLE triggers. When the app starts it triggers the call back onCharacteristicChanged and it get the data on mobile app start up. But, doing a manual read does not trigger this call back.
I found the problem, which was really odd. The call backs were in the wrong place, onCharacteristicRead should be at the end of the main code block. I delete this function onCharacteristicRead, then it reported an error and then auto added the function back into the right location.
Superb tutorial. I do have a question, how do you get the Major, Minor, and the TxPower or RSSI from the BLE, is it the same from getting the temperature and humidity?
Thank you! You can get the TxPower and RSSI in onScanResult from the ScanResult itself which is a readable form of the advertising package. Minor and Major are also part of such an advertising package. But iBeacon where the Major and Minor is included is just a standard that bases on BLE but not every BLE device has this iBeacon standard. So the Android Bluetooth classes does not provide a minor and major property since it is not always there if a BLE ScanResult comes in. I never needed to access these two values but maybe you have to use some third party library
hi Sir, thank you for the best tutorial, is it possible to create another tutorial where we actually write to Arduino or Esp32 to control a simple LED to turn ON and Turn Off?
Great video, thank you for your job! Can you help me please? May i connect Tuya BLE THB2 sensor using this app, the fact is that when ble sensors are scanned, it does not see them, although these sensors are ble devices :(
Great video, Matze! Which sensor are you using? Looks like a pretty small one that you could just tuck into a corner pretty easily. Appreciate you taking the time to make this video - covered a ton of ground!
Hello Sir ! I liked your work. Thanks ! I have a question: Do we need any kind of data from Device with BLE to be able to connect and share data with it ?
Thx for this contribution! I am getting troubles perhaps you can help me... I added 2 notifyble characteristics on a first service and 1 more notifyble characteristic on a second service. So 3 notyfiable charactics total. I have used enablenotification three times with each charact uuid without errors it seems all to be ok from app point of view ( I verifyed is ok and three different descriptor adresses) but only the first one change the descriptor on server.. any suggestions? writeDescription function needs anything else? It is not reporting error but I am verifying on two devices and with nRF app only the first descriptor is enabled on server..
Update: if I change the order wnen using enableNotification function ever the first is enabled but not the other two characteristics.. perhsps needs time between descrptor writes?
SOS! First step- first Problem! compose_version and classpath are red, Gradle sync failed. Is there anything I should have done before? How did you all do this?
Hey Amazing tutorial, i have a question. I am new to kotlin jetpack and i am currently working with a similar app with kotlin jetpack compose and I need to connect my application with an HC-05 Bluetooth module, how should I change this code to fit my application, or is there any source that can help me? Can you please help me as I am unable to find any good resource.
Thank you! Of course you can. When you get your scan results then just start the connection for all devices you want (Or list them to the user first and connect via click on the specific devices). Inside your gattCallback functions you can then check the devices address or name on the received gatt for example to check which connected device is currently triggering the callBack function. I would save the received gatt of each device after connection in some kind of array data struct like List at the beginning to make the device management comfortable.
@@kapps7407 I was able to connect two similar devices but can get data from only one. Does BLE support data retrieval from multiple devices simultaneously?
Yes you should be able to retrieve them. When you establish the connection to those devices then you need to save the gatt somewhere with a corresponding ID or something like this to differentiate later which gatt belongs to which device. And then in your onCharacteristicChanged() Callback you will get a gatt and need to check which gatt it actually is. If you just want to check if the retrieving of both devices works then just connect to them both subscribe to the right characteristics and then in your onCharacteristicChanged both values should come. But be careful when you connect and subscribe to both devices always do it step by step and not two commands at once.
@@kapps7407 thanks. I was able to connect multiple devices and retrieve the data, however, the auto-reconnect function is not working? Does auto-reconnect works for multiple device?
Difficult to say without seeing your code. But you can try to leave the requestMtu() command away and just subscribe directly to the notification inside the onServiceDiscovered() callback. Make also sure that you don't execute two commands in the process line at once. They need to be executed after each other.
@@kapps7407 I also have the same problem where the app is "stuck" on "adjusting MTU space". I'm using the same code but have made the change from having two inputs to one. Where in the code can I check if the commands are executed after each other? Great video, thank you for all the help!
@@simonandersson1729 You can apply logs on different positions to check what gets executed when. I recommend you to implement some kind of execution queue which assures that everything happens step by step. But logs should already help I think
Hi, thank you for the tutorial. I would like to import your project on my pc and do some mods. I tried first to export the apk of your project but it's not working the same way. I see that there are some missing files uploaded in the github folder(not sure about that). Can you help to import correctly the project on my PC?
Im stuck in currentlyInitializing state which keeps scanning for my device. I have changed the Service and Characteristics Uuid as per my device but there is no progress. I don't use compose so Im using button to trigger the scan. I would appreciate if you can help me with this. Thank you regardless.
hey! So actually I got past the scanning stage but now I cant figure out how to get data properly... Im using a proxy device from the an App to replicate BLE... I can connect to it but I cannot figure out how to retrieve the data I want - "BLE Scanner" the apps name. If know anything about how to do that... I will be appreciated
Thanks for the Video .. its so amazing.❤ It helped me for implementing with weight scale in android app. As I don’t have any device name , i added a filter with service_uid and I used the same descriptor_uid as as in your code and it works fine..😊 But when I convert the byte array to my weight , I had to convert the byte to toUInt to get the proper value upto some extend.. after that I’m getting incorrect value in the byte array.. Could you please suggest something on this ?
did you get his code to build or did you code your own version along with him? I was trying to follow this but after following his steps to add dagger hilt and even cloning his finished project it just won't give me a successful build no matter how i try to fix the gradle file. any suggestions?
Can you help me how to build his original version? With Giraffe version of Android Studio, I have the following build error. e: This version (1.1.0-beta01) of the Compose Compiler requires Kotlin version 1.5.31 but you appear to be using Kotlin version 1.6.21 which is not known to be compatible... So I changed build.gradle file as follows: buildscript { ext { // compose_version = '1.1.0-beta01' compose_version = '1.2.0-rc02' } It compile and build OK. App appears OK but at BLE scanning stage, it stuck and did not show any avaiable device.. Your help will be greatly appreciate..
Followed the tutorial well, but my application is stuck in "Adjusting MTU" it doesn't go past that. Tried changing to many Service IDs and Characteristic ID. Any help?
Any updates? About month ago i resolved it then today i checked the feature again and its not working... shame me i could write down what i have changed@@jon_mark
To anyone getting this error: java.lang.SecurityException: Permission Denial: starting Intent { act=android.bluetooth.adapter.action.REQUEST_ENABLE cmp=com.android.settings/.bluetooth.RequestPermissionActivity } from ProcessRecord{5ba8236d 124:com.example.appname/u0a155239} (pid=321, uid=2314) requires android.permission.BLUETOOTH_CONNECT As of android 6.0 some permissions have to be requested at runtime so it's not enough to put the permissions in the manifest anymore. This tutorial gives more info - ua-cam.com/video/x38dYUm7tCY/v-deo.html&ab_channel=AndroidDevelopers
i downloaded the "BLE scanner" on my android phone and it shows so many "mac addresses" and someone said it is people who took the jab. i went to walgreens since they give the jab there and i got over 200 "BLE mac addresses" when no one was in the store by the pharmacy. is it true it is the people who took the jab?
Can you tell me which version of Android Studio used in this example? I have a running error using current version of Android Studio. Your help will be appreciate in advance. Error is as follows: :app:kaptGenerateStubsDebugKotlin java.lang.IllegalAccessError: class org.jetbrains.kotlin.kapt3.base.KaptContext (in unnamed module @0x52a8bf8b) cannot access class com.sun.tools.javac.util.Context (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.util to unnamed module @0x52a8bf8b
You have to update the Kotlin Gradle Plugin Version. Plus, you might have an error of incompatibility with your compose compiler, in that case you have to update the compose compiler version number in the "build.gradle" file accoridng to your Kotlin version (if you don't know which one to choose google "Compose to Kotlin Compatibility Map")
The best tutorial on the subject
Thank you!
Great video. Only one remark: you can use callback flow to wrap the callbacks, instead of launching coroutine every time a callback is invoked.
Thanks for the tutorial, very good job👍
Thanks for the wonderful tutorial. Great explanation.
Could you please tell me how can I read RSSI value of the connected tag?
Absolutely perfect video. I learned a lot!
This is a outstanding tutorial well done, I am having problems with the BLE reading and no call back is been triggered. I added your example code, odd in the logcat there is no debug commands for any ble read. I have similar code running in Java and I can see the BLE triggers. When the app starts it triggers the call back onCharacteristicChanged and it get the data on mobile app start up. But, doing a manual read does not trigger this call back.
I found the problem, which was really odd. The call backs were in the wrong place, onCharacteristicRead should be at the end of the main code block. I delete this function onCharacteristicRead, then it reported an error and then auto added the function back into the right location.
@@brendonshaw6412 can i see your code, if you don't mind? my app gets stuck at ""Could not find temp and humidity publisher"
@@KenFuzion Did you manage to fix this?
@@alexkokos5363 nope
Superb tutorial. I do have a question, how do you get the Major, Minor, and the TxPower or RSSI from the BLE, is it the same from getting the temperature and humidity?
Thank you! You can get the TxPower and RSSI in onScanResult from the ScanResult itself which is a readable form of the advertising package. Minor and Major are also part of such an advertising package. But iBeacon where the Major and Minor is included is just a standard that bases on BLE but not every BLE device has this iBeacon standard. So the Android Bluetooth classes does not provide a minor and major property since it is not always there if a BLE ScanResult comes in. I never needed to access these two values but maybe you have to use some third party library
You showed us an example of how to read values from the BLE device. Weren't you reading from the BLE Device already?
Niceee thank you for this tutorial!
Hi there, do you have an example to read the characteristic ?
hi Sir, thank you for the best tutorial, is it possible to create another tutorial where we actually write to Arduino or Esp32 to control a simple LED to turn ON and Turn Off?
Great video, thank you for your job! Can you help me please?
May i connect Tuya BLE THB2 sensor using this app, the fact is that when ble sensors are scanned, it does not see them, although these sensors are ble devices :(
Great video, Matze! Which sensor are you using? Looks like a pretty small one that you could just tuck into a corner pretty easily. Appreciate you taking the time to make this video - covered a ton of ground!
Thanks for the tutorial
Great video. Thank you.
Thank you, it was a great help.
Hello Sir ! I liked your work. Thanks !
I have a question: Do we need any kind of data from Device with BLE to be able to connect and share data with it ?
Thx for this contribution! I am getting troubles perhaps you can help me... I added 2 notifyble characteristics on a first service and 1 more notifyble characteristic on a second service. So 3 notyfiable charactics total. I have used enablenotification three times with each charact uuid without errors it seems all to be ok from app point of view ( I verifyed is ok and three different descriptor adresses) but only the first one change the descriptor on server.. any suggestions?
writeDescription function needs anything else? It is not reporting error but I am verifying on two devices and with nRF app only the first descriptor is enabled on server..
If you need more descritions or the modified code please let me know
Update: if I change the order wnen using enableNotification function ever the first is enabled but not the other two characteristics.. perhsps needs time between descrptor writes?
Ok.. it seems clear i am missing to wait the writeDescriptor to finish properly. As a newbie I am still struggling with basics
do you know what bluetooth chip the sensor uses? I'm trying to do a similar project with a HM-10 chip! Thanks
Nice tutorial. Please make tutorial on BLE mesh using Android.
SOS! First step- first Problem! compose_version and classpath are red, Gradle sync failed. Is there anything I should have done before? How did you all do this?
To what part of this video do I need the code ? I only want to write Gatt Characteristics to a BLE ESP32 Module
thanks for the video, learned so much in one video, could you please try to make video with wifi also
Hey Amazing tutorial, i have a question. I am new to kotlin jetpack and i am currently working with a similar app with kotlin jetpack compose and I need to connect my application with an HC-05 Bluetooth module, how should I change this code to fit my application, or is there any source that can help me? Can you please help me as I am unable to find any good resource.
Thank you for this 🤟🏾
Hi! . How to connect to a smartphone using bluetooth?
Create a classic Bluetooth socket connection between both Smartphones and then you can use an input and output stream for communication :)
@@kapps7407 Thanks :)
Really nice tutorial. Is it possible to have a multiple devices connected to the same app ?
Thank you! Of course you can. When you get your scan results then just start the connection for all devices you want (Or list them to the user first and connect via click on the specific devices). Inside your gattCallback functions you can then check the devices address or name on the received gatt for example to check which connected device is currently triggering the callBack function. I would save the received gatt of each device after connection in some kind of array data struct like List at the beginning to make the device management comfortable.
@@kapps7407 I was able to connect two similar devices but can get data from only one. Does BLE support data retrieval from multiple devices simultaneously?
Yes you should be able to retrieve them. When you establish the connection to those devices then you need to save the gatt somewhere with a corresponding ID or something like this to differentiate later which gatt belongs to which device. And then in your onCharacteristicChanged() Callback you will get a gatt and need to check which gatt it actually is. If you just want to check if the retrieving of both devices works then just connect to them both subscribe to the right characteristics and then in your onCharacteristicChanged both values should come. But be careful when you connect and subscribe to both devices always do it step by step and not two commands at once.
@@kapps7407 thanks. I was able to connect multiple devices and retrieve the data, however, the auto-reconnect function is not working? Does auto-reconnect works for multiple device?
Do you mean the autoConnect Boolean which you pass in the connectGatt(..) function?
Hi sir, i need some help on my code, how can I reach you?
my app got stuck on "adjusting mtu space", can you help me
What exactly do you mean by "got stock"? That the "onMtuChanged()" callback does not get triggered?
@@kapps7407 i think thats the problem, because when i run it, it always showing loading icon and text "adjusting mtu space"
Difficult to say without seeing your code. But you can try to leave the requestMtu() command away and just subscribe directly to the notification inside the onServiceDiscovered() callback. Make also sure that you don't execute two commands in the process line at once. They need to be executed after each other.
@@kapps7407 I also have the same problem where the app is "stuck" on "adjusting MTU space". I'm using the same code but have made the change from having two inputs to one. Where in the code can I check if the commands are executed after each other? Great video, thank you for all the help!
@@simonandersson1729 You can apply logs on different positions to check what gets executed when. I recommend you to implement some kind of execution queue which assures that everything happens step by step. But logs should already help I think
Hi, thank you for the tutorial. I would like to import your project on my pc and do some mods. I tried first to export the apk of your project but it's not working the same way. I see that there are some missing files uploaded in the github folder(not sure about that). Can you help to import correctly the project on my PC?
Im stuck in currentlyInitializing state which keeps scanning for my device. I have changed the Service and Characteristics Uuid as per my device but there is no progress. I don't use compose so Im using button to trigger the scan. I would appreciate if you can help me with this. Thank you regardless.
hey! So actually I got past the scanning stage but now I cant figure out how to get data properly... Im using a proxy device from the an App to replicate BLE... I can connect to it but I cannot figure out how to retrieve the data I want - "BLE Scanner" the apps name. If know anything about how to do that... I will be appreciated
Thanks for the Video .. its so amazing.❤
It helped me for implementing with weight scale in android app.
As I don’t have any device name , i added a filter with service_uid and I used the same descriptor_uid as as in your code and it works fine..😊
But when I convert the byte array to my weight , I had to convert the byte to toUInt to get the proper value upto some extend.. after that I’m getting incorrect value in the byte array.. Could you please suggest something on this ?
did you get his code to build or did you code your own version along with him? I was trying to follow this but after following his steps to add dagger hilt and even cloning his finished project it just won't give me a successful build no matter how i try to fix the gradle file. any suggestions?
Can you help me how to build his original version? With Giraffe version of Android Studio, I have the following build error. e: This version (1.1.0-beta01) of the Compose Compiler requires Kotlin version 1.5.31 but you appear to be using Kotlin version 1.6.21 which is not known to be compatible... So I changed build.gradle file as follows:
buildscript {
ext {
// compose_version = '1.1.0-beta01'
compose_version = '1.2.0-rc02'
}
It compile and build OK. App appears OK but at BLE scanning stage, it stuck and did not show any avaiable device.. Your help will be greatly appreciate..
Hi do you mind to assist me on my project? i can compensate you.
hello just a question is that possible to monitor multiple BLE devices?
Yes sure it is !:) you can have multiple gatts. For each ble one
Followed the tutorial well, but my application is stuck in "Adjusting MTU" it doesn't go past that. Tried changing to many Service IDs and Characteristic ID.
Any help?
I am stuck there as well, aby updates?
@@MohannadHaddad3 not really, haven't yet figured it out... I dropped the future for a later release when I get the Bluetooth part figured out
Any updates? About month ago i resolved it then today i checked the feature again and its not working... shame me i could write down what i have changed@@jon_mark
einfach Klasse , ich finde du hast viele Mühe für BLE gegeben.
Darf ich fragen wie heisst dieser Sensor?
Danke! Das war dieser hier: JINOU Bluetooth Low Energy 5.0 Beacon/iBeacon mit Sensor, kabelloser Feuchte- und Temperatursensor. Für Android/iOS
Is it possible to see the arduino code you are using? I am having trouble with the communication between app and arduino :)
Hi Emelie, sorry no I don’t have the code I just bought that sensor on Amazon ..
To anyone getting this error:
java.lang.SecurityException: Permission Denial: starting Intent { act=android.bluetooth.adapter.action.REQUEST_ENABLE cmp=com.android.settings/.bluetooth.RequestPermissionActivity } from ProcessRecord{5ba8236d 124:com.example.appname/u0a155239} (pid=321, uid=2314) requires android.permission.BLUETOOTH_CONNECT
As of android 6.0 some permissions have to be requested at runtime so it's not enough to put the permissions in the manifest anymore.
This tutorial gives more info - ua-cam.com/video/x38dYUm7tCY/v-deo.html&ab_channel=AndroidDevelopers
Thanks for sharing, this was very helpful!
(my own progress timestamp)
22:10
i downloaded the "BLE scanner" on my android phone and it shows so many "mac addresses" and someone said it is people who took the jab. i went to walgreens since they give the jab there and i got over 200 "BLE mac addresses" when no one was in the store by the pharmacy. is it true it is the people who took the jab?
bm - 22:09
this is already outdated lol.
most the libraries are depreciated too.
Can you tell me which version of Android Studio used in this example? I have a running error using current version of Android Studio. Your help will be appreciate in advance. Error is as follows:
:app:kaptGenerateStubsDebugKotlin
java.lang.IllegalAccessError: class org.jetbrains.kotlin.kapt3.base.KaptContext (in unnamed module @0x52a8bf8b) cannot access class com.sun.tools.javac.util.Context (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.util to unnamed module @0x52a8bf8b
I am also getting the same error when attempting to test the app for the second time. (Meaning at around 14 mins when you do)
did u figure it out yet? i am also getting the same error.
You have to update the Kotlin Gradle Plugin Version. Plus, you might have an error of incompatibility with your compose compiler, in that case you have to update the compose compiler version number in the "build.gradle" file accoridng to your Kotlin version (if you don't know which one to choose google "Compose to Kotlin Compatibility Map")