灯
| 技术方案 | Classic |
|---|---|
| 应用场景 | 照明 |
本示例演示如何通过 ESP32 系列开发板和手机 App 控制 LED 灯泡的色调、饱和度、亮度和电源状态。
产品应用场景
- 客厅照明:按时段与氛围切换场景,可通过 ESP RainMaker Home App 控制。
- 会议室照明:线性吊灯随日光调节,切换专注白光,演示时自动调暗。
- 仓库高天棚照明:当班全功率输出,天窗下日光采集,以及人感待机亮度。
概览
| 支持的芯片 | ESP32, C3, C6, S3, H2 |
|---|---|
| 连接方式 | Wi-Fi 或 Thread,BLE 用于配网 |
| 框架 | ESP-IDF v5.x |
| 云端 | ESP RainMaker |
准备物品
- ESP32、ESP32-C3、ESP32-C6、ESP32-S3 或 ESP32-H2 开发板
- USB 数据线
- Chrome 或 Edge 浏览器(Web Serial)
- ESP RainMaker 手机 App
可体验的功能
- 颜色与亮度: 通过 App 设置色调、饱和度、亮度和电源。
- 定时与场景: 按时间自动执行,或与其他设备组合联动。
- OTA 升级: 通过仪表盘向开发板推送新固件。
- 语音助手: 通过 RainMaker 支持 Alexa 和 Google Home。
- 系统服务: 远程重启、重置 Wi-Fi 或恢复出厂设置。
- 时间服务: 同步设备时钟,确保定时任务准确执行。
在真实开发板上体验
从乐鑫或其授权分销商购买官方开发板,然后直接在本页烧录此示例。 选购乐鑫开发板
烧录并体验
选择部署
公共部署
由乐鑫托管,供评估使用。免费,无需任何部署。
- 连接: 通过 USB 连接开发板,并选择对应的串口。
- 烧录: 写入预编译固件,等待擦除和烧录完成。
- 复位: 重启开发板,控制台中将显示二维码。
- 配对: 在 Home App 中点击 +,通过蓝牙连接,并输入控制台中显示的 PoP。
详细说明
1. 准备工作
- 一台 Linux、macOS 或 Windows 电脑。
- 一块 ESP32/ESP32-C6/ESP32-C3/ESP32-S3/ESP32-H2 开发板。
- USB 数据线。
2. 连接设备
- 使用 USB 数据线将设备连接到电脑,然后点击终端上方左上角的
连接按钮。 - 选择正确的串口,然后点击
连接。 - 连接成功后,即可开始烧录设备。
3. 烧录设备
- 点击终端上方的
烧录设备,选择 擦除并烧录。等待erase_flash擦除过程完成后,再写入固件。 - 等待固件烧录完成。
- 点击
复位按钮复位设备。 - 终端中出现二维码,即表示烧录成功。
4. 在 Home App 中为设备配网
- 在控制台旁的 Home App 面板中,保持 ESP RainMaker Classic 部署,然后登录。也可以使用 ESP RainMaker 手机 App(点击此处获取)。
- 点击
+,选择 I do not have a QR code,再选择 Bluetooth。 - 在 Chrome 的蓝牙窗口中,选择与控制台中名称一致的设备,例如
PROV_ff7bf2。 - 按提示输入 PoP。PoP 即控制台
QRCODE:行中的"pop"值,例如{"ver":"v1","name":"PROV_xxxxxx","pop":"xxxxxxxx","transport":"ble"}。 - 选择 Wi-Fi 网络,输入密码,等待配网完成。设备随后会出现在 My Devices 中。
- 在 App 中控制设备。
私有部署
您自己的 ESP RainMaker Classic 部署。请通过 Admin CLI 注册节点,而非 Dashboard。
- Register: With the ESP RainMaker Admin CLI, generate device certificates and register them with node_certs.csv.
- Load credentials: Zip the CLI batch folder (Mfg-…) or pick one node's .bin from its bin/ folder, and drop it into Device credentials.
- Flash: Write the firmware and the credentials in one pass. The board resets when done.
- Pair: Sign in to your private Classic deployment in the Home App, then add the device with the PoP from the console.
详细说明
1. Before you start
- A private ESP RainMaker Classic deployment (you need its deployment base URL and super-admin email from setup).
- The ESP RainMaker Admin CLI installed on your computer (esp-rainmaker-admin-cli).
- An ESP32-family DevKit that matches this example, a USB data cable, and Chrome or Edge.
2. Generate and register device certificates
- Follow the Admin CLI user guide. Set your deployment endpoint and log in:
python rainmaker_admin_cli.py account serverconfig --endpoint <your-deployment-base-url> python rainmaker_admin_cli.py account login --email <super-admin-email>
- Generate certificates for your boards (factory NVS images land under
bin/in the output folder):python rainmaker_admin_cli.py certs devicecert generate --count <n> --prov ble --outdir <outdir>
- Register them with the cloud using the batch's
common/node_certs.csv:python rainmaker_admin_cli.py certs devicecert register --inputfile <outdir>/<date>/Mfg-<no>/common/node_certs.csv
- Save the
request_idfrom the register command and check status when needed:python rainmaker_admin_cli.py certs devicecert getcertstatus --requestid <request_id>
- The output holds private keys. Keep it out of chats and repositories, and delete it when you are done.
3. Load the device credentials
- From the Admin CLI output folder, zip the
Mfg-<no>batch folder, or pick onebin/node-….binfile. - Drop that ZIP or
.binonto Device credentials above the console. It is read in your browser and never uploaded. - With the ZIP, pick the node for this board. Every board needs its own node: two boards with the same one connect as the same device.
- The credentials are flashed at
0x3FA000, where this example keeps itsfctrypartition.
4. Connect and flash
- Connect the board over USB, click
Connectabove the console and pick its port. - Click
Flash Deviceand choose Erase, then flash firmware + credentials. The firmware image goes to0x0and the credentials to0x3FA000in one pass, so the erase cannot wipe them. - The board resets when flashing is done. Type
get-node-idin the console when the firmware supports it: it prints the node you picked. - To give a board another node later, or restore one after a full erase, load the credentials and choose Credentials only. The firmware on the board is kept.
- To reflash only the firmware, choose Flash only. The credentials on the board are kept.
5. Sign in on your deployment
- In the Home App panel next to the console, sign in to your private ESP RainMaker Classic deployment (the base URL from your deployment setup).
- You can also use the ESP RainMaker phone app (iOS / Android); point it at the same deployment if your build supports a custom endpoint.
- Use a regular user account for day-to-day testing, not the super-admin account used with the Admin CLI.
6. Provision the device in the Home App
- Tap
+, choose I do not have a QR code, then Bluetooth. - In Chrome's Bluetooth window, pick the device whose name matches the one in the console, for example
PROV_ff7bf2. - Enter the PoP when asked. It is the
"pop"value in theQRCODE:line of the console, for example{"ver":"v1","name":"PROV_xxxxxx","pop":"xxxxxxxx","transport":"ble"}. - Pick your Wi-Fi network, enter its password and wait for provisioning to finish. The device then appears under My Devices.
- Control the device from the app.
连接遇到问题?
- 确保设备已通过 USB 正确连接
- 检查是否已安装正确的驱动程序
- 尝试更换 USB 端口或数据线
- 确认设备已进入烧录模式
- 点击此处获取最新版 ESP RainMaker 手机 App