esp8266三种工作模式
1 接入点模式Access Point
esp8266不仅可以接收信号也可以向外部发送信号(可以建立一个wifi)
2 无线终端模式Wireless Station
可以接入网络
3 混合模式
集合二者有点
4 Http
请求包含请求头,请求空行,请求头(post还有请求体) 响应包含状态行,响应头,响应体
GET /favicon.ico HTTP/1.1
Host: www.taichi-maker.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.39
Accept: image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8
Referer: http://www.taichi-maker.com/wp-content/uploads/2016/12/esp8266_devkit_horizontal-01.png
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
Cookie: NWZbTK=19xDdISvF8; blQWITsEVOcrL=FG90m3W; eQf_liynbDCJtRZ=MAl0ZjE2K
GET /favicon.ico HTTP/1.1
请求类型GET /favicon.ico 请求网站的内容 HTTP/1.1 协议的版本
Host: www.taichi-maker.com
esp8266默认ip地址为192.168.4.1
在这里插入图片描述
5 写个简单的服务器
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WebServer.h>
ESP8266WiFiMulti eSP8266WiFiMulti;
ESP8266WebServer eSP8266WebServer(80);
void handRoot(){
eSP8266WebServer.send(200,"text/plain","Hello Esp8266 Web");
}
void handNotFound(){
eSP8266WebServer.send(404,"text/plain","PageNot found");
}
void setup() {
Serial.begin(115200);
eSP8266WiFiMulti.addAP("mark2","12345678");
int i = 0;
while (eSP8266WiFiMulti.run() != WL_CONNECTED)
{
delay(2000);
Serial.print(i++);Serial.print(' ');
}
Serial.print('\n');
Serial.print("IP address: ");
Serial.println(WiFi.SSID());
Serial.println(WiFi.localIP());
eSP8266WebServer.begin();
eSP8266WebServer.on("/",handRoot);
eSP8266WebServer.onNotFound(handNotFound);
delay(3000);
Serial.println(WiFi.localIP());
}
void loop() {
eSP8266WebServer.handleClient();
}
|