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

Solution: BLE RGB Light

1 功能概述

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

2 环境要求

  • board: pan107

  • uart (option): 显示串口log

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

3 编译和烧录

例程位置:<home>\nimble\samples\solutions\ble_rgb_light\keil

使用keil进行打开项目选择需要的controller进行烧录ble_rgb_light_origin或者ble_rgb_light_spark进行编译烧录,推荐选择ble_rgb_light_spark

4 演示说明

  1. PAN107 EVB板GPIO P11、P12、P14与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。

6 RAM/Flash资源使用情况

Spark Controller:

Flash Size: 128.04k
RAM Size:  37.20 k