The GATT client and GATT server use case involves discovering and connecting to nearby Bluetooth Low Energy (BLE) devices. This functionality is essential for scenarios where devices need to establish a secure communication channel over BLE. The use case covers basic situations where one device acts as a GATT server, exposing data and services, while another device acts as a GATT client, initiating the connection and interacting with the server.

  • GATT Server: This device holds data and services that it exposes to connected clients. It advertises its availability and waits for a client to connect. Once connected, it can provide data or services to the client.

  • GATT Client: This device initiates the connection to the GATT server. It scans for nearby servers, and upon discovering one, it establishes a connection to exchange data.

This use case is particularly useful for:

  • Smart home devices: Connecting to and managing smart home gadgets such as lights, thermostats, and security systems.

  • Wearable technology: Pairing with fitness trackers, smartwatches, or health monitors for data synchronization.

Communication model

The GATT Client and GATT Server use case utilizes a connection-oriented communication model. In this model, a direct connection is established between the GATT client (the device that connects) and the GATT server (the device that exposes services and characteristics). This model is essential for structured data transactions and is built on the Generic Attribute Profile (GATT) of the BLE protocol.

In this model, the GATT Server device defines various services, each containing multiple characteristics. These characteristics represent individual pieces of data that can be read or written by the client. The GATT client connects with the server and interacts with these characteristics to retrieve data or send commands.

Key characteristics:

  • Connection requirement: Direct connection is necessary between the GATT client and the GATT server.

  • Data transmission: Bidirectional; both the GATT client and server can send data to each other through the defined characteristics.

  • Advantages: Provides a robust framework for structured and reliable data exchange, suitable for applications requiring precise and consistent data communication. This model is suitable for complex interactions, such as health monitoring devices, where continuous and accurate data exchange is crucial.

BLE Scan and Connect demo

Digi’s BLE Scan and Connect demo covers the goal of this use case showcasing how two XBee 3 BLU devices can be used to establish a secure BLE connection and exchange data. This setup is applicable in real-world scenarios where devices need to connect and exchange information, such as in smart homes or wearable technology environments.

The demo involves two XBee 3 BLU devices configured with specific setups (applied using the Quick Setup feature of XBee Studio). One acts as a GATT server and the other as a GATT client.

diagram
  • One XBee 3 BLU device is configured as a server that listens for incoming BLE connections.

  • The other XBee 3 BLU device is configured as a client that scans for nearby BLE devices and connects to the XBee 3 BLU device acting as server. Once connected, it exchanges data with the server and disconnects.

Requirements

The BLE Scan and Connect demo requires the following components and software:

  • 2 XBee 3 BLU devices.

  • 2 XBIB-C development boards.

  • 2 U.FL antennas.

  • A computer with the XBee Studio application installed.

    • You can download it here.

Set up the hardware

Before testing the demo, ensure the hardware is set up correctly:

  1. Attach each XBee 3 BLU device to the XBee socket of an XBIB-C development board.

  2. In case your devices require antennas, connect each antenna to the antenna connector of the XBee 3 BLU devices:

    1. Align the U.FL antenna with the U.FL female counterpart on the device. Then, press down until you hear a click.

  3. Connect each XBIB-C development board to your computer using USB cables.

  4. Verify that the RSSI (orange LED) on each board is solid.

Apply the BLE Scan and Connect Quick Setup

Follow these steps to configure your XBee 3 BLU devices for the BLE Scan and Connect Quick Setup:

  1. Open XBee Studio and wait for your XBee 3 BLU devices to be automatically discovered.

  2. Access the Quick Setup wizard from the left navigation menu (lightning icon, second option in the list). The wizard page displays.

  3. Select the BLE Scan and Connect Quick Setup from the list of available quick setups.

  4. Click Start. The tab associated with the selected quick setup displays.

    The interactive help may appear if this is the first time you are executing a quick setup. In that case, uncheck the Always show interactive help option and then click anywhere in the screen to close the interactive help.
  5. The Quick Setup tab displays two controls: a list of devices and two role boxes titled Server and Client. Drag and drop one XBee 3 BLU device from the list to the Server role box and the other to the Client role box.

  6. Click Next to continue. The Summary page displays.

  7. Verify one XBee 3 BLU is associated with each role and click Next to continue. The Flash page appears.

  8. The Flash page displays a table with the configuration progress for the selected XBee 3 BLU devices selected in the Quick Setup. When the devices are fully configured, the Test page displays.

  9. Click Evaluate to start testing the Quick Setup. The XBee 3 BLU devices reset and the MicroPython Terminal tab for each device displays.

    The Test page contains a set of instructions to evaluate the Quick Setup, you can skip them as they are explained in this documentation too.

Test the BLE Scan and Connect demo

Once the Quick Setup is applied to the XBee 3 BLU devices, you can test the BLE connection and data exchange:

  1. In the MicroPython Terminal of the XBee 3 BLU configured as server in XBee Studio:

    1. Verify that the device is waiting for connections:

      - Waiting for connection...
  2. In the MicroPython Terminal of the XBee 3 BLU configured as client in XBee Studio:

    1. Verify thath the XBee 3 BLU device has scanned for nearby XBee 3 BLU devices and lists them in a table:

      - Discovered devices:
      +----+-------------------+------------------------------+
      | ID | Address           | Name                         |
      +----+-------------------+------------------------------+
      |  0 | 00:3c:84:fa:b2:0d | XBee Scan-And-Connect        |
      +----+-------------------+------------------------------+
      
      - Enter the ID of the XBee 3 BLU device to connect and press kbd:[Enter] or just press kbd:[Enter] to execute another scan.
    2. Enter the ID of the XBee 3 BLU device running the server application by entering its index and pressing Enter.

      You can recognize it because its name is XBee Scan-And-Connect.
    3. The application asks for the password:

      - Enter the password of the XBee 3 BLU device and press kbd:[Enter]:
    4. Enter the Bluetooth password 1234 to establish the connection and press Enter.

    5. Verify that the client connects, sends a 'Ping' message and receives a 'Pong' response from the server. Then, it disconnects:

      - Connecting with device '00:3c:84:fa:b2:0d'...
      - Connected!
      - Sending 'Ping'...
      - Sent! Waiting for 'Pong'...
      - 'Pong' received from the device!
      - Disconnected from the XBee device.
  3. In the MicroPython Terminal of the XBee 3 BLU configured as server in XBee Studio:

    1. Verify that the client connected, sent a 'Ping' message, the server answered with 'Pong' and the client disconnected:

      - Client connected!
      - 'Ping' received from client. Sending 'Pong'...'
      - 'Pong' sent!'
      - Client disconnected!

Recap

In this chapter, you have successfully configured two XBee 3 BLU devices to operate as GATT Client and GATT Server, demonstrating the structured data transactions enabled by BLE. This feature is essential for applications demanding wireless accurate and reliable data exchange.

Key achievements

As part of this guide, you have:

  • Configured one XBee 3 BLU device to act as a GATT server, exposing services and characteristics.

  • Configured another XBee 3 BLU device to act as a GATT client, connecting to the GATT server.

  • Exchanged data between the GATT client and GATT server, demonstrating bidirectional communication using the characteristics exposed by the server.

Demo components review

Here is a brief explanation of the role of each component that took part in the BLE Scan and Connect demo that covers the functionality of the GATT client and GATT server use case:

Component Role Software used Technology Tasks

XBee 3 BLU device

GATT server

Embedded MicroPython app

  • MicroPython

  • Expose service and characteristics (automatically done by the XBee Bluetooth layer)

  • Advertise a custom name

  • Wait for a client connection

  • Answer with 'Pong' to a 'Ping' message sent by the client

XBee 3 BLU device

GATT client

Embedded MicroPython app

  • MicroPython

  • Scan for BLE devices

  • Securely connect to the GATT server

  • Send a 'Ping' message to the server (writing in its TX characteristic)

  • Wait for a 'Pong' message from the server (reading its RX characteristic)