Android Question I need BT GATT services on Android [SOLVED]

Peter Simpson

Expert
Licensed User
Longtime User
Hello All,
I've been working with a new client for the past few months that already has an iOS developer that created an iOS app that interacts with my clients bespoke hardware solutions, my client has in-house hardware designers with bespoke Arduino hardware and PCB solutions in place.

I've been developing an Android app for them for another solution that they are more than happy with but I've hit a hurdle.
What I need need to integrate next is BT GATT services. Without Android BT GATT services and learning about their BT GATT characteristics the project cannot be completed thus it will come to a complete standstill. Android BT GATT is the last peace in the puzzle. Once BT GATT is integrated into my app and it's broadcasting multiple UUID's and receiving characteristics data, my app can start to control their bespoke hardware. Please note that my app will be running on custom Android hardware and using a customised forked version of Android that I've asked the manufacturer to modify for my client. The manufacturer has sent me videos of the modification and they are looking good.

I need help with the following as I have absolutely no idea about BT GATT services on Android. I need to create Bluetooth GATT services, does anyone have a working example of how to achieve Bluetooth GATT services on Android that broadcasts multiple UUID's and that can receiving characteristics?

Bluetooth GATT services:
https://developer.android.com/reference/android/bluetooth/BluetoothGattService

Bluetooth GATT characteristics:
https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic

I have seen the following post on reading the characteristics and I believe that Erel's response it will help me a lot, maybe. But I still need to know how to create a separate BT GATT service that broadcasts multiple UUID's.

Any help or feedback would be great appreciated.


Thank you...
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
I'm not sure that I understand. Are you implementing a BLE peripheral? Or BLE central?

In most cases the phone apps are implemented as BLE central.

More information here: https://www.b4x.com/android/forum/threads/ble-peripheral.84051/#content
Good morning Erel, thank you for your response.
I've seen that post and I tried looking at them both especially central. I couldn't see how to implement Bluetooth GATT services which is the link that the iOS app developer sent me.
https://developer.android.com/reference/android/bluetooth/BluetoothGattService

I saw BLE peripheral but I'm not sure if that will let me create and add a Bluetooth GATT service to my clients app.

Thanks you
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
I also read this last night if it helps anyone understand what I'm trying to accomplish.

The Bluetooth LE protocol operates on multiple layers. General Attribute Profile (GATT) is the layer that defines services and characteristics and enables read/write/notify/indicate operations on them. When reading more about GATT, you may encounter GATT concepts of a “server” and “client”. These don’t always correspond to central and peripherals. In most cases, though, the peripheral is the GATT server (since it provides the services and characteristics), while the central is the GATT client.

Thank you...
 
Upvote 0

GabrielM

Member
Licensed User
Longtime User
Hello Peter
if you know the UUID's of the private Services and their Characteristics , as defined on the hardware side, you should be able to connect to it, then if you also have access to their API you could send and receive data as needed. Attached is a simple code where a GATT private Service and few Characteristics are used. Obviously, you need to have the BLE peripheral hardware for the test.
 

Attachments

  • BLE-TEST.zip
    15.4 KB · Views: 47
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Hello Peter
if you know the UUID's of the private Services and their Characteristics , as defined on the hardware side, you should be able to connect to it, then if you also have access to their API you could send and receive data as needed. Attached is a simple code where a GATT private Service and few Characteristics are used. Obviously, you need to have the BLE peripheral hardware for the test.

Thank you for your example code, this is excellent for connecting to an actual GATT service and sending data via Characteristic, this code will definitely come in handy for that. My client is also looking to emulate the hardware itself on an Android device, I believe that this can only be achieved by using Bluetooth GATT services. Your excellent example code (thank you again for that) is perfect for writing/sending data via Bluetooth GATT characteristics.

Peter...
 
Upvote 0
Top