BlueNRG-1 sensor
profile demo
UM2264
36/55
DocID030868 Rev 1
10.2.2
Add service and characteristics
The BlueNRG-1 BLE stack has both server and client capabilities. A characteristic is an
element in the server database where data is exposed, while a service contains one or
more characteristics. The acceleration service is added with the following command:
aci_gatt_add_service(UUID_TYPE_128, &service_uuid, PRIMARY_SERVICE, 7,
&accServHandle);
The command returns the service handle on variable
accServHandle
. The free fall and
acceleration characteristics must now be added to this service thus:
aci_gatt_add_char(accServHandle, UUID_TYPE_128, &char_uuid, 1, CHAR_PROP_NOTIFY,
ATTR_PERMISSION_NONE, 16, 0, &freeFallCharHandle);
aci_gatt_add_char(accServHandle, UUID_TYPE_128, &char_uuid, 6,
CHAR_PROP_NOTIFY|CHAR_PROP_READ, ATTR_PERMISSION_NONE,
GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP, 16, 0, &accCharHandle);
The free fall and acceleration characteristics handles are returned on
freeFallCharHandle
and
accCharHandle
variables respectively.
Similar steps are followed for adding the environmental sensor and relative characteristics.
10.2.3
Enter connectable mode
Use GAP API command to enter one of the discoverable and connectable modes:
aci_gap_set_discoverable(ADV_IND, (ADV_INTERVAL_MIN_MS*1000)/625,
(ADV_INTERVAL_MAX_MS*1000)/625, STATIC_RANDOM_ADDR, NO_WHITE_LIST_USE
sizeof(local_name), local_name, 0, NULL, 0, 0);
Where
local_name[] = {AD_TYPE_COMPLETE_LOCAL_NAME,'B','l','u','e','N','R','G'};
The
local_name
parameter contains the name presented in advertising data, as per
Bluetooth core specification version, Vol. 3, Part C, Ch. 11.
10.2.4
Connection with central device
Once the BlueNRG-1 BLE stack is placed in discoverable mode, it can be detected by a
central device. The smartphone app described in
Section 10.1: "BlueNRG app for
is designed to interact with the sensor profile demos (it also supports the
BlueNRG-1 device).
Any Bluetooth smart or Bluetooth smart ready device like a smartphone can connect to the
BlueNRG-1 BLE sensor profile demo.
For example, the LightBlue application in Apple Store
®
(iPhone
®
versions 4S/5 and above)
can connect to the sensor profile device. When you use the LightBlue application, detected
devices appear on the screen with the BlueNRG name. By tapping on the box to connect to
the device, a list of all the available services is shown on the screen; tapping a service
shows the characteristics for that service.
The acceleration characteristic can be notified using the following command:
aci_gatt_update_char_value(accServHandle, accCharHandle, 0, 6, buff);
Where
buff
is a variable containing the three axes acceleration values.
Once this API command has been sent, the new value of the characteristic is displayed on
the phone.