Android: Using BLE without a bespoke GATT Server - android

I want to use the BLE Current Time Service (0x1805) in conjunction with a BLE enabled device. My question is: Do I "need" to create an App to manage BLE connectivity and return results for the Current Time Service to my device, or does Android somehow implement a generic GATT server?
If so, how do I enable that?
So far, my BLE pairing attempts have simply errored out on the device side.

I'm not aware of a generic GATT Server on Android, but there are apps that can do the job for you. I would suggest starting with the nRF Connect app which is able to start a GATT server with a pre defined current time service.

Related

One bluetooth device with multiple apps

I am writing an android app to connect with BLE heart rate monitor devices.
All works well until another application tries to connect to the same service on the BLE device.
Only one application seems to be able to connect at a time.
Is it possible to connect the same BLE service to multple apps at once?
I set up my Bluetooth service in accordance with Link :
You can use BluetoothManager.getConnectedDevices() to get a list of Bluetooth devices, even ones not connected by your app. Unfortunately, you don't also get the service information for those devices.
What you can do then, is connect to the ones not already connected by your app and perform service discovery on them (BluetoothDevice.connectGatt() / BluetoothGatt.discoverServices()), then disconnect those that you aren't interested in. It's a bit cumbersome, but it seems to work for us.
No you can not do that, this is something is not supported in BLE.

What is the best approach to implement bluetooth connectivity with multiple devices in Android?

I have to implement bluetooth connectivity with multiple devices(4 devices) from my android java application. App will be continuously receiving data from 2 connected BT (bluetooth) devices, the other 2 BT devices can be connected on need basis & no need to maintain continuous connection. As per the requirements, app has to run continuously for 24 to 48 hours. The device with the app installed will be dedicatedly used for the app & the app will be continuously pushing the bluetooth received data to a remote server. The connected BT devices can be disconnected & reconnected any time from the app. Also if the BT connection is lost, automatic reconnect should happen. What is the best approach to implement this?
Hi i have developed a similar app for BLE Heart rate Belts (Polar H7)
what i did (may not be the best approach but it works smoothly for me as i am able to mangae 5-7 belts at a time) is i made a service to manage the connection with multiple BLE devices
in the service i keep record of all the GATT Callbacks.
so i am using one service in backgorund to keep and mange the connections and separate GATT callbacks for each device in a list or Hashmap .
If a device disconnects or new connection needs to be established i connect/disconnect accordingly and update my record of GATT callbacks .
take a look at the Android BLE sample something similar

Send a Android BLE GATT Notification

I´m currently developing an BLE application, based on the Gatt sample project provided by Google.
What I want to realize is to send a notification from my Android device(smartphone) to another BLE device(e.g. TI CC2540). There are many discussion about how to receive a notification on the Internet.
However, I can't find out any discussions about sending a notification. So is there any method to sending a notification through Android device? Thank you in advance.
Technically, there is a difference between the Central/Peripheral classification, which belongs to the GAP, and the Client/Server one, which belongs to the GATT. A Central (one that scans and connects) is usually a Client, and the Peripheral (one that advertises) is usually a Server, but not necessarily.
The smartphone is the Central (it can be Peripheral as of Android 5.0 but I doubt that's the case for you), and usually it's the Client because it connects to GATT Servers located on Peripherals such as your sensor (or whatever you are building).
So, if you want to send a Notification from your device you need 2 things:
Create a GATT Server on your smartphone.
Design your Peripheral to execute GATT Client procedures (Discover Characteristics, Read/Write etc).
This may not be necessary, as #istirbu pointed out. If your application is already up-and-running, your smartphone Central is a Client. The equivalent of a Notification at Client-side is the Write Command (without response). So use that.
Notifications are used by the peripheral device to send back information to the client (eg Android device). There is no need to send a notification to the device from GATT perspective, you can perform a write operation on a characteristic. As a result of that write, or any periodic operation, the peripheral device will send back (notify) some info to the client on the same or other characteristic that you have subscribed for.

Android WiFiDirect service discovery confusion

I'm trying to use WiFi Direct service discovery to connect two android phones. I'm only interested in one phone being able to send a connection request. I thought what I needed to do was register a local service on one phone, and discover the service on the other phone, and after discovering it I can connect to it. But it seems like I have to do the discovery stuff on both phones in order for it to work...so I'm just confused on what's happening. I'm using this tutorial. Can anyone help me understand what's necessary to have the two phones connect? I can't have one phone only registering and the other phone only discovering?
It really depends on what you are trying to do. You can actually discover other devices and perform a connection without having a Service Discovery layer on top. Peer Discovery and Service discovery are not the same thing. Peer discovery involves detecting all of the nearby devices that use Wifi Direct while Service Discovery involves only discovering devices that advertise a specific kind of service.
You should start with this other Tutorial before moving on to Service Discovery which is a more advanced topic.
You can detect other devices using peer discovery but there is no need for service discovery to exchange data or service. You can use socket connection also after connecting the devices ex - for exchanging of files .
It's worth to mention that using ServiceDiscovery you can sent some additional data, like running port or something else in record map (in DNS-SD at least).

BLE GattServices

I'm developing an application that tries to connect my smartphone to a BLE device with Gatt (it can be either a smartphone or a BLE device) and read just a piece of data. This data will dynamically change and I want to keep this data as the value of a characteristic of a service. My main purpose is to read this data from the client side. Since I am connecting with Gatt, I think the only way is to store that data as the value of characteristic.
How can I add a service and a characteristic to the BLE device from the app which I created for the BLE device? I did a research and found some useful information from here. But this helps you create a service for a device you have connected to. Please help me or give me an idea. Thank you very much
Seems to me that what you are trying to do is to connect to a device and add a service on that remote device. That is not have it works and you will not be able to create an app that does this.
In BLE, both sides have a Gatt server. The addService API call in BluetoothGattService is only for adding services to your local Gatt server, not the remote server.
This is how it needs to work:
Your phone is called the central (or master), the device you are connecting to are the peripheral (or slave).
Both sides can define their local Gatt server (typically before they connect). The local Gatt server is mandatory for both sides.
If you can write the firmware running on the peripheral you can certainly create the services and characteristics you need to make your application work (again this is usually as the devices is starting, not after a connection has been made)
Your phone will connect to the peripheral and can read from or write to the Gatt server running on the remote device using the Android Gatt client. The structure however remains unchanged.
To be able to answer more detailed a lot more information on the setup is necessary.
Android (prior to 5.0) doesn't support acting as a peripheral mode you can write applications in order to act as central(master) or Observer mode.
Since Android 5.0, you can use android.bluetooth.le API along with BluetoothGattServer to adopt peripheral role on your Android 5.0+ devices.

Categories

Resources