#include <WiFi.h>
#include <DNSServer.h>
#include <WebServer.h>
#include <ESPmDNS.h> //用于设备域名 MDNS.begin("esp32")
#include <esp_wifi.h> //用于esp_wifi_restore() 删除保存的wifi信息
const int baudRate = 115200; //设置波特率
const byte DNS_PORT = 53; //设置DNS端口号
const int webPort = 80; //设置Web端口号
const int resetPin = 0; //设置重置按键引脚,用于删除WiFi信息
const int LED = 2; //设置LED引脚
const char* AP_SSID = "NodeMCU-ESP32"; //设置AP热点名称
//const char* AP_PASS = ""; //设置AP热点密码
const char* HOST_NAME = "MY_ESP32S"; //设置设备名
String scanNetworksID = ""; //用于储存扫描到的WiFi ID
int connectTimeOut_s = 15; //WiFi连接超时时间,单位秒
IPAddress apIP(192, 168, 4, 1); //设置AP的IP地址
String wifi_ssid = ""; //暂时存储wifi账号密码
String wifi_pass = ""; //暂时存储wifi账号密码
//定义根目录首页网页HTML源代码
#define ROOT_HTML "<!DOCTYPE html><html><head><title>WIFI Config by lwang</title><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head><style type=\"text/css\">.input{display: block; margin-top: 10px;}.input span{width: 100px; float: left; float: left; height: 36px; line-height: 36px;}.input input{height: 30px;width: 200px;}.btn{width: 120px; height: 35px; background-color: #000000; border:0px; color:#ffffff; margin-top:15px; margin-left:100px;}</style><body><form method=\"POST\" action=\"configwifi\"><label class=\"input\"><span>WiFi SSID</span><input type=\"text\" name=\"ssid\" value=\"\"></label><label class=\"input\"><span>WiFi PASS</span><input type=\"text\" name=\"pass\"></label><input class=\"btn\" type=\"submit\" name=\"submit\" value=\"Submie\"> <p><span> Nearby wifi:</P></form>"
//定义成功页面HTML源代码
#define SUCCESS_HTML "<html><body><font size=\&#
arduino+ESP32 web配网演示代码
最新推荐文章于 2024-07-13 15:02:12 发布