Send a Android BLE GATT Notification

4k Views Asked by At

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.

2

There are 2 best solutions below

1
On BEST ANSWER

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:

  1. Create a GATT Server on your smartphone.
  2. 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.

1
On

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.