ESP32C3 使用web网页配网教程
概述
今天我来给大家介绍一下如何用 ESP32C3 创建一个网页,用来配置 WiFi 参数。通过这种方式,我们可以通过网页输入 WiFi 的 SSID 和密码,让 ESP32C3 连接到指定的 WiFi 网络。
先决条件
在开始之前,确保你已经搞定了以下几个事情:
- 安装并配置好 ESP-IDF 开发环境。
- 对 ESP-IDF 和 ESP32C3 有个基本的了解。
步骤
1. 克隆项目仓库
首先,从 GitHub 或 Gitee 上克隆项目仓库:
-
Gitee 链接: https://gitee.com/renbingcheng/esp_web_wificfg
git clone https://github.com/renbingcheng/esp_web_wificfg
cd esp_web_wificfg
或者
git clone https://gitee.com/renbingcheng/esp_web_wificfg
cd esp_web_wificfg
2. 配置项目
打开 menuconfig
配置界面:
idf.py menuconfig
在这里,确保设置了正确的目标芯片(ESP32C3)和其他相关参数。
3. 项目代码讲解
主文件 main.c
这个文件包含了启动 WiFi AP 模式和配置网页服务器的代码。以下是关键代码片段的讲解:
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "nvs_flash.h"
#inc