BLE

This chapter explains the BLE (Bluetooth Low Energy) functionalities of Audio Agent 6.

General BLE functionalities

Enable / Disable BLE

BLE is enabled by default. The number of connection supported is specified in the PROFILES config. Only 1 connection is possible in Peripheral mode and up to 3 in Central mode. When set to 0 BLE is disabled.

BLE states

There are four BLE states. The current state can be known using the STATUS command:

  • OFF - BLE disabled

  • IDLE - wait for user action (advertising, connect..)

  • ADVERTISING – Audio Agent is advertising (Peripheral or Beacon only)

  • CONNECTED – at least one BLE connection is established

BLE roles

Audio Agent supports three BLE roles:

  • Peripheral (server)

  • Central (client)

  • Beacon (iBeacon / Eddystone)

The BLE BLE role is set in BLE_CONFIG. When the role is changed, all BLE connections are closed.

Connection, advertising and scanning parameters

The BLE connections parameters can be modified by changing the values in the parameter BLE_CONN_PARAMS. Theses parameters are used by Audio Agent to set the following:

  • Advertising parameters. This will control how Audio Agent advertises (fast advertisements or slow advertisements). While fast advertisements allow remote devices to see and connect to audio agent faster (audio agent will be consuming more power), slow advertisements will reduce the power consumption and make the scanning and connection slower.

  • Scanning parameters. This will control audio agent scanning intervals. As in advertising, fast scanning will find more devices with higher power consumption, and slow scanning will require more time to find the required device, but with lower power consumption.

  • Connection parameters. Once a BLE link is established, the connection parameters control how often and quick the data transfer is. For example to achieve a higher data rate or lower the power consumption.

The parameters are the following:

  • scan_interval: The time interval from when BC-127 started its last LE scan until it begins the subsequent LE scan. Scan interval in units of 0.625 ms. The allowed range is between 4 (2.5 ms) and 16384 (10240 ms).

  • scan_window: Amount of time for the duration of the LE scan. LE Scan Window shall be less than or equal to LE Scan Interval. Scan window in units of 0.625 ms. The allowed range is between 4 (2.5 ms) and 16384 (10.240 s).

  • conn_interval_min: Minimum value for the connection event interval. This shall be less than or equal to Connection Interval Max. Connection interval in units of 1.25 ms. The allowed range is between 6 (7.5 ms) and 3200 (4 s).

  • conn_interval_max: Maximum value for the connection event interval. This shall be greater than or equal to Connection Interval Min. Connection interval in units of 1.25 ms. The allowed range is between 6 (7.5 ms) and 3200 (4 s).

  • conn_latency: Slave latency for the connection in number of connection events. The allowed range is between 0 and 500.

  • supervision_timeout: The timeout before disconnecting when no communication is present on the lower layers. Supervision timeout in units of 10 ms. The allowed range is between 10 (100 ms) and 3200 (32 s).

  • conn_attempt_timeout: Time to wait for connection to be fully established. Changing this value can reduce the number of successful connection.

  • adv_interval_min: Minimum advertising interval for non-directed advertising. Audio Agent does not support directed advertisements. Range: 32 - 16384.

  • adv_interval_max: Maximum advertising interval for non-directed advertising. Range: 32 - 16384.

  • conn_latency_max: Maximum allowed slave latency that is accepted if slave requests connection parameter update once connected.

  • supervision_timeout_min: Minimum allowed supervision timeout. The minimum allowed supervision timeout that is accepted if slave requests connection parameter update once connected.

  • supervision_timeout_max: Maximum allowed supervision timeout. The maximum allowed supervision timeout that is accepted if slave requests connection parameter update once connected.

Advertising data

The ADVERTISING command can be used start/stop advertising or to modify the advertising data. If the advertising data is not modified by the user, default values are used. The SSRD command allows the user to set the scan response data.

Random address

By default Audio Agent use a random BLE address. This is necessary to make it work with android. It can be disabled in BLE_CONFIG.

MTU

The maximum MTU (Maximum transmission unit) value supported is set in BLE_CONFIG. When the connection is established the MTU is negotiated with the remote device. The value negotiated is displayed in the STATUS command’s result.

BLE data mode

When using the BC Smart service (enabled by default), it possible to enter in Data mode to transfer data up to 7.2kbps.

BC Smart service

The BC Smart service can be used to send seamlessly data and commands over BLE (see BC Smart example). The UUIDs of the BC Smart service and its Data characteristic are store in the parameter BC_SMART_CONFIG.

Peripheral role

1 - Set Advertising data and scan response (optional)

The default advertising data includes NAME_SHORT and the BC Smart service UUID. It can be changed by the user with the ADVERTISING command. The scan response data can be set using the SSRD command.

2 – Set GATT database (optional)

Audio Agent uses a default GATT database including the GAP, GATT and BC Smart services. It can be changed by the user using BLE_SET_DB command in order to support other BLE profiles. The values expected by this command can be generated with the db_gen library which is available on our website in the Tool sections (Tools/Audio Agent BLE db gen). The modified database is not persistent and should be set every time after a reset.

3 – Start advertising

Use the ADVERTISING command to start or stop advertising.

4 – Wait for Central device to connect

When Audio Agent is advertising, a Central device can see it and initiate a connection.

5 – Send and receive data

Audio Agent has generic commands and notifications in order to be able to work any BLE profile:

Commands:

  • BLE_NOTIFICATION: Send a notification to the remote device

  • BLE_INDICATION: Send an indication to the remote device

  • BLE_READ_RES: Send a read response to the remote device

Notifications:

  • BLE_WRITE: Write indication received from remote device

  • BLE_READ: Read request received from remote device. Must reply with BLE_READ_RES command.

If the database is not changed by the user, the functionalities relative to the BC Smart services can be used:

  • Sending and receiving data with SEND, SEND_RAW commands and RECV notification or in Data mode

  • Handling commands over BLE and sending command responses

6 – Close connection

The BLE connection can be closed by the remote device or using the CLOSE command.

Central role

1 – Scan

The SCAN command is used to see the advertising devices in the area. Audio Agent sends a SCAN notification for each device found with its Bluetooth address and the type of address (public or random).

2 – Initiate connection with Peripheral

With the informations retrieved from the SCAN notification (address and type) you can initiate a connection with the OPEN command.

3 – Service / Characteristic discovery

Once connected, the BLE_GET_SERV and BLE_GET_CHAR commands can be used to discover the services and characteristics of the remote device. It gives the handles of the services and characteristics supported by the remote server.

4 – Send/Receive data

The following generic commands and notifications can be used communicate with the remote device (See BLE central example.):

Commands:

  • BLE_READ: Request to read a characteristic value

  • BLE_WRITE: Write a characteristic value

Notifications:

  • BLE_READ_RES: Read response received from remote device

  • BLE_NOTIFICATION: Notification received from remote device

  • BLE_INDICATION: Indication received from remote device

If the remote device supports the BC Smart service, the following commands and notifications can also be used:

BC Smart commands:

  • BC_SMART_NOTIF: Enable/Disable BC Smart notifications

  • BC_SMART_COMMAND: Send a command over BLE

  • SEND/SEND_RAW/ENTER_DATA_MODE: Send data

BC Smart notification:

  • RECV: Data or command response received

5 – Close connection

The BLE connection can be closed by the remote device or using the CLOSE command.

Beacon role

Three types of Beacons are supported: iBeacon, Eddystone UID and Eddystone URL. The type of Beacon and its parameters are set in BEACON_DATA (see Beacon example). Just like with the Peripheral role, the ADVERTISING command can be used to start and stop advertising.

Beacon data

iBeacon

0

ProximityUUID
(16 bytes)
Major
(2 bytes)
Minor
(2 bytes)
Tx Power
(1 byte)

Eddystone-UID

1

Namespace
(10 bytes)
Instance
(6 bytes)
Tx Power
(1 byte)
unused
(4 bytes)

Eddystone-URL

2

Tx Power
(1 byte)
Prefix
(1 byte)
encoded URL
(17 bytes)