I'm building a bluetooth project. I select a connected device through a ListView. I want to get the serviceUuid and characteristicUuid from the selected device when I click a button. How can I get that?
Use This app to get UUID
I select a connected device through a ListView. I want to get the serviceUuid and characteristicUuid from the selected device by the coding of my own app. Not by the help of other app.
Generally, if there is a specific device your App connects to, you should know the relevant UUIDs (of which there can be many for one device) from the device documentation.
If the device advertises it's Service UUIDs, you can collect them as a list:
Note: The latest MIT BLE Extension version 20200828 is required.
You will find that together with lots of useful links and info on my website:
https://www.professorcad.co.uk/appinventortips#TipsBluetooth
I tried to show the ServiceUuid in the textbox by the following code, but it does not work. and shows an error (Attempt to invoke virtual method 'android.bluetooth.le.ScanRecord android.bluetooth.le.ScanResult.getScanRecord()' on a null object reference). Why did this happen?
Hi again
What is the device being selected? Device Type, Manufacturer, model.
hello, the devices are micro: bit and Arduino UNO with HC-05 Bluetooth module.
Right - well the HC05 Module uses Serial Comms on Bluetooth v2 - not BLE, so no UUIDs etc. You can use the built-in App Inventor Bluetooth Blocks to connect with your Arduino and HC05.
Concerning micro-bit, App Inventor has a bespoke extension for it - which unfortunately is a bit of a mess at the moment but basically works once you have developed a certain amount of gray hair. See my website for links:
https://www.professorcad.co.uk/appinventortips#TipsMicroBit
Thank you !
Sorry to dig up an old thread but this is the best situation I've found to match mine. I have a BLE device and currently I have manually entered service/characteristic UUID's and my app is working as intended. I'm assuming not all UUID's for various BLE devices are the same (if they are, let me know). I want to collect them as you show and be able to "get" them from the list. I'm having trouble understanding the procedure.
The bottom two lines are my existing "manual" use case. I want the text string to be variables set from the procedure you are referring to.
My understanding: An empty global list is created, procedure sets global empty list with information from call UUIDs but what is the deviceAddress referring to? I'm looking to store these values in a list and set my variables equal to the appropriate needs (service, characteristic). Looking for where to go from here please.
Edit: added my .aia for ease of review.
BT_LED.aia (192.4 KB)
The idea behind a UUID is that because the space is so large (2^128, more than the estimated number of atoms in the universe) that it's basically impossible create a collision when randomly selecting two UUIDs to identify things. If you know what services/characteristics you want to connect to, then it makes sense to encode them into the app. If you're making a more generic UI for people to explore the services available from a BLE advice, then you may want to look at the DeviceCharacteristics property which returns a list of tuples containing the service, characteristic, and a name (if the characteristic name is known by the extension).
The project as a whole is simply sending characters over to the BLE device so my thought is the services/characteristics used won't change but I wasn't sure if the values are different between devices for the same services/characteristics.
When finding the service/characteristic through a BT Scanner app I pulled the Custom Service and Custom Characteristic value and that is what I have defined and working. I'm working with an AT-09 Bluetooth 4.0 BLE module. I was able to get a list with DeviceCharacteristics that you mentioned. But in my app it does say Unknown Characteristic for all of them so I don't think it is going to work as I wanted with no name to reference like the BT Scanner app had. Thanks for the quick reply.
Sorry to necro this post but I think i've managed to get lists of service and char UUIDs in app.
Used call.supportedServices and Use call.supportedCharacteristics. and it gave me a list.
From what i can tell the last in each list is always a usable UUID for service and char.
Unsure how usefull the other uuids are for connections
(Someone tell me please im finding BLE very painfull to use)
Hello Ben2 - that's a perfectly valid way to obtain the UUID's of a device that has them built-in.
If you are creating your own device based on a microcontroller, then you will need to define custom UUIDs to suit your requirements:
ProfessorCad: Tips & Tricks Create/Validate BLE UUIDs
Hi a want to create an app with app inventor but I dont understand how to obtain UIDD and chracteristics from my "smart button" flic 2 Flic 2 Product Page | Flic Smart Button . Can somebody help me please?
I think you need to use the Flic SDK. It should be mentioned in the User Manual. When you have found it, post it here.
Hi Chrisward, thank you for your answer.
Here there is the github with informarion but i dont know how to use this information in app inventor.
Could you help me please?
Well if you read that documentation, which is very thorough, they have made communication with the buttons as easy as possible.
However, their code is not aimed at block-type coding languages like App Inventor and makes extensive use of structures, which App Inventor does not support.
Their security is good but also difficult to support. For example:
When pairing the button (requires it to be in Public mode), a pairing identifier (32-bit) and pairing key (128-bit) is created. This pair should be stored persistently so communication can continue after a re-connection.
Your App will need to 'grab' those values and store in TinyDb for recall the next time the App is opened.
The BLE extension has the facility to enlarge the MTU (Maximum Transmission Unit) as is required by flic2.
I think the best way to support flic2 is to incorporate the GitHub code provided into an App Inventor extension, or use Android Studio and not App Inventor.
You can suggest a flic2 extension on the App Inventor Extensions forum page.
If you are familiar with coding in Java you could write that extension yourself: