风扇
| 技术方案 | Classic |
|---|---|
| 应用场景 | 家电与控制 |
本示例演示如何使用 ESP32 系列开发板模拟风扇,通过 RGB LED 指示风速(0–5 档),并支持使用 BOOT 按键或手机 App 中的开关控件进行控制。
产品应用场景: 落地风扇:通过 ESP RainMaker Home App 或开发板按键在 0 到 5 档之间调速。
概览
| 处理器 | ESP32/ESP32-C6/ESP32-C3/ESP32-S3/ESP32-H2 |
|---|---|
| 连接方式 | Wi-Fi/Thread + BLE |
| 供电电压 | 3.3V |
| IDF 版本 | ESP-IDF v5.x 及以上版本 |
准备物品
- ESP32、ESP32-C3、ESP32-C6、ESP32-S3 或 ESP32-H2 开发板
- USB 数据线
- Chrome 或 Edge 浏览器(Web Serial)
- ESP RainMaker 手机 App
可体验的功能
- 系统服务: ESP RainMaker 的系统服务支持远程执行设备的基本操作,如重启、重置 Wi-Fi 设置和恢复出厂设置。
- 时间服务: 时间对任何物联网设备都至关重要,设备定时等功能尤其依赖准确的时间。
- 场景: 在 ESP RainMaker 中,场景可以为一个或多个设备预设特定的参数值,这些设备可以分布在不同节点上。触发场景后,相关设备将按照预设参数调整至对应状态。
- 定时: ESP RainMaker 的定时功能可按预设时间自动控制设备,提升使用便利性和能源效率。
- OTA 升级: 通过 OTA 升级,可为已部署的设备添加新功能并修复问题。
在真实开发板上体验
从乐鑫或其授权分销商购买官方开发板,然后直接在本页烧录此示例。 选购乐鑫开发板
烧录并体验
选择部署
公共部署
由乐鑫托管,供评估使用。免费,无需任何部署。
- 连接: 通过 USB 连接开发板,并选择对应的串口。
- 烧录: 写入预编译固件,等待擦除和烧录完成。
- 复位: 重启开发板,控制台中将显示二维码。
- 配对: 在 Home App 中点击 +,通过蓝牙连接,并输入控制台中显示的 PoP。
详细说明
1. 准备工作
- 一台 Linux、macOS 或 Windows 电脑。
- 一块 ESP32/ESP-C6/ESP-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