본문 바로가기

MCU/ESP32

Bluetooth: GATT Server vs Client

728x90
반응형

ESP32 example에서 GATT Server와 Gatt Client 예제가 있다.

GATT에서의 Server와 Client의 개념이 와닿지가 않았는데,

 

GATT Server는 GATT와 관련된 정보와 서비스를 저장하고 있어서, 해당 디바이스와 연결된 client에게

해당 서비스(와 정보)를 제공해주는 역할이다.

 

GATT Client는 GATT Server에 연결되어 GATT Server에서 제공해주는 서비스를 이용할 수 있는 client

 

블루투스 키보드를 만들고, 해당 블루투스 키보드를 컴퓨터와 연결하여 사용한다면,

블루투스 키보드: GATT Server

컴퓨터: GATT Client

 

아래는 ChatGPT 설명

 
You
In the ESP32 documentations, I saw that GATT Server and GATT Client. I don't understand that concept of server and client of GATT.
 

 

ChatGPT

In Bluetooth Low Energy (BLE), the concepts of GATT Server and GATT Client are fundamental to understanding how data is managed and exchanged between devices. Let's clarify these roles:

GATT Server

The GATT Server is the device that holds the data and services that it might share with other devices. Here are the key points about a GATT Server:

  • Data Storage: It stores data in the form of services, characteristics, and descriptors. Each of these data elements is identified by a UUID (Universally Unique Identifier).
  • Services and Characteristics: Services are collections of data and behavior relating to a specific function (like a Heart Rate Monitor service), and characteristics are data points within those services (like heart rate value).
  • Responds to Requests: The GATT Server responds to read, write, and command requests from the GATT Client. This includes sending notifications or indications when data changes if the client has subscribed to those updates.
  • Example: In the case of an ESP32 used as a BLE keyboard, the ESP32 acts as a GATT Server hosting the Human Interface Device (HID) service. It contains characteristics such as keystroke data that can be read by a connected device.

GATT Client

The GATT Client, on the other hand, is the device that initiates interactions with the GATT Server to read or write data. Here are the important aspects of a GATT Client:

  • Service Discovery: The client discovers services and their associated characteristics and descriptors on the server.
  • Data Manipulation: It sends requests to read from or write data to the server’s characteristics. It can also subscribe to notifications or indications from the server, allowing for real-time data updates.
  • Control Commands: The client can send commands to control the behavior of the server, such as changing the measurement interval of a sensor.
  • Example: A smartphone connecting to a BLE smartwatch. The smartphone acts as a GATT Client, querying the smartwatch for data like step count or heart rate.

Interaction Between GATT Server and Client

In a typical interaction:

  • The GATT Client starts by scanning for devices and connecting to a GATT Server.
  • Once connected, the client performs service discovery to find out what services and characteristics are available on the server.
  • The client can then read or write to these characteristics, depending on its needs and the permissions set on the server’s characteristics.
  • The server, depending on the characteristic’s properties, may also send updates to the client (via notifications or indications) without a direct request, if the client has configured it to do so.

Practical Example with ESP32

If you use an ESP32 to build a BLE device:

  • As a GATT Server, it might advertise services like environmental sensing. It stores and manages the data (like temperature readings), responding to read/write requests from clients.
  • As a GATT Client (less common for ESP32 but possible), it could connect to another BLE device like a BLE heart rate monitor. It would use the monitor's services to read heart rate data or configure settings.

Conclusion

Understanding the roles of GATT Server and Client is crucial for designing and implementing BLE applications, as it defines how devices interact and manage data in a BLE environment. Each role has specific responsibilities and capabilities that enable the versatile, low-energy communications in BLE networks.

728x90
반응형