# Perform Bluetooth Low Energy GATT server functions

Source: [https://docs.qualcomm.com/doc/80-70017-13/topic/perform_ble_gatt_server_functions.html](https://docs.qualcomm.com/doc/80-70017-13/topic/perform_ble_gatt_server_functions.html)

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

## About this task

Before you begin:

## Procedure

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 via 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-70017-13/topic/gatt_config_params.html#references_1__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.txtCopy 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.txtCopy to clipboard

This command ensures that the newly added or modified parameters are
                                reflected 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-70017-13/topic/gatt_config_params.html#references_1__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.txtCopy 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.txtCopy to clipboard

This command ensures that the modified parameters are reflected 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-70017-13/topic/set_up_ble_gatt.html#set_up_ble_gatt_client__context_o3z_5dt_s1c).

**Parent Topic:** [General Attribute Profile](https://docs.qualcomm.com/doc/80-70017-13/topic/set_up_ble_gatt.html)

## Start Bluetooth Low Energy GATT server

Source: [https://docs.qualcomm.com/doc/80-70017-13/topic/perform_ble_gatt_server_functions.html](https://docs.qualcomm.com/doc/80-70017-13/topic/perform_ble_gatt_server_functions.html)

### About this task

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-70017-13/topic/perform_ble_gatt_server_functions.html#perform_ble_gatt_server_functions__step_gsp_htz_jbc_navyanka_05-14-24-1050-31-902) and [advertiser configuration file](https://docs.qualcomm.com/doc/80-70017-13/topic/perform_ble_gatt_server_functions.html#perform_ble_gatt_server_functions__step_jlx_hvz_jbc_navyanka_05-14-24-1105-51-83).

### Procedure

1. Read the `ServerConfigFile.txt` file by running the
                        following command:
                    
gattstest_init_serverCopy 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 DoneCopy to clipboard
2. Add a server instance by running the following command:
                    
gattstest_addserversCopy 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-70017-13/topic/gatt_config_params.html#references_1__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 1Copy to clipboard

**Sample output**

gattstest_addservers
        Adding Server 1
        gattstest_addservices 1 1
        AddServicesCopy to clipboard
4. Initialize the GATT advertiser by running the following command:
                    
gattstest_init_advertiserCopy to clipboard
5. Advertise the server that is added and configured by running the following
                        command: 
                    
gattstest_start_advertiser <server instance>Copy to clipboard

**Example**

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

        gattstest_start_advertiser 1Copy 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:50Copy to clipboard

## Read and set PHY parameters

Source: [https://docs.qualcomm.com/doc/80-70017-13/topic/perform_ble_gatt_server_functions.html](https://docs.qualcomm.com/doc/80-70017-13/topic/perform_ble_gatt_server_functions.html)

### About this task

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

### Procedure

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 1Copy 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: 0Copy 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-70017-13/topic/gatt_config_params.html#references_1__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 0Copy 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: 0Copy to clipboard

## Disconnect a remote device

Source: [https://docs.qualcomm.com/doc/80-70017-13/topic/perform_ble_gatt_server_functions.html](https://docs.qualcomm.com/doc/80-70017-13/topic/perform_ble_gatt_server_functions.html)

### About this task

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:50Copy 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:50Copy to clipboard

## Stop Bluetooth Low Energy GATT server

Source: [https://docs.qualcomm.com/doc/80-70017-13/topic/perform_ble_gatt_server_functions.html](https://docs.qualcomm.com/doc/80-70017-13/topic/perform_ble_gatt_server_functions.html)

### About this task

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 1Copy to clipboard

Last Published: Dec 26, 2024

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