In the previous article
Exploring BLE through nRF51 DK development board, we mentioned briefly about BLE and nRF51-dk. In this article we will be explaining two important concepts which are required to code a bluetooth application.
Before that you should know that bluetooth network model is based on
'proximity networking' which implies that when two devices come into range of each other, they are capable of establishing a connection.
The advertising takes place in following ways:
1. GAP:
GAP is an acronym of
Generic Access Profile, it is used to control the advertising and defines various roles of the devices.It is responsible for your device to be visible to the outer world.
Devices can be divided in the following two roles:
1. Peripheral : These devices are small and are restricted to lesser resources. They are used to connect to much more powerful central devices. eg: heart rate monitoring watches, beacons.
2. Central: These devices are with greater processing power and memory. eg: phones, tablets etc.
There are two ways to send advertising out with GAP. The
Advertising Data payload and the
Scan Response payload.
Peripheral Devices sets an advertising interval , and sends the advertising data in that duration. The
Advertising Data is essential for peripheral device , as it signifies its existence to any nearby listening devices.
Scan Response is sent out by central device , if required for additional information from the peripheral.
During advertising process, a single peripheral advertising data can be scanned by two or more central devices as shown in the figure below.This is known as
broadcasting.
Figure 1 Broadcast Topology
In our project we are using
beacons. Please visit the first link to know what are beacons and how do they work.
Beacons advertise themselves by sending advertising data, which can be of 47 bytes in length and consist of :
1 byte preamble
4 byte access address
2-39 bytes advertising channel PDU
3 bytes CRC
Figure 2 Advertised Data
As shown in the figure above PDU contains header, MAC and Data upto 31 bytes.
The Data of 31 bytes contains Beacon prefix, Proximity UUID , Major , Minor and TX power as shown in the figure.
Figure 3 Inside the Data Bytes
Our task was to scan the beacons using nRF51-dk. We used the example
code BLE_Observer , which scans the beacons and returns the values of MAC address, RSSI, Scan response , Advertising type,Proximity UUID , Major , Minor and TX power .
The main purpose of peripheral to advertise is to establish a connection with the central device.
Once the connection occurs advertising process ends and we use GATT services and characteristics to communicate in both directions.
BLE devices can operate in a
non-connectable advertisement-only mode
(where all the information is contained in the advertisement), but they
can also allow connections (and usually do).
In our project , we are using only GAP and we have used it in our scanner.
2. GATT:
GATT is an acronym for the
Generic Attribute Profile, and it defines the
way that two Bluetooth Low Energy devices transfer data back and forth
using concepts called
Services and
Characteristics.
As mentioned above, GATT comes into play once a connection is established.
Now comes the interesting part, as said peripheral device can be scanned by two or more central devices. But once a connection is established , peripheral cannot advertise anymore and communicates with a single central device.
But a central device is capable of establishing connection with two or more peripheral devices. This kind of topology is called Connected Network Topology.
|
Figure 4 Connected Topology |
An important concept which comes into play in GATT is server/client relationship.
We would recommend you to visit the second link mentioned below to understand the concept.
Useful/ Recommended Links:
http://www.pointrlabs.com/blog/beacons-everything-you-need-to-know/
https://learn.adafruit.com/introduction-to-bluetooth-low-energy/gatt