简体   繁体   English

发送Android BLE GATT通知

[英]Send a Android BLE GATT Notification

I´m currently developing an BLE application , based on the Gatt sample project provided by Google. 我目前正在开发一个基于Google提供的Gatt示例项目的BLE application

What I want to realize is to send a notification from my Android device(smartphone) to another BLE device(eg TI CC2540 ). 我想要实现的是从我的Android设备(智能手机)向另一个BLE设备(例如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? 那么有没有通过Android设备发送通知的方法? 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. 从技术上讲,属于GAP的中央/外围分类与属于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). 智能手机是中央(它可以是Android 5.0的外围设备,但我怀疑你的情况), 通常它是客户端,因为它连接到外围设备上的GATT服务器,例如你的传感器(或你正在建造的任何东西)。

So, if you want to send a Notification from your device you need 2 things: 因此,如果您想从设备发送通知,则需要两件事:

  1. Create a GATT Server on your smartphone. 在智能手机上创建GATT服务器。
  2. Design your Peripheral to execute GATT Client procedures (Discover Characteristics, Read/Write etc). 设计外围设备以执行GATT客户端程序(发现特性,读/写等)。

This may not be necessary, as @istirbu pointed out. 正如@istirbu指出的那样,这可能没有必要。 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). 外围设备使用通知将信息发送回客户端(例如,Android设备)。 There is no need to send a notification to the device from GATT perspective, you can perform a write operation on a characteristic. 无需从GATT角度向设备发送通知,您可以对特性执行写操作。 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. 由于该写入或任何定期操作,外围设备将以您订阅的相同或其他特征向客户端发回(通知)某些信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM