TA的每日心情 | 开心 2018-11-14 16:42 |
---|
签到天数: 136 天 连续签到: 1 天 [LV.7]常住居民III
|
这次通过Arduino IDE来设置ESP8266为clientsecure模式,并通过Web来配置要被连接的路由器的SSID和密码
1.安装要被使用的库
打开Arduino IDE 项目-加载库-管理库

搜索wifimanager并安装

2.编写程序
首先添加库文件
ESP8266WebServer ESP8266mDNS WIFImanager

编写代码
#include <WiFiManager.h>#include <ESP8266WebServer.h>#include <ESP8266mDNS.h>#include <ESP8266WiFi.h>#include <ESP8266WiFiAP.h>#include <ESP8266WiFiGeneric.h>#include <ESP8266WiFiMulti.h>#include <ESP8266WiFiScan.h>#include <ESP8266WiFiSTA.h>#include <ESP8266WiFiType.h>#include <WiFiClient.h>#include <WiFiClientSecure.h>#include <WiFiServer.h>#include <WiFiUdp.h>void setup() { // put your setup code here, to run once: Serial.begin(115200); //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around WiFiManager wifiManager; //reset saved settings //wifiManager.resetSettings(); //set custom ip for portal wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); //fetches ssid and pass from eeprom and tries to connect //if it does not connect it starts an access point with the specified name //here "AutoConnectAP" //and goes into a blocking loop awaiting configuration wifiManager.autoConnect("LinkNodeAP"); //or use this for auto generated name ESP + ChipID //wifiManager.autoConnect(); //if you get here you have connected to the WiFi Serial.println("connected... "); pinMode(BUILTIN_LED, OUTPUT);} void loop() { digitalWrite(BUILTIN_LED, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(BUILTIN_LED, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second}编译代码,无错误后下载到LinkNode D1
用手机连接到WIFI LinkNodeAP,打开手机浏览器输入10.0.1.1后你会看到如图的页面
点击Configure WiFi 输入你要连接的路由器的SSID(路由器的名字)和密码

3.查看实验结果
在电脑上用浏览器打开路由器的管理界面,可以看到ESP8266已经连接到路由器上

打开Arduino IDE的串口监视器,也可以看到连接成功的信息
 |
|