BLE Mesh 指令帧
帧结构
所有 BLE Mesh 指令均为 hex 字符串,格式:
53 <命令体> <签名>53— 帧头- 命令体 — 由
genCommand()生成 - 签名 — 由
signCommand()生成(防篡改)
msgType 定义
| msgType | 说明 |
|---|---|
30 | 控制指令(ble_in 下发) |
80 | 状态响应(ble_out 上报) |
32 | 查询指令 |
0c | 登录指令 |
04 | Mesh 配置 |
01 | BLE 名称设置 |
12 | 扫描指令 |
92 | 设备列表上报 |
genCommand 指令对照表
genCommand(type, data) 生成 53 + 命令体 + 签名。
命令体格式
30 <cmdLen> <naddr> <msgType> <参数>| 字段 | 长度 | 说明 |
|---|---|---|
30 | 1 字节 | 固定前缀 |
| cmdLen | 1 字节 | 后续数据长度(04 或 05) |
| naddr | 1 字节 | 设备网络地址 |
| msgType | 1 字节 | 指令类型码 |
| 参数 | 可变 | 指令参数 |
开关控制
| type | cmdLen | msgType | 参数格式 | 示例 |
|---|---|---|---|---|
controlSwitch | 04/05 | 02/45 | <status_byte> / <status_byte><status_byte2> | 533004aabb02ff02 + sign |
controlPlugcardSwitch | 04 | 48 | <status_byte> | 插卡取电 |
status_byte 编码(4 路):
bit 7 6 5 4 3 2 1 0
[4][3][2][1] 每路 2 bit: 10=开, 01=关, 00=不变8 路开关(oe=true)使用 cmdLen=05、msgType=45,额外一个字节编码 5-8 路。
亮度控制
| type | cmdLen | msgType | 参数 | 说明 |
|---|---|---|---|---|
setBrightnessPercentage | 04 | 03 | <val> | 设置亮度百分比 |
increaseBrightnessPercentage | 04 | 2f | <val> | 增加亮度 |
decreaseBrightnessPercentage | 04 | 30 | <val> | 降低亮度 |
setBrightnessV2 | 05 | 9c | <index><val> | 设置子灯亮度 |
increaseBrightnessV2 | 05 | a1 | <index><val> | 增加子灯亮度 |
decreaseBrightnessV2 | 05 | a2 | <index><val> | 降低子灯亮度 |
色温控制
| type | cmdLen | msgType | 参数 | 说明 |
|---|---|---|---|---|
setColorTemperature | 04 | 04 | <val> | 设置色温 |
increaseColorTemperature | 04 | 31 | <val> | 增加色温 |
decreaseColorTemperature | 04 | 32 | <val> | 降低色温 |
setColorTemperatureV2 | 05 | 9d | <index><val> | 设置子灯色温 |
increaseColorTemperatureV2 | 05 | a5 | <index><val> | 增加子灯色温 |
decreaseColorTemperatureV2 | 05 | a6 | <index><val> | 降低子灯色温 |
窗帘控制
| type | cmdLen | msgType | 参数 | hex 示例 |
|---|---|---|---|---|
openCurtain | 04 | 05 | 01 | 533004aabb0501 |
closeCurtain | 04 | 05 | 02 | 533004aabb0502 |
stopCurtain | 04 | 05 | 03 | 533004aabb0503 |
openCurtainPos | 04 | 06 | <pos> | 533004aabb0632 (pos=50) |
closeCurtainPos | 04 | 06 | <pos> | 同 openCurtainPos |
空调控制
| type | cmdLen | msgType | 参数 | 说明 |
|---|---|---|---|---|
openAC | 04 | 02 | 02 | 开空调 |
closeAC | 04 | 02 | 01 | 关空调 |
setACMode | 04 | 1d | <mode> | mode: 1=cold, 2=warm, 3=fan, 4=auto |
setACTemperature | 04 | 1b | <val> | 设置温度 |
increaseACTemperature | 04 | 33 | <val> | 增加温度 |
decreaseACTemperature | 04 | 34 | <val> | 降低温度 |
setFanSpeed | 04 | 1c | <speed> | speed: 1=high, 2=middle, 3=low, 4=auto |
increaseFanSpeed | 04 | 35 | 01 | 增加风速 |
decreaseFanSpeed | 04 | 36 | 01 | 降低风速 |
红外控制
| type | cmdLen | msgType | 参数 | 说明 |
|---|---|---|---|---|
ir_transmitter | 07 | 8f | <ir_data> | 红外指令 |
ir_data 格式:
<study><cmd_id><delay><reserved>| 字段 | 长度 | 说明 |
|---|---|---|
| study | 1 字节 | 00=发送,01=学习 |
| cmd_id | 1 字节 | 红外指令码(见下表) |
| delay | 1 字节 | 延时(单位 100ms) |
| reserved | 1 字节 | 保留 |
红外指令码对照:
| 动作 | TV | 机顶盒 |
|---|---|---|
| turn_on | 0d | 2f |
| turn_off | 0d | 2f |
| increase_volume | 04 | 26 |
| decrease_volume | 0e | 30 |
| set_volume_mute | 00 | 22 |
| increase_channel | 05 | 27 |
| decrease_channel | 0f | 31 |
其他指令
| type | cmdLen | msgType | 参数 | 说明 |
|---|---|---|---|---|
setColorRgb | 06 | 4c | <rgb> | RGB 灯颜色 |
disableDevice | 04 | bc c0 26 | <01/00> | 禁用/启用设备 |
场景执行
genExecuteScene(id) → 53 30 04 bc c0 01 <id> <sign>| 字段 | 说明 |
|---|---|
53 | 帧头 |
30 | 控制指令 |
04 | 数据长度 |
bc c0 | 场景指令标识 |
01 | 固定 |
<id> | 场景 ID(1 字节 hex) |
<sign> | 签名 |
naddr 编码
encodeNaddr(data.naddr) 将设备的网络地址编码为 1 字节 hex。naddr 是 BLE Mesh 中的单播地址,范围 0x0001-0x7FFF,编码时取低 8 位。
签名
signCommand(cmd) 对命令体计算签名,附加在末尾。签名算法用于防止指令篡改,网关收到指令后会验证签名。
