Solution: BLE Google Light¶
1 功能概述¶
本文主要介绍PAN1080 BLE灯控接入google home音箱,通过谷歌音箱控制RGB灯的亮度与颜色。
2 环境要求¶
board: pan108xxb5_evb
uart (option): 显示串口log
google home音箱
google home app
3 编译和烧录¶
例程位置:zephyr\samples_panchip\solutions\ble_google_light
使用 ZAL 工具可以对其进行编译、烧录、打开 VS Code 调试等操作。关于 ZAL 工具的详细介绍请参考:Zephyr APP Launcher 工具介绍。
4 演示说明¶
PAN1080 EVB板GPIO P10、P11、P16与RGB电路用跳线帽连接。
EVB板上电灯的颜色默认是白色,BLE广播设备的名字是“EnergeticLighting” 。
打开安卓手机”google home“ app与google home音箱连接,然后在app上添加灯泡设备,app上启动搜索灯泡。
搜索到后连接并配网,配网的过程中灯会闪烁。
配网成功后app上会显示一个灯泡的图案,然后就可以控制灯的开关、亮度和颜色。
灯和音箱断开连接后的BLE广播设备的名字是“EnergeticLightingPRO” ,此时与音箱连接无需重新配网可以直接连接。
app上设置移除灯泡后此时灯进入退网状态,BLE广播设备的名字是“EnergeticLighting” ,与音箱连接需要重新配网。
5 设备配网和控制¶
5.1 广播数据¶
Data Type |
Description |
Length |
Detail |
---|---|---|---|
0xff |
Device id |
6byte |
mac addr |
0xfe |
Deviceinfo: Manufacturer model |
7byte |
“panchip” |
0xfd |
HW Version |
1byte |
0x01 |
0xfc |
SW Version |
1byte |
0x01 |
0x09(未配网) |
Device name |
n byte |
“EnergeticLighting” |
0x09(已配网) |
Device name |
n byte |
“EnergeticLightingPRO” |
配网前和配网后的广播包主要是名字不一样,其他的都是一样的。
5.2 GATT服务¶
Function |
Service Attribute |
UUID(128bit) |
---|---|---|
Useless |
Primary service |
0x1800(Generic GAP Service) |
读灯的状态 |
Read characteristic declaration |
0x35, 0xb1, 0xc3, 0xd8, 0x7e, 0xd4, 0x21, 0x81, 0x13, 0x46, 0xb7, 0x9c, 0x43, 0xaf, 0x83, 0x76 |
读灯的名字 |
Read characteristic declaration |
0x36, 0xb1, 0xc3, 0xd8, 0x7e, 0xd4, 0x21, 0x81, 0x13, 0x46, 0xb7, 0x9c, 0x43, 0xaf, 0x83, 0x76 |
控制灯的配网和灯状态 |
Write characteristic declaration |
0x37, 0xb1, 0xc3, 0xd8, 0x7e, 0xd4, 0x21, 0x81, 0x13, 0x46, 0xb7, 0x9c, 0x43, 0xaf, 0x83, 0x76 |
读灯的亮度和开关状态 |
Read characteristic declaration |
0x38, 0xb1, 0xc3, 0xd8, 0x7e, 0xd4, 0x21, 0x81, 0x13, 0x46, 0xb7, 0x9c, 0x43, 0xaf, 0x83, 0x76 |
读灯的软件版本信息 |
Read characteristic declaration |
0x39, 0xb1, 0xc3, 0xd8, 0x7e, 0xd4, 0x21, 0x81, 0x13, 0x46, 0xb7, 0x9c, 0x43, 0xaf, 0x83, 0x76 |
主动上报灯的亮度和开关状态 |
Notify characteristic declaration |
0x40, 0xb1, 0xc3, 0xd8, 0x7e, 0xd4, 0x21, 0x81, 0x13, 0x46, 0xb7, 0x9c, 0x43, 0xaf, 0x83, 0x76 |
5.3 通信协议¶
5.3.1 Read Light Status¶
UUID = {0x35,0xb1,0xc3,0xd8,0x7e,0xd4,0x21,0x81,0x13,0x46,0xb7,0x9c,0x43,0xaf,0x83,0x76}
Function |
Length |
Detail |
---|---|---|
Light OnOff |
1byte |
0x0:关闭,0x1:使能 |
Light Brightness |
1byte |
0x0:关闭,0x1:使能 |
Light Color Temperature |
1byte |
0x0:关闭,0x1:使能 |
Light Color Setting |
1byte |
0x0:关闭,0x1:使能 |
Light Min Temperature |
2byte |
eg:2000 |
Light Max Temperature |
2byte |
eg:7500 |
灯发送数据如下:
data[8]={0x01 ,0x01 ,0x01 ,0x01 ,0x07 ,0xd0, 0x1d ,0x4c}
5.3.2 Read Light Name¶
UUID = {0x36,0xb1,0xc3,0xd8,0x7e,0xd4,0x21,0x81,0x13,0x46,0xb7,0x9c,0x43,0xaf,0x83,0x76}
Function |
Length |
Detail |
---|---|---|
Name |
14byte |
“A19 Full Color” |
灯的名字:
name_data[] = “A19 Full Color”
5.3.3 Light Control¶
UUID = {0x37,0xb1,0xc3,0xd8,0x7e,0xd4,0x21,0x81,0x13,0x46,0xb7,0x9c,0x43,0xaf,0x83,0x76}
Function |
Length |
Type(1byte) |
Detail |
---|---|---|---|
Onoff |
2byte |
0x00 |
on:0x01;off:0x00 |
Bright |
2byte |
0x01 |
bright:0~100 |
Color Temperature |
3byte |
0x02 |
temp:2000~7500 |
Blink |
2byte |
0x03 |
on:0x01;off:0x00 |
Provision |
2byte |
0x04 |
succeed:0x01;failed:0x00 |
Unprovision |
2byte |
0x05 |
succeed:0x01;failed:0x00 |
Color |
4byte |
0x06 |
red:0~255;green:0~255;blue:0~255 |
控制灯的开关、亮度、色温、颜色、闪烁、配网和退网。
5.3.4 Read Light Version¶
UUID = {0x39,0xb1,0xc3,0xd8,0x7e,0xd4,0x21,0x81,0x13,0x46,0xb7,0x9c,0x43,0xaf,0x83,0x76}
Function |
Length |
Detail |
---|---|---|
Hardware and software version |
2byte |
hw:0x01;sw:0x01 |
5.3.5 Read Light Bright and Color temp¶
UUID = {0x38,0xb1,0xc3,0xd8,0x7e,0xd4,0x21,0x81,0x13,0x46,0xb7,0x9c,0x43,0xaf,0x83,0x76}
Function |
Length |
Detail |
---|---|---|
Onoff |
1byte |
on:0x01;off:0x00 |
Bright |
1byte |
bright:0~100 |
ColorTemperature |
2byte |
temp:2000~7500 |
5.3.6 Notify Light Status¶
UUID = {0x40,0xb1,0xc3,0xd8,0x7e,0xd4,0x21,0x81,0x13,0x46,0xb7,0x9c,0x43,0xaf,0x83,0x76}
每次收到控制命令后将灯的状态通知给音箱。
6 RAM/Flash资源使用情况¶
Memory region Used Size Region Size %age Used
FLASH: 213144 B 1020 KB 20.41%
SRAM: 27908 B 52 KB 52.41%
IDT_LIST: 0 GB 2 KB 0.00%