# Perform Bluetooth Low Energy GATT server functions

You can perform Bluetooth Low Energy GATT server functions using the
`gattstest_menu` options.

Before you begin:

1. Configure the Bluetooth Low Energy GATT server in the command prompt as follows:

    1. Pull the server configuration file, `ServerConfigFile.txt`, by running the following command:

scp -r root@<IP_address>:/etc/bluetooth/ServerConfigFile.txt <destination_file_path>
            Copy to clipboard

        To pull a file to the current file path, enter the `<destination_file_path>` as `.` in the command.

Note

When prompted for a password, enter `oelinux123` to authenticate a file transfer through the Secure Copy Protocol (SCP).

        **Example**

        The IP address of the device is `10.92.160.222`. To pull the `ServerConfigFile.txt` file from the `/etc/bluetooth/` directory of the device, run the following command:

scp -r root@10.92.160.222:/etc/bluetooth/ServerConfigFile.txt .
            Copy to clipboard

        For more information about the server configuration file, see [GATT server configuration parameters](https://docs.qualcomm.com/doc/80-70018-13/topic/gatt_config_params.html#section-jsr-3lq-m1c).
    2. Configure or add services, characteristics, and descriptors for the servers in the file, as required.
    3. Push the modified server configuration file to the device by running the following command:

scp -r ServerConfigFile.txt root@<IP_address>:/etc/bluetooth/ServerConfigFile.txt
            Copy to clipboard

        **Example**

        The IP address of the device is `10.92.160.222`. To push the `ServerConfigFile.txt` file back to the device, run the following command:

scp -r ServerConfigFile.txt root@10.92.160.222:/etc/bluetooth/ServerConfigFile.txt
            Copy to clipboard

        This command ensures that the newly added or modified parameters reflect in the device.

2. Configure the Bluetooth Low Energy GATT advertisement in the command prompt as follows:

    1. Pull the advertiser configuration file, `AdvertiserConfigFile.txt`, by running the following command:

scp -r root@<IP_address>:/etc/bluetooth/AdvertiserConfigFile.txt <destination_file_path>
            Copy to clipboard

        To pull a file to the current file path, enter the `<destination_file_path>` as `.` in the command.

        **Example**

        The IP address of the device is `10.92.160.222`. To pull the `AdvertiserConfigFile.txt` file from the `/etc/bluetooth/` directory of the device, run the following command:

scp -r root@10.92.160.222:/etc/bluetooth/AdvertiserConfigFile.txt .
            Copy to clipboard

        For more information about the advertiser configuration file, see [GATT server configuration parameters](https://docs.qualcomm.com/doc/80-70018-13/topic/gatt_config_params.html#section-jsr-3lq-m1c).
    2. Configure the advertising parameters in the file, as required.
    3. Push the modified advertiser configuration file to the device by running the following command:

scp -r AdvertiserConfigFile.txt root@<IP_address>:/etc/bluetooth/AdvertiserConfigFile.txt
            Copy to clipboard

        **Example**

        The IP address of the device is `10.92.160.222`. To push the `AdvertiserConfigFile.txt` file back to the device, run the following command:

scp -r AdvertiserConfigFile.txt root@10.92.160.222:/etc/bluetooth/AdvertiserConfigFile.txt
            Copy to clipboard

        This command ensures that the modified parameters reflect in the device.
3. Set up the device and go to the GATT server menu as described in [Set up device for Bluetooth Low Energy GATT functions](https://docs.qualcomm.com/doc/80-70018-13/topic/set_up_ble_gatt.html#context-o3z-5dt-s1c).

## Start Bluetooth Low Energy GATT server

To start the Bluetooth Low Energy GATT server, do the following:

Note

Ensure that you configure the [server configuration file](https://docs.qualcomm.com/doc/80-70018-13/topic/perform_ble_gatt_server_functions.html#step-gsp-htz-jbc-navyanka-05-14-24-1050-31-902) and [advertiser configuration file](https://docs.qualcomm.com/doc/80-70018-13/topic/perform_ble_gatt_server_functions.html#step-jlx-hvz-jbc-navyanka-05-14-24-1105-51-83).

1. Read the `ServerConfigFile.txt` file by running the following command:

gattstest_init_server
        Copy to clipboard

    **Sample output**

gattstest_menu
        
        ***************** Menu *******************
                 gattstest_init_server (only for Init time)
                 gattstest_addservers
                 gattstest_addservices<space><server instance><space><service instance>
                 gattstest_init_advertiser initialzes advertiser
                 gattstest_start_advertiser<space><server instance>
                 gattstest_readphy<space><remote address><server instance>
                 gattstest_set_preferred_phy<space><remote address><space><server instance><space><tx phy><space><rx phy><space><phy opt>
                 gattstest_stop<space><server_instance>
                 gattstest_disable
                 gattstest_cancel_connection<space><remote address>
                 gattstest_unregister_server<space><server instance>
                 main_menu
        ******************************************
        gattstest_init_server
        ENABLE GATTSTEST
        Initializing Gattstest
        Reading Server Configuration File ....
        File reading Done
        Copy to clipboard
2. Add a server instance by running the following command:

gattstest_addservers
        Copy to clipboard
3. Add a service to this server instance by running the following command:

gattstest_addservices <server instance> <service instance>
        Copy to clipboard

    In this command, the server instance is followed by the service instance that must be added to it. The service number is mentioned in the `ServerConfigFile.txt`. For more information, see [GATT server configuration parameters](https://docs.qualcomm.com/doc/80-70018-13/topic/gatt_config_params.html#section-jsr-3lq-m1c).

    **Example**

    To add the service `1` recorded in the `ServerConfigFile.txt` file to the newly created server `1`, run the following command:

gattstest_addservices 1 1
        Copy to clipboard

    **Sample output**

gattstest_addservers
        Adding Server 1
        gattstest_addservices 1 1
        AddServices
        Copy to clipboard
4. Initialize the GATT advertiser by running the following command:

gattstest_init_advertiser
        Copy to clipboard
5. Advertise the server that’s added and configured by running the following command:

gattstest_start_advertiser <server instance>
        Copy to clipboard

    **Example**

    To advertise a server instance `1` that’s added and configured, run the following command:

gattstest_start_advertiser 1
        Copy to clipboard
6. After the device starts advertising, connect it from the Bluetooth Low Energy application on another device.

    **Sample output**

gattstest_start_advertiser 1
        StartAdvertisement
        onAdvertisingSetStarted - Success
        The device 22:22:85:3d:2e:50 got connected
        ACL state:0 change with reason 00 for device: 22:22:85:3d:2e:50
        Copy to clipboard

## Read and set PHY parameters

To read and set the PHY parameters, do the following:

1. Read the PHY parameters of the current connection by running the following command:

gattstest_readphy <remote address> <server instance>
        Copy to clipboard

    **Example**

    The server instance `1` is advertised for a remote device with the address `22:22:85:3d:2e:50`. To read the PHY parameters of this connection, run the following command:

gattstest_readphy 22:22:85:3d:2e:50 1
        Copy to clipboard

    **Sample output**

gattstest_readphy 22:22:85:3d:2e:50 1
        Read Phy
        User input is 22:22:85:3d:2e:50
        
        onPhyRead deviceAddress: 22:22:85:3d:2e:50, txPhy: 1 rxPhy: 1 status: 0
        Copy to clipboard
2. Set the preferred PHY of the current connection by running the following command:

gattstest_set_preferred_phy <remote address> <server instance> <tx Phy> <rx Phy> <Phy option>
        Copy to clipboard

    For more information about the PHY parameters, see [GATT server configuration parameters](https://docs.qualcomm.com/doc/80-70018-13/topic/gatt_config_params.html#section-jsr-3lq-m1c).

    **Example**

    A remote device with the address `22:22:85:3d:2e:50` is connected to the server instance `1`. To set Tx PHY as `1 M`, Rx PHY as `1 M`, and PHY option as `0` for this connection, run the following command:

gattstest_set_preferred_phy 22:22:85:3d:2e:50 1 1 1 0
        Copy to clipboard

    **Sample output**

gattstest_set_preferred_phy 22:22:85:3d:2e:50 1 1 1 0
        Set Preferred Phy
        the user options are address: 22:22:85:3d:2e:50 server_instance: 1 txoption: 1 rxoption: 1 phyoption: 0
        Copy to clipboard

## Disconnect a remote device

To disconnect a remote device, run the following command:

gattstest_cancel_connection <remote address>
    Copy to clipboard

**Example**

To disconnect a remote device with the address `22:22:85:3d:2e:50`, run the following command:

gattstest_cancel_connection 22:22:85:3d:2e:50
    Copy to clipboard

**Sample output**

gattstest_cancel_connection 22:22:85:3d:2e:50
    Cancel Connection
    The device 22:22:85:3d:2e:50 got disconnected
    ACL state:1 change with reason 16 for device: 22:22:85:3d:2e:50
    Copy to clipboard

## Stop Bluetooth Low Energy GATT server

To stop advertising a Bluetooth Low Energy GATT server instance, run the following command:

gattstest_stop <server_instance>
    Copy to clipboard

**Example**

To stop the server instance `1`, run the following command:

gattstest_stop 1
    Copy to clipboard

Last Published: Apr 02, 2025

[Previous Topic
General Attribute Profile](https://docs.qualcomm.com/bundle/publicresource/80-70018-13/topics/set_up_ble_gatt.md) [Next Topic
Perform Bluetooth Low Energy GATT client functions](https://docs.qualcomm.com/bundle/publicresource/80-70018-13/topics/perform_ble_gatt_client_functions.md)