Single Phase Voltage Stabilizer single phase voltage stabilizer zhejiang ttn electric co.,ltd , https://www.ttnpower.com
Some basic knowledge of Android BLE and related operational procedures
**Foreword:**
This article provides an overview of the fundamental concepts and operational procedures related to Android BLE (Bluetooth Low Energy). It does not focus on specific business implementations but rather offers insights into analyzing broadcast and response packets. The goal is to help developers who are currently working with or planning to work on Android BLE projects.
Note: Terms such as single mode, dual mode, BR, BT, BLE, Bluetooth 3.0, and Bluetooth 4.0 may be confusing for some readers. I have tried to explain them clearly, but if you find anything unclear, feel free to leave a comment!
---
**1. Introduction**
**1.1 Overview of Bluetooth Technology**
Bluetooth is a universal short-range wireless technology that allows multiple electronic devices to connect and communicate. It is widely used in small radios, offering low power consumption, low cost, security, stability, and ease of use. Due to its advantages, such as high speed and special networking capabilities, Bluetooth technology continues to evolve rapidly.
**1.2 Classification of Bluetooth**
There are three main types of Bluetooth:
- **Bluetooth Smart Ready**: This is a dual-mode device that supports both classic Bluetooth and BLE (Bluetooth Low Energy). It is compatible with both traditional Bluetooth and BLE devices.
- **Bluetooth Smart (or BLE)**: A single-mode device designed for low-power applications, such as heart rate monitors or pedometers. These devices typically run on button batteries and communicate with one device at a time.
- **Standard Bluetooth**: Also known as classic Bluetooth, it is used for higher data transfer rates but consumes more power. It cannot communicate with BLE devices.
*Image: [Android BLE Learning Notes](http://i.bosscdn.com/blog/15/23/01/O05_0.jpg)*
**1.3 Introduction to BLE (Bluetooth Low Energy)**
BLE, also known as Bluetooth 4.0, is a low-power wireless communication technology developed by Nokia under the name Wibree. It enables continuous connectivity between mobile devices and peripheral accessories. With an effective range of over 100 meters, BLE can operate for years on a single button battery.
BLE devices come in two modes:
- **Single Mode (LE/BLE)**: Can only communicate with other BLE devices.
- **Dual Mode (BR/EDR + LE)**: Supports both classic Bluetooth and BLE. This is commonly found in smartphones and modern devices like iOS 4.0+ and Android 4.3+.
Single-mode devices are often used in wearables like smartwatches due to their low power consumption and long battery life.
---
**2. Basic Concepts in BLE**
**2.1 Generic Access Profile (GAP)**
GAP defines how a device connects and advertises itself to other devices. It controls visibility, discoverability, and connection policies. For example, a device might be set to "discoverable" so other devices can see it and initiate a connection.
**2.2 Generic Attribute Profile (GATT)**
GATT is the profile used for reading and writing attribute data over a BLE connection. Most BLE applications today are built on GATT, which organizes data into services and characteristics.
**2.3 Attribute Protocol (ATT)**
ATT is the underlying protocol that GATT uses. It is optimized for BLE, minimizing data usage during transmission. Each attribute has a unique UUID, and data is transferred in the form of characteristics and services.
**2.4 Characteristic**
A characteristic is a data type that contains a value and optionally one or more descriptors. It represents a specific piece of information that can be read from or written to a BLE device.
**2.5 Descriptor**
A descriptor provides additional information about a characteristic, such as units of measurement, user descriptions, or client configuration settings.
**2.6 Service**
A service is a collection of characteristics that represent a specific function. For example, a "Heart Rate Monitor" service might include a characteristic for heart rate measurements.
**2.7 UUID (Universally Unique Identifier)**
UUIDs are unique identifiers assigned to each service, characteristic, and descriptor. They ensure that data is correctly identified and accessed across different devices.
---
**3. Android BLE API Overview**
**3.1 BluetoothGatt**
The `BluetoothGatt` class is used to manage connections to a BLE device. It handles discovering services and communicating with the remote device via callbacks. It acts as the lifecycle manager for a BLE connection.
**3.2 BluetoothGattCharacteristic**
Represents a specific data point (characteristic) on a BLE device. It includes a value and one or more descriptors.
**3.3 BluetoothGattDescriptor**
A descriptor provides metadata about a characteristic, such as its description, format, or access permissions.
**3.4 BluetoothGattService**
A group of related characteristics. For example, a "Heart Rate Service" might contain multiple characteristics like "heart rate measurement" or "body sensor location."
**3.5 BluetoothProfile**
Defines a standard way for devices to exchange data. GATT and GAP are examples of profiles used in BLE.
**3.6 BluetoothManager**
Used to obtain the `BluetoothAdapter`. It acts as a central hub for managing Bluetooth functionality on the device.
```java
BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
```
**3.7 BluetoothAdapter**
Represents the local Bluetooth adapter on the device. It is used to enable Bluetooth, scan for devices, and manage connections.
```java
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
```
**3.8 BluetoothDevice**
Represents a remote Bluetooth device. You can get it after scanning and identifying a device.
```java
BluetoothDevice bluetoothDevice = bluetoothAdapter.getRemoteDevice(address);
```
**3.9 BluetoothGattCallback**
A callback interface used to receive events from the `BluetoothGatt` class, such as when a service is discovered, a characteristic is read, or a connection is lost. It helps manage the state transitions of a BLE connection.
---
This guide aims to provide a clear understanding of Android BLE fundamentals. Whether you're new to BLE or looking to deepen your knowledge, this should serve as a solid foundation for further exploration.