ArtOS 快速开发框架

ArtOS 快速开发框架

首页
ArtOS框架
使用文档视频教程
Micropython
官方文档学习教程固件开发
发现
树莓派ESP32
生态圈
智能生活直播物联工业物联Node-RED
开发资源
开发板软件资源器件资源
关于ArtOS
登录 →
ArtOS 快速开发框架

ArtOS 快速开发框架

首页 ArtOS框架
使用文档视频教程
Micropython
官方文档学习教程固件开发
发现
树莓派ESP32
生态圈
智能生活直播物联工业物联Node-RED
开发资源
开发板软件资源器件资源
关于ArtOS
登录
  1. 首页
  2. 生态圈
  3. 智能生活
  4. BLE开发的概念,profile,service,characteristic, UUID

BLE开发的概念,profile,service,characteristic, UUID

0
  • 智能生活
  • 发布于 2026-01-08
  • 7 次阅读
极客熊
极客熊

一、Attribute(属性)——一切的“原子单位”

1. Attribute 是什么?

Attribute 协议中唯一存在的实体

2.每一个 Attribute 都包含:

ble_att.png
  • Attribute Handle:Attribute handle,Attribute 句柄,16-bit 长度。Client 要访问 Server 的 Attribute,都是通过这个句柄来访问的,也就是说 ATT PDU 一般都包含 handle 的值。用户在软件代码添加 characteristic 的时候,系统会自动按顺序地为相关 attribute 生成句柄。

  • Attribute Type:Attribute 类型,2 字节或者 16 字节长。在 BLE 中我们使用 UUID 来定义数据的类型,UUID 是 128 bit 的,所以我们有足够的 UUID 来表达万事万物。其中有一个 UUID 非常特殊,它被蓝牙联盟采用为官方 UUID,这个 UUID 如下所示:

    ble_uuid.png
  • Attribute Value:就是数据真正的值,0 到 512 字节长

  • Attribute Permissions:Attribute 的权限属性,读 / 写 / 认证 / 加密

ATT 层根本不知道“Service”“Characteristic”这些词

二、什么是profile?

可以理解为一种规范,一种通信协议,profile 存在于从机中。SIG 规定了一些 profile,如心率计,防丢器,HID OVER GATT 等等。每个 Profile 中都包含多个 Service。每个 Service 代表从机的一个能力。

三、Service(服务)是什么?

可以理解为一个服务,在 BLE 从机中,可以有多个服务,譬如系统电量信息服务,系统信息服务,每个 Service 又包含多个 Characteristic。每个具体的 Characteristic 值才是 BLE 通信的主体。比如当前电量是 80%,会通过电量的 Characteristic 特征值存在从机的 Profile 里面,这样,主机就可以通过这个 Characteristic 值获得从机的 80% 电量值。

1. Service 本质

Service = 一个特殊的 Attribute + 一个作用范围

  • Service 自身是 一个 Attribute

  • UUID:

    • Primary Service:0x2800

    • Secondary Service:0x2801

  • Value:

    • 服务的 UUID(16-bit 或 128-bit)

2. Service 的作用

  • 声明:

    “从我开始,到下一个 Service 之前的所有 Attribute,属于我”

Service 本身不存业务数据

四、Characteristic(特征)是什么?

可以理解为一个标签,通过这个标签可以获取或写入想要的内容。

Characteristic 是一个“复合结构”,不是一个 Attribute

一个完整的 Characteristic 至少由 2 个 Attribute 组成,通常是 3 个或更多。一个 characteristic 包含三种类型的数据条目(attribute):characteristic 声明条目(declaration attribute),characteristic 值条目(value attribute)以及 characteristic 描述符条目(descriptor attribute)(一个 characteristic 可以有多个描述符条目),如下所示:

ble_characteristic.png

1、Characteristic Declaration(特征声明)

  • 一个 Attribute

  • UUID 固定为:0x2803

  • Characteristic Declaration 的 Value 包含:

[Properties][Value Handle][Characteristic UUID]
  • Properties:

    • Read / Write / Notify / Indicate 等

  • Value Handle:

    • 指向下一个 Attribute(Characteristic Value)

  • Characteristic UUID:

    • 业务定义的 UUID

“这是一个特征,它的值在某个 Handle,它支持哪些操作”

2、Characteristic Value(特征值)

  • 一个 Attribute

  • UUID = Characteristic 的 UUID

  • Value = 实际业务数据

  • 客户端真正关心的对象

    • Read → 读这里

    • Write → 写这里

    • Notify / Indicate → 从这里发

3、Descriptor(描述符)

  • 附属于某个 Characteristic 的 Attribute

  • 用来:

    • 描述

    • 配置

    • 解释 Characteristic Value

Descriptor 必须紧跟在 Characteristic Value 后面

  • 直到:

    • 遇到下一个 Characteristic Declaration

    • 或 Service 结束

  • 常见 Descriptor

Descriptor

UUID

作用

CCCD

0x2902

开启 / 关闭 Notify

User Description

0x2901

文本说明

Presentation Format

0x2904

数据格式

Notify / Indicate 必须有 CCCD

五、层级关系(核心)

1. 从“本质”角度

Attribute
 ├── Service (特殊 Attribute)
 ├── Characteristic Declaration (特殊 Attribute)
 ├── Characteristic Value (普通 Attribute)
 └── Descriptor (普通 Attribute)

2. 从“结构”角度

Service
 ├── Characteristic
 │     ├── Characteristic Declaration (Attribute)
 │     ├── Characteristic Value (Attribute)
 │     ├── Descriptor (Attribute)
 │     └── Descriptor (Attribute)
 ├── Characteristic
 │     ├── ...

3. 从“Handle 排列”角度(非常关键)

Handle N     : Service Declaration (0x2800)
Handle N+1   : Characteristic Declaration (0x2803)
Handle N+2   : Characteristic Value (UUID=xxxx)
Handle N+3   : Descriptor (0x2902)
Handle N+4   : Characteristic Declaration
Handle N+5   : Characteristic Value
...

六、关系对照表(强烈建议记住)

概念

本质

是否 Attribute

Attribute

ATT 基本单元

是

Service

Attribute + 作用域

是

Characteristic

Attribute 组合

否

Characteristic Declaration

声明 Attribute

是

Characteristic Value

数据 Attribute

是

Descriptor

附属 Attribute

是

一个“温度服务”,一个“温度特征”

0x0001  Service           UUID=0x2800  Value=0x1809
0x0002  Char Declaration  UUID=0x2803  Value=Read|Notify, 0x0003, 0x2A1C
0x0003  Char Value        UUID=0x2A1C  Value=25.3
0x0004  Descriptor        UUID=0x2902  Value=0x0001

BLE 里没有 Service 和 Characteristic,只有 Attribute
Service / Characteristic 是人类为了组织 Attribute 而定义的语义层

相关文章
iBeacon安装布置建议

iBeacon安装布置建议

一、布置前的原则 1️⃣ 目的明确 先明确你的 iBeacon 系统想做什么: 目标

iBeacon 中的TxPower的值为什么0xC5?

iBeacon 中的TxPower的值为什么0xC5?

它“看起来像固定的”,这正是很多人困惑的根源。 下面我分 规范层 → 工程现实 → 你该如何对待 三层说清楚。 一、规范层结论(标准答案) TxPower 不是固定值。 在 iBeacon 规范中: TxPower = 1 米处的 RSSI 单位:dBm 类型:int8

iBeacon 数据帧解释

iBeacon 数据帧解释

一、iBeacon 本质上的“数据帧位置” 首先明确一点: iBeacon 并不是一个独立的 BLE 协议层,而是放在 BLE 广播数据(Advertising Data)里的一种格式约定。 它存在于: BLE Advertising Packet └── Advertising Data (AD

什么是iBeacon?

什么是iBeacon?

一、什么是 iBeacon(本质定义) iBeacon 是一种基于 BLE 广播的“近距离识别协议”,最早由 Apple 提出。 从技术本质看: 它 不是定位系统 不是连接协议 不建立连接 只做一件事:周期性广播身份信息 一句话概括: iBeacon = 低功耗广播 + 唯

蓝牙定位:Beacon与iBeacon的区别

蓝牙定位:Beacon与iBeacon的区别

随着物联网技术的普及,蓝牙Beacon和iBeacon成为室内定位与智能场景应用的核心技术。然而,许多人对两者的概念仍存在混淆。本文将深入解析它们的区别,并推荐两款高性价比的亿佰特蓝牙模组,助你轻松选型! Beacon与iBeacon:本质与定义 ① 蓝牙Beacon(信标) 技术基础:基于BLE(

BLE开发的概念,profile,service,characteristic, UUID

BLE开发的概念,profile,service,characteristic, UUID

一、Attribute(属性)——一切的“原子单位” 1. Attribute 是什么? Attribute 协议中唯一存在的实体

目录
  • 极客熊
  • 极客熊
  • 极客熊
Copyright © 2026 ArtOS All Rights Reserved. Powered by ArtOS.