简体   繁体   English

Android:蓝牙低功耗GATT配置文件

[英]Android: Bluetooth Low Energy GATT Profile

I am looking to send information from my Android device to a micro-controller (such as an Arduino). 我希望从我的Android设备发送信息到微控制器(如Arduino)。 Using Bluetooth Classic I simply send a byte array of data to the micro-controller, and process the byte array accordingly. 使用蓝牙经典我只需将一个字节数组数据发送到微控制器,并相应地处理字节数组。

I started reading about Bluetooth Low Energy and I am hearing all this talk about GATT profiles. 我开始阅读有关蓝牙低功耗的内容,我听到所有关于GATT配置文件的讨论。 Why should I create a GATT profile? 我为什么要创建GATT档案? What is a GATT profile going to do for me in the case of exchanging information from an Android device to a micro-controller? 在将信息从Android设备交换到微控制器的情况下,GATT配置文件会为我做什么?

Thanks in advance! 提前致谢!

GATT profiles are a way to communicate between Bluetooth central and Peripheral. GATT配置文件是蓝牙中央和外围设备之间通信的一种方式。 Lets assume I have an app that reads temperature from a sensor. 让我们假设我有一个从传感器读取温度的应用程序。 My current setup is to have the phone act as central, the sensor attached to a bluetooth LE chip as peripheral. 我目前的设置是让手机充当中央,传感器连接到蓝牙LE芯片作为外设。

So I communicate to bluetooth LE chip using this profile. 所以我使用这个配置文件与蓝牙LE芯片通信。 In GATT profile declaration in chip, I will be defining a service and two characteristics. 在芯片中的GATT配置文件声明中,我将定义一个服务和两个特性。 Two characteristics being 有两个特点

  1. Sensor enabler 传感器启动器
  2. Temperature value 温度值

Sensor enabler has both read and write permissions, while temperature value has only read permission. 传感器启用程序具有读取和写入权限,而温度值仅具有读取权限。

So in your app, whenever you want to read temperature value, you first write 0x01 to enabler characteristic and then read value from temperature value. 因此,在您的应用程序中,每当您想要读取温度值时,首先将0x01写入启动器特性,然后从温度值读取值。

To identify the characteristics and services, bluetooth has the concept of UUIDs and handles. 为了识别特征和服务,蓝牙具有UUID和句柄的概念。 UUIDs are globally unique and handles are assigned in the chip. UUID是全局唯一的,并且在芯片中分配了句柄。

Services encapsulate the characteristics available. 服务封装了可用的特征。 So in a hierarchy you have, Profiles which can multiple services which in turn can have multiple characteristics. 因此,在您拥有的层次结构中,可以使用多个服务的配置文件,这些服务又可以具有多个特征。

To explain everything in an answer would be too much. 解释答案中的所有内容太多了。 Why don't you go through the basics here ? 你为什么不经历这里的基础知识? I found these documents really useful. 我发现这些文件非常有用。

The whole concept of Bluetooth Low Energy is to use the less power for transmission between two Bluetooth devices. 蓝牙低功耗的整个概念是在两个蓝牙设备之间使用较少的功率进行传输。 In order to achieve this one can not use the traditional Bluetooth classic which keeps the channel even though the data transmission is not done. 为了实现这一点,即使没有进行数据传输,也不能使用传统的蓝牙经典版本来保持频道。 Hence, the concept of ATT/GATT evolved which provides the specifications to transfer the short data packets over BLE link between two Low Energy devices. 因此,ATT / GATT的概念得到了发展,其提供了在两个低能量设备之间通过BLE链路传输短数据分组的规范。 Due to which when two devices are not communicating then will be as good as stopped. 由于当两个设备没有通信时,它将与停止一样好。 In order to implement the BLE services one has to use these ATT/GATT profiles & protocols. 为了实现BLE服务,必须使用这些ATT / GATT配置文件和协议。

GATT provides the specification on how a group of attributes(which are nothing but data) are grouped together into meaningful services. GATT提供了关于如何将一组属性(除了数据之外的任何属性)组合成有意义的服务的规范。 It does the common operations of data transfer & storing over ATT by defining its own client-server mechanism. 它通过定义自己的客户端 - 服务器机制来完成通过ATT进行数据传输和存储的常见操作。 It makes developers life easy by defining whole framework for you & one just need to group these characteristics & services by customizing for developing there profiles & applications. 它通过为您定义整个框架,使开发人员生活变得简单,只需要通过定制开发那些配置文件和应用程序来对这些特性和服务进行分组。

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

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