The history of Bluetooth
Bluetooth technology was originally developed by Ericsson. The technology began with Ericsson’s 1994 project to develop a method of low-power, low-cost wireless communication between mobile phones and other accessories. The inventors hope to create a set of uniform rules (standardized protocols) for communication between devices to address incompatible mobile devices.
On May 20, 1998, SONY established the “Special Interest Group SIG”, the predecessor of Bluetooth Technology Alliance, with the leading members of the industry such as Lixin, INTERNATIONAL Business Machines, Intel, Nokia and Toshiba. The goal is to develop a low cost, high efficiency bluetooth technology standard that can be freely connected in a short distance. The international organization responsible for the development and promotion of bluetooth specifications.
The 0.7 spec was introduced in 1998, followed by 0.8, 0.9 and so on in 1999. Version 1.0 was officially released in July 1999, using the 2.4ghz spectrum with a maximum data transmission speed of 1Mbps. Version 1.1 of 2001 was officially included in the IEEE standard.
Bluetooth is actually a near field communication technology.
- Bluetooth Low Energy BLE is short for Bluetooth Low Energy. The main feature is low power consumption. Some BLE devices can last a year or two with a single button battery. This is a big breakthrough for current wearable devices and various iot sensors. It also transmits very little data.
- Bluetooth low power support began in Android 4.3. Supports only central mode, which means only other Bluetooth peripherals can be connected. In 2014, Android 5.0 also supported peripheral mode.
Protocol stack
Image from Internet
From bottom to top: Controller –> host –> Application
Controller: the implementation of the bottom layer of the protocol stack, directly related to the hardware, implemented by chip manufacturers, including the physical layer, link layer, host control interface.
Host: The upper implementation of the protocol stack is a hardware abstraction, independent of the specific hardware vendor.
Application layer: Applications developed using apis provided by the host layer.
Describe the meaning of each layer in detail:
- PHY (Physical Layer) : Bluetooth works in the vicinity of 2.4GHz, which is the frequency band of industrial, scientific, and medical ISM. WIFI also works on the same frequency band. Bluetooth divides the frequency band into 40 channels, including 3 broadcast channels and 37 data channels, according to a regular frequency hopping communication.
- LL (Linker Layer) controls the RADIO status of the device. The device is in one of five states: Waiting, advertising, scanning, initializing, and connecting. The broadcast device can send data without establishing a connection, while the scanning device accepts the data sent by the broadcast device. The device that initiates the connection responds to the broadcast device by sending a connection request. If the broadcast device accepts the request, the broadcast device and the device that initiates the connection enter the connection state. The device that initiates the connection is called the host, and the device that accepts the connection request is called the slave.
- Host Controller Interface (HCI) : A Host communicates with a Controller through the HCI command. This layer is optional in the protocol stack. Some small terminals may not have it, but Android devices certainly have it. This layer is the only way for the bluetooth upper layer to interact with the chip.
- The HOST part is complicated. There are link control and Adaptation layer (L2CAP), security management (SM) and so on. Focus on the attribute protocol layer, also known as ATT. It is the basis of the entire BLE communication. ATT is responsible for data encapsulation, exposing it to the outside as “attributes”, providing “attributes” for the server, and obtaining “attributes” for the client. ATT is a transmission protocol specially designed for BLE low power Bluetooth, with simple structure and short data transmission.
- Generic Attribute Profile (GATT) : The Generic Attribute Profile (GATT) is a further logical encapsulation based on ATT that defines the interaction mode and meaning of data. APP development uses this layer. GATT defines three very important concepts: services, characteristics, and Descripter. Their relationship is shown below
A Service can contain several characteristics. a Characteristic can contain properties and values, and also multiple descripters. Characteristic actually has permissions to read, write, notify, etc. After we successfully initiate a connection to a BLE device, we carry out read and write operations on it, which are actually Characteristic operations. The Profile in the figure is a collection of services that together form a specific usage scenario for which embedded workers can add services. BLE Bluetooth uses UUID to distinguish Service, Characteristic, and Descripter.
- The Generic Access Profile (GAP) is a Generic Access control Profile. Defines the flow of the BLE communication process, which is responsible for handling device access patterns and procedures, including device discovery, connection establishment, connection termination, and so on. The GAP layer always acts as one of the following four roles: (1) broadcaster: unconnectable broadcast device. (2) Observer: scans the device, but does not initiate a connection. (3) External device: a connectable broadcast device that can be used as a slave machine in a single link layer connection. (4) Concentrator: scans broadcast devices and initiates connections, which can be used as a host in a single link layer connection.
Application development
BLE applications can be divided into two broad categories: connection-based and connection-based
Based on unconnected:
This means that there is no connection between peripherals and peripheral devices, and information is obtained mainly by scanning broadcast. The party that delivers the broadcast is called broadcaster and the party that listens to the broadcast is called Oberver. There is a corresponding role definition in the GAP layer.
Network topology:
In this way, the broadcast device continuously sends out a broadcast (containing a specific message), which is then received by the observer and parsed according to the agreed protocol between the two to obtain useful information. For example, iBeacon, through which we can achieve indoor positioning.
In fact, the role of these devices can be both the broadcaster and the observer. The broadcast was received, processed, and then sent. This creates a bidirectional network, similar to the Internet, known as bluetooth Mesh networking.
Broadcast packet format:
Each broadcast packet consists of 31 bytes. It is divided into valid data and invalid data.
- Invalid data: Because the broadcast packet must be 31 bytes long, if there are less than 31 bytes of valid data then the rest is filled with zeros. This part is invalid, that is, invalid data.
- Valid data part: contains several broadcast data units, called AD Structure. The composition format of each AD Structure is as follows: The first byte is the Length value Length, indicating that the next Length byte is the data part. The first byte of the data is the data Type AD Type, and the remaining Leng-1 is the real data. Data types are important, there are standards that determine what the data means and how it should be interpreted. Right
Example:
E/TAG:scandata:02011A05FFAC013456000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000Copy the code
Here is the scanned packet (converted to hexadecimal, where two bytes represent one byte). The first byte is 02 to indicate that the next two bytes are the data portion, and the second byte is 01 to indicate the type of data. The next byte is the actual data. That’s the end of the broadcast data unit. So here’s another data unit. By analogy, the explanation of data types is available on the official website.
This is a table of meanings for data types.
Connection-based:
A GATT connection between two devices requires communication between the two. The two roles here are the Peripheral device and the center device (usually a cell phone) Centeral.
Network topology:
A central device can connect to multiple peripherals, but a peripheral can only connect to one central device (after the connection is successful, the peripheral will stop broadcasting, and others cannot discover it). The number of connected peripherals for one of the central devices is also limited.