当前文档版本为 v0.4.0,您可以访问当前页面的 开发中 版本以获取最近可能的更新。

Solution: BLE RGB Light

1 功能概述

本文主要介绍PAN1080 BLE RGB灯和手机APP进行连接,通过APP控制RGB灯的亮度与颜色。

2 环境要求

  • board: pan1080a_afld_evb

  • uart (option): 显示串口log

  • 安卓亿觅精灵灯app V1.5.5,或 微信小程序(待补充)

3 编译和烧录

项目位置:zephyr\samples_panchip\solutions\ble_rgb_light

目前可使用ZAL工具或quick build脚本进行编译和下载。

脚本位置:quick_build_samples\solutions\ble_rgb_light.bat

打开脚本后默认会编译项目,编译完成时,可输入字符进行后续下载等操作:

Input the keyword to continue:
  'b' build                         编译项目
  'r' make clean and rebuild        重新编译项目
  'f' flash download                下载
  'e' erase chip                    擦除芯片
  'o' open project by VS Code       打开 `VS Code`,可查看源码,执行编译下载等
  others exit                       退出
wait input:

4 演示说明

  1. PAN1080 EVB板GPIO P10、P11、P16与RGB电路用跳线帽连接。

  2. EVB板上电灯的颜色默认是蓝色,BLE广播设备的名字是”b+EMIE Elfy” 。

  3. 打开安卓手机”亿觅精灵灯“ app,在app上启动搜索设备。

  4. 搜索到后点击连接,连接成功后就可以控制灯的开关和颜色了。

5 设备连接和控制

5.1 广播数据

Adv Data Type

Description

Length

Detail

0xff

Device id

6byte

0x11, 0x00, 0xc9, 0x7a, 0xbb, 0x8f, 0xdd, 0x4b, 0x00, 0x11

0x07

128-bit UUID

16byte

0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
0x93, 0xf3, 0xa3, 0xb5, 0x01, 0x20, 0x40, 0x6e

0x09

Device name

n byte

“b+EMIE Elfy”

5.2 GATT服务

Function

Service Attribute

UUID(128bit)

Useless

Primary service

0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
0x93, 0xf3, 0xa3, 0xb5, 0x01, 0x20, 0x40, 0x6e

控制灯的状态

Write characteristic declaration

0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
0x93, 0xf3, 0xa3, 0xb5, 0x02, 0x20, 0x40, 0x6e

Notify灯的状态

notify characteristic declaration

0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0,
0x93, 0xf3, 0xa3, 0xb5, 0x03, 0x20, 0x40, 0x6e

5.3 通信协议

5.3.1 Light Control

UUID = {0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0, 0x93, 0xf3, 0xa3, 0xb5, 0x03, 0x20, 0x40, 0x6e}

Function

Length

Detail

off

2byte

off:0xaa, 0x03

Color

5byte

0xaa,0x16,red:0~255,green:0~255,blue:0~255

控制灯的开关、颜色。

5.3.2 Notify Light Status

UUID = {0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0, 0x93, 0xf3, 0xa3, 0xb5, 0x02, 0x20, 0x40, 0x6e}

每次收到控制命令后将灯的状态通知给手机app。