UM2264
BLE chat
master and slave demo application
DocID030868 Rev 1
31/55
The BLE peripheral and central roles are specified in the
aci_gap_init()
command.
See the BlueNRG-1 BLE API documentation for more information on these and following
commands.
8.1.2
Add service and characteristics
Refer to
Section 7.1.2: "Add service and characteristics"
8.1.3
Start discovery procedure
To find another BlueNRG-1 BLE chat master and slave device in discovery mode, a
discovery procedure must be started via:
aci_gap_start_general_discovery_proc(0x4000, 0x4000, 0x00, 0x00);
8.1.4
Enter connectable mode
The following GAP API command is used for entering general discoverable mode:
aci_gap_set_discoverable(ADV_IND, 0x90, 0x90, PUBLIC_ADDR, NO_WHITE_LIST_USE,
sizeof(local_name), local_name, 0, NULL, 0x6, 0x8);
8.1.5
Connection with chat master and slave client device
In the above mentioned discovery and mode assignment procedures, the two chat master
and slave applications assume respective client and server roles at runtime. During this
initial configuration phase, when a chat master and slave device is placed in discoverable
mode and it is found by the other chat master and slave device performing a discovery
procedure, a Bluetooth low energy connection is created and the device roles are defined.
The following GAP API command is used for connecting to the discovered device:
aci_gap_create_connection(0x4000, 0x4000,device_found_address_type,
device_found_address, PUBLIC_ADDR, 40, 40, 0, 60, 2000 , 2000);
Where
device_found_address_type
is the address type of the discovered chat master
and slave and
device_found_address
is the peer address of the discovered chat
master and slave device.
Once the two devices are connected, you can set up corresponding serial terminals and
type messages in either of them. The typed characters are stored in two respective buffers
and when the return key is pressed:
On the BLE chat master-and-slave server device, the typed characters are sent to the
master-and-slave client device by notifying the previously added TX characteristic (after
notifications have been enabled). This is done via:
aci_gatt_update_char_value(chatServHandle, TXCharHandle, 0, len, (uint8_t *)cmd+j);
On the master-and-slave client device, the typed characters are sent to the master-and-
slave server device, by writing the previously added RX characteristic. This is done via:
aci_gatt_write_without_resp (connection_handle, rx_1, len, (uint8_t
*)cmd+j);
Where
connection_handle
is the handle returned upon connection as a parameter of
the connection complete event,
rx_handle
is the RX characteristic handle discovered by
the client device.
Once these API commands have been sent, the values of the TX and RX characteristics
are displayed on the serial terminals.