Analysis and application of key technologies of BLE low-power Bluetooth[Copy link]
1. The transmission distance of traditional Bluetooth ranges from tens of meters to hundreds of meters, while BLE is set at 100 meters (actually not that far, it is relatively stable within 50 meters, which is related to the transmission power of the device) 2. In order to achieve extremely low power consumption, the BLE protocol is designed to completely shut down the radio frequency in the air when it is not necessary (it can quickly establish a connection for control operations when needed). Compared with traditional Bluetooth BR\EDR, BLE has the following three characteristics to achieve low power consumption: shorten the wireless opening time, quickly establish a connection, and reduce the peak power consumption of sending and receiving (determined by the chip). 3. The first trick to shorten the wireless startup time is to use only 3 "advertising" channels (the rest of the channels are used for data transmission). The second trick is to reduce the duty cycle by optimizing the protocol stack. A device in advertising can automatically and quickly establish a connection with a device in search, so the connection establishment and data transmission can be completed within 3ms. (In fact, the first connection is not that fast because some initialization configuration is required) 4. Low-power design will bring some sacrifices, for example: audio data cannot be transmitted through BLE. BLE is still a very robust technology. It still supports frequency hopping (37 data channels) and uses an improved GFSK modulation method to improve link stability. BLE is still a very secure technology because it provides 128-bit AES encryption at the chip level (which saves a lot of work in terms of security in application layer development). 5. Android's BLE standard was released on July 24, 2013. Generally, mobile phones with Android 4.3 and above support Bluetooth 4.0 (BLE). Smartphones and tablets will have dual-mode Bluetooth baseband and protocol stacks, which include all parts of GATT and below, but no specific protocols above GATT. Therefore, these specific protocols need to be implemented in the application, and the implementation needs to be based on various GATT API sets. This is conducive to simply implementing specific protocols on the smart phone side, and it is also possible to simply develop a set of private protocols based on GATT on the smart phone side. 6. BLE protocol stack PHY layer: 1Mbps adaptive frequency hopping GFSK (Gaussian frequency shift keying), running on the license-free 2.4GHz frequency band. Link Layer (LL): Controls the state of the device. A device may have 5 states: standby, advertising, scanning, initiating and connected. A device in a connected state will have a role: master and slave. The one who initiates the connection is the master, and the one who accepts the connection request is the slave (usually a mobile phone or tablet is the master). Host Control Layer (HCI): Provides some methods for communication between the host and the controller through a standard interface. This layer can implement device control through a software API or hardware interfaces such as UART, SPI and USB. Logical Link Control and Adaptation Protocol L2CAP layer: provides data encapsulation services for the upper layer, allowing logical end-to-end data communication. Security Management Layer SM: provides pairing and key distribution services to achieve secure connections and data exchange. General Access Profile GAP layer: an interface that communicates directly with applications or profiles, handling device discovery and connection-related services. It also handles the initialization of security features. Attribute Protocol Layer (ATT) ): The ATT protocol allows a device to display some data, which is called "Attribute" to other devices. In ATT, the device that displays these attributes is called server, and the other equivalent device is called client. The states of the LL layer, master and slave, are independent of the two states of the ATT layer. General Attribute Profile (GATT) ): It is a service framework that defines the subroutines of ATT applications. GATT specifies the structure of the profile. In BLE, all types of data used by a profile or service are called characteristics. All data exchanged between two devices through a BLE connection must be processed by the GATT subroutines. Therefore, apps and profiles use GATT directly. 7. Generic Attribute Profile (GATT) GATT defines two roles: server and client. GATT roles are not necessarily associated with specific GAP roles, but may be specified by higher-level profiles. GATT and ATT are not transport-specific and can also be used for BR/EDR and low energy. However, since GATT and ATT are used as discovery services, they must be implemented in low energy technology. 8. GATT Profile Hierarchy The highest level of this hierarchy is the profile. A profile consists of one or more services required to implement a use case. A service consists of characteristics or references to other services. Each characteristic includes a value and may also include optional information about the value. Services, characteristics, and the components of characteristics (i.e., values and descriptors) contain profile data and are all stored in the server's attributes. 9. Device Role Division In the BLE protocol, there are two roles, peripheral and central. The peripheral is the data provider and the central is the data user/processor. In the iOS SDK, an iOS device can be used as a peripheral or a central. However, in the Android SDK, until the latest Android 4.4.2. Android phones can only use and process data as a central. A central can connect to multiple peripherals at the same time, but a peripheral can only connect to one central at a time. BluetoothGattServer acts as a peripheral to provide data; BluetoothGattServerCallback returns the status of the peripheral. BluetoothGatt acts as a central to use and process data; BluetoothGattCallback returns the status of the central and the data provided by the peripheral. A Ble device can only play one role at a time. Each peripheral BluetoothGattServer contains multiple services, each Service contains multiple characteristics, and each Characteristic contains multiple Descriptors. 10. In order to obtain the central BluetoothGatt, the following process is roughly required: Get BluetoothManager:mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); [ size=4] Get BluetoothAdapter:mBluetoothAdapter = mBluetoothManager.getAdapter(); ] Scan Ble device: mBluetoothAdapter.startLeScan( BluetoothAdapter. LeScanCallback); [color=#000000 ] Get BluetoothDevice from LeScanCallback: public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) [color= #000000]{.....} Use BluetoothDevice to get BluetoothGatt: gatt = device.connectGatt(this, true, gattCallback); Get BluetoothGatt and call BluetoothGatt methods to interact with the surrounding BluetoothGattServer through BluetoothGattCallback.BLUETOOTH_SERVICE); [color =#000000]Get BluetoothAdapter: mBluetoothAdapter = mBluetoothManager.getAdapter();[/ backcolor] [ backcolor=white]Scan Ble devices: mBluetoothAdapter.startLeScan( BluetoothAdapter. LeScanCallback); [/backcolor ] Get BluetoothDevice from LeScanCallback: public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) [backcolor= white]{.....} Use BluetoothDevice to get BluetoothGatt: gatt = ]device.connectGatt(this, true, gattCallback); [/ size] Get BluetoothGatt, and by calling the BluetoothGatt method, you can use [color =#000000]BluetoothGattCallback interacts with the surrounding BluetoothGattServer. BLUETOOTH_SERVICE); [color =#000000]Get BluetoothAdapter: mBluetoothAdapter = mBluetoothManager.getAdapter();[/ backcolor] [ backcolor=white]Scan Ble devices: mBluetoothAdapter.startLeScan( BluetoothAdapter. LeScanCallback); [/backcolor ] Get BluetoothDevice from LeScanCallback: public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) [backcolor= white]{.....} Use BluetoothDevice to get BluetoothGatt: gatt = ]device.connectGatt(this, true, gattCallback); [/ size] Get BluetoothGatt, and by calling the BluetoothGatt method, you can =#000000]BluetoothGattCallback interacts with the surrounding BluetoothGattServer. gattCallback); Get BluetoothGatt, and by calling the BluetoothGatt method, you can interact with the surrounding BluetoothGattServer through BluetoothGattCallback. gattCallback); Get BluetoothGatt, and by calling the BluetoothGatt method, you can interact with the surrounding BluetoothGattServer through BluetoothGattCallback.