本文描述一款基于 TuyaOS 平台开发的 Zigbee 协议照明灯具 Demo,支持开关、亮度调节、色温调节、彩光调节等功能。
概述
功能特点
- 支持涂鸦特色开关、亮度、色温、彩光 HSV、情景和音乐灯的远程控制,接入涂鸦网关即可使用涂鸦 App 控制。
- 支持 Zigbee 3.0 标准指令控制,产品开发包中已经提供绝大部分的标准指令处理方式,接入标准 Zigbee 3.0 网关即可使用。
- 支持 Zigbee Touchlink 组网及控制。
操作及现象
-
进行网络配对:
-
当
light_app_config.h
文件中的POWER_ON_AUTO_JOIN
宏定义配置为1
时,设备在无网络状态下上电,会自动进行网络配对。 -
当
light_app_config.h
文件中的POWER_ON_AUTO_JOIN
宏定义配置为0
时,需要手动重置配网,此时您需要对灯进行上下电重置操作,上下电次数需要大于等于SCAN_NETWORK_RESET_COUNT
宏定义的值,并且重置过程中上电时间不能超过 5s,否则需要重新计算次数。 -
网络配对窗口期时长由宏定义
ZIGBEE_JOIN_TIMEOUT_MS
决定,超出窗口期时长则本次配网超时。 -
当灯开启网络配对时,灯会进入灯闪提示。宏定义
SCAN_NETWORK_PROMPT_METHOD
为0
时为闪烁提示,SCAN_NETWORK_PROMPT_METHOD
为1
时为呼吸提示。网络配对灯闪提示时长由宏定义SCAN_NETWORK_PROMPT_TIME_S
决定,通常SCAN_NETWORK_PROMPT_TIME_S
≤ZIGBEE_JOIN_TIMEOUT_MS
。 -
网络配对期间灯闪提示的模式和 HSVBT 数据,以及网络配对完成后常亮的模式和 HSVBT 数据可由您在
app_light_prompt.c
文件的app_light_prompt_ctrl_start
函数中编辑。//prompt start data prompt_start_data.on_off = TRUE; #if (APP_LIGHT_CHANNELS == 3) prompt_start_data.mode = COLOR_MODE; #else prompt_start_data.mode = WHITE_MODE; #endif prompt_start_data.b_data = 1000; //range: 0-1000 prompt_start_data.t_data = 1000; //range: 0-1000 prompt_start_data.h_data = 0; //range: 0-360 prompt_start_data.s_data = 1000; //range: 0-1000 prompt_start_data.v_data = 1000; //range: 0-1000 //prompt stop data prompt_stop_data.on_off = TRUE; #if (APP_LIGHT_CHANNELS == 3) prompt_stop_data.mode = COLOR_MODE; #else prompt_stop_data.mode = WHITE_MODE; #endif prompt_stop_data.b_data = 1000; //range: 0-1000 prompt_stop_data.t_data = 1000; //range: 0-1000 prompt_stop_data.h_data = 0; //range: 0-360 prompt_stop_data.s_data = 1000; //range: 0-1000 prompt_stop_data.v_data = 1000; //range: 0-1000
-
此时可将灯与网关进行配对,步骤参考 配网步骤。
-
配对成功时,灯会恢复到常亮状态,此时可在 App 页面看到此设备。
-
配对超时(时间默认 180 秒)后,灯会恢复到常亮状态。
-
产品创建
关于产品创建流程,参考产品创建。
设备协议介绍
Zigbee 基本信息
参数 | 数值 |
---|---|
Profile ID | 0x0104 |
Device ID |
|
Endpoint 描述
Endpoint | 描述 |
---|---|
0x01 | 当前灯具使用的端口号 |
0xF2 | Green Power 使用的端口号 |
支持的 cluster
Endpoint 0x01
Input clusters (Server) | Output clusters (Client) |
---|---|
Basic (0x0000) | OTA Upgrade (0x0019) |
Identify (0x0003) | Time (0x000A) |
Groups (0x0004) | / |
Scenes (0x0005) | / |
On/Off (0x0006) | / |
Level Control (0x0008) | / |
Color Control (0x0300) | / |
Touchlink Commissioning (0x1000) | / |
Endpoint 0xF2
Input clusters (Server) | Output clusters (Client) |
---|---|
/ | Green Power (0x0021) |
支持的属性和命令
Basic cluster
Attributes
ID | Name | Data type | Range | Default |
---|---|---|---|---|
0x0000 | ZCL Version | uint8-0x20 | 0x00-0xff | 0x03。 |
0x0001 | Application Version | uint8 -0x20 | 0x00-0xff | 例如,0b 01 00 0001 = 1.0.1 ,即 0x41 为 1.0.1 。OTA 功能会用到该版本号,在 OTA 开始阶段,网关会读取 OTA 包的版本号推送给设备。在 OTA 成功重启后,网关会读取版本号来确定是否升级成功。只能往更高的版本升级。 |
0x0002 | Stack Version | uint8-0x20 | 0x00-0xff | 0x02。 |
0x0003 | Hardware Version | uint8-0x20 | 0x00-0xff | 0x01。 |
0x0004 | Manufacturer Name | string-0x42 | 0-32 bytes | XXX…XXX (长度为 16 个字节,由 8 字节前缀和 8 字节的 PID 组成),0-7 bytes:_TZ3000_ ,8-16 bytes:PID(由产品经理在平台或者自助创建和提供)。该字段决定了手机 App 界面的 UI 和功能展现,如果对 PID 没有特殊要求,可采用默认 PID。 |
0x0005 | Model Identifier | string-0x42 | 0-32 bytes | TS0505B。 |
0x0007 | Power Source | enum8-0x30 | 0x00-0xff | 0x01。 |
0xFFFD | Cluster Revision | uint16-0x21 | 0x0000-0xffff | 0x0001。 |
Identify cluster
Attributes
ID | Name | Data type | Range | Default |
---|---|---|---|---|
0x0000 | Identify Time | uint16-0x21 | 0x0000-0xffff | 0x0000 |
0xFFFD | Cluster Revision | uint16-0x21 | 0x0000-0xffff | 0x0001 |
Commands
ID | Name | Direction |
---|---|---|
0x00 | Identify | C->S |
0x01 | Identify Query | C->S |
Groups cluster
Attributes
ID | Name | Data type | Range | Default |
---|---|---|---|---|
0x0000 | Name Support | map8-0x18 | desc | 0x00 |
0xFFFD | Cluster Revision | uint16-0x21 | 0x0000-0xffff | 0x0002 |
Commands
ID | Name | Direction |
---|---|---|
0x00 | Add Group | C->S |
0x01 | View Group | C->S |
0x02 | Get Group Membership | C->S |
0x03 | Remove Group | C->S |
0x04 | Remove All Groups | C->S |
0x05 | Add Group If Identifying | C->S |
Scenes cluster
Attributes
ID | Name | Data type | Range | Default |
---|---|---|---|---|
0x0000 | Scene Count | uint8-0x20 | 0x00-0xff | 0x00 |
0x0001 | Current Scene | uint8-0x20 | 0x00-0xff | 0x00 |
0x0002 | Current Group | uint16-0x21 | 0x0000-0xfff7 | 0x0000 |
0x0003 | Scene Valid | bool-0x10 | 0 or 1 | 0x00 |
0x0004 | Name Support | map8-0x18 | desc | 0x00 |
0xFFFD | Cluster Revision | uint16-0x21 | 0x0000-0xffff | 0x0002 |
Commands
ID | Name | Direction |
---|---|---|
0x00 | Add Group | C->S |
0x01 | View Group | C->S |
0x02 | Get Group Membership | C->S |
0x03 | Remove Group | C->S |
0x04 | Remove All Groups | C->S |
0x05 | Add Group If Identifying | C->S |
On off cluster
Attributes
ID | Name | Data type | Range | Default |
---|---|---|---|---|
0x0000 | On Off | bool-0x10 |
| 0x00 |
0xFFFD | Cluster Revision | uint16-0x21 | 0x0000-0xffff | 0x0002 |
Commands
ID | Name | Direction |
---|---|---|
0x00 | Off | C->S |
0x01 | On | C->S |
0x02 | Toggle | C->S |
Level control cluster
Attributes
ID | Name | Data type | Range | Default |
---|---|---|---|---|
0x0000 | Current Level | uint8-0x20 | 0x01-0xfe | 0xfe |
0x000F | Options | map8-0x18 | desc | 0x00 |
0xFFFD | Cluster Revision | uint16-0x21 | 0x0000-0xffff | 0x0002 |
Commands
ID | Name | Direction |
---|---|---|
0x00 | Move to Level | C->S |
0x01 | Move | C->S |
0x02 | Step | C->S |
0x03 | Stop | C->S |
0x04 | Move to Level (with On/Off) | C->S |
0x05 | Move (with On/Off) | C->S |
0x06 | Step (with On/Off) | C->S |
0x07 | Stop (with On/Off) | C->S |
Color control cluster
Attributes
ID | Name | Data type | Range | Default |
---|---|---|---|---|
0x0000 | Current Hue | uint8-0x20 | 0x00-0xfe | 0x00 |
0x0001 | Current Saturation | uint8-0x20 | 0x00-0xfe | 0xfe |
0x0003 | Current X | uint16-0x21 | 0x0000-0xfeff | 0x0000 |
0x0004 | Current Y | uint16-0x21 | 0x0000-0xfeff | 0x0000 |
0x0007 | Color Temperature Mireds | uint16-0x21 | 0x0000-0xfeff | 0x0000 |
0x0008 | Color Mode | enum8-0x30 | 0x00-0x02 | 0x02 |
0x000F | Options | map8-0x18 | / | 0x00 |
0x0010 | Number Of Primaries | uint8-0x20 | 0x00-0x06 | 0xff |
0x4001 | Enhanced Color Mode | enum8-0x30 | 0x00-0xff | 0x02 |
0x400A | Color Capabilities | map16-0x19 | 0x0000-0x001f | 0x0019 |
0x400B | Color Temp Physical Min Mireds | uint16-0x21 | 0x0000-0xfeff | 0x0099 |
0x400C | Color Temp Physical Max Mireds | uint16-0x21 | 0x0000-0xfeff | 0x01F4 |
0x400D | Couple Color Temp To Level Min Mireds | uint16-0x21 | Color Temp Physical Min Mireds-Color Temp Physical Max Mireds | 0x0099 |
0x4010 | Start Up Color Temperature Mireds | uint16-0x21 | 0x0000-0xfeff | 0x0099 |
0xFFFD | Cluster Revision | uint16-0x21 | 0x0000-0xffff | 0x0002 |
Commands
ID | Name | Direction |
---|---|---|
0x00 | Move to Hue | C->S |
0x01 | Move Hue | C->S |
0x02 | Step Hue | C->S |
0x03 | Move to Saturation | C->S |
0x04 | Move Saturation | C->S |
0x05 | Step Saturation | C->S |
0x06 | Move to Hue and Saturation | C->S |
0x07 | Move to Color | C->S |
0x08 | Move Color | C->S |
0x09 | Step Color | C->S |
0x0a | Move to Color Temperature | C->S |
0x47 | Stop Move Step | C->S |
0x4b | Move Color Temperature | C->S |
0x4c | Step Color Temperature | C->S |
Touchlink commissioning cluster
Attributes
ID | Name | Data type | Range | Default |
---|---|---|---|---|
0xFFFD | Cluster Revision | uint16-0x21 | 0x0000-0xffff | 0x0001 |
Commands
ID | Name | Direction |
---|---|---|
0x00 | Scan request | C->S |
0x02 | Device information request | C->S |
0x06 | Identify request | C->S |
0x07 | Reset to factory new request | C->S |
0x10 | Network start request | C->S |
0x12 | Network join router request | C->S |
0x14 | Network join end device request | C->S |
0x16 | Network update request | C->S |
Over the air upgrade
Attributes
ID | Name | Data type | Range | Default |
---|---|---|---|---|
0x0000 | UpgradeServerID | EUI64 - 0xF0 | / | 0xffffffffffffffff |
0x0001 | FileOffset | uint32 - 0x23 | / | 0x00000000 |
0x0002 | CurrentFileVersion | uint32 - 0x23 | / | 0x00000040 |
0x0006 | ImageUpgradeStatus | enum8 - 0x30 | / | 0x00 |
0x0007 | Manufacturer ID | uint16 - 0x21 | / | 0x1002 |
0x0008 | Image Type ID | uint16 - 0x21 | / | 0x1602 |
0x0009 | MinimumBlockPeriod | uint16 - 0x21 | / | 0x0000 |
0xfffd | ClusterRevision | uint16 - 0x21 | 0x0000 -0xffff | 0x0001 |
Commands
ID | Name | Direction |
---|---|---|
0x00 | Image Notify | S->C |
0x01 | Query Next Image Request | C->S |
0x02 | Query Next Image Response | S->C |
0x03 | Image Block Request | C->S |
0x05 | Image Block Response | S->C |
0x06 | Upgrade End Request | C->S |
0x07 | Upgrade End Response | S->C |
常用 DP 与 cluster 对应关系
DPID | DP 含义 |
---|---|
1 | 开关 |
2 | 模式 |
3 | 白光亮度 |
4 | 白光色温 |
5 | 彩光颜色 |
6 | 情景 |
8 | 音乐律动 |
9 | 实时调节 |
DP1 开关
指令方向 | Cluster ID | ATTR ID | Type | Value |
---|---|---|---|---|
下发 | 0x0006 |
| - | - |
上报 | 0x0006 | 0x0000 | bool |
|
DP2 模式
指令方向 | Cluster ID | ATTR ID | Type | Value |
---|---|---|---|---|
下发 | 0x0300 | 0xF0:私有指令 | - |
|
上报 | 0x0300 | 0xF000:私有属性 | uint8 |
|
DP3 白光亮度
指令方向 | Cluster ID | ATTR ID | Type | Value |
---|---|---|---|---|
下发 | 0x0008 | 0xF0:私有指令 | - | 2 Bytes,范围 0x0000-0x03E8 |
上报 | 0x0008 | 0xF000:私有属性 | uint16 | 2 Bytes,范围 0x0000-0x03E8 |
DP4 白光色温
指令方向 | Cluster ID | ATTR ID | Type | Value |
---|---|---|---|---|
下发 | 0x0300 | 0xE0:私有指令 | - | 2 Bytes,范围 0x0000-0x03E8 |
上报 | 0x0300 | 0xE000:私有属性 | uint16 | 2 Bytes,范围 0x0000-0x03E8 |
DP5 彩光颜色
指令方向 | Cluster ID | ATTR ID | Type | Value |
---|---|---|---|---|
下发 | 0x0300 | 0xE1:私有指令 | - |
|
上报 | 0x0300 | 0xE100:私有属性 | uint4 |
|
DP6 情景
指令方向 | Cluster ID | ATTR ID | Type | Value |
---|---|---|---|---|
下发 | 0x0300 | 0xF1:私有指令 | - | 数据长度:2 + 8 × n,n 是场景的单元个数,n ≤ 8 |
上报 | 0x0300 | 0xF003:私有属性 | uint16 | 2 Bytes,范围 0x0000-0x03E8 |
情景 DP 的数据域详细解析,参考 情景 DP。
DP8 音乐/DP9 实时调节
指令方向 | Cluster ID | ATTR ID | Type | Value |
---|---|---|---|---|
下发 | 0x0300 | 0xF2:私有指令 | - | 11 Bytes |
音乐 DP 和实时调节 DP 的 Zigbee 协议相同。
默认心跳
150s-180s 随机上报,上报内容为 App Version。