参考资料:
从零开始的ESP8266探索(06)-使用Server功能搭建Web Server
https://blog.csdn.net/Naisu_kun/article/details/80398667

#include <ESP8266WiFi.h>/*** 该工程可以在2.4.0版本esp8266库中运行,没在更高版本库中进行测试 ***/const char *ssid = "HelloWifi";
const char *password = "123ab";WiFiServer server(80);String readString = ""; //建立一个字符串对象用来接收存放来自客户的数据//响应头
String responseHeaders =String("") +"HTTP/1.1 200 OK\r\n" +"Content-Type: text/html\r\n" +"Connection: close\r\n" +"\r\n";//网页
String myhtmlPage =String("") +"<html>" +"<head>" +"    <title>ESP8266 Web Server Test</title>" +"    <script defer=\"defer\">" +"        function ledSwitch() {" +"            var xmlhttp;" +"            if (window.XMLHttpRequest) {" +"                xmlhttp = new XMLHttpRequest();" +"            } else {" +"                xmlhttp = new ActiveXObject(\"Microsoft.XMLHTTP\");" +"            }" +"            xmlhttp.onreadystatechange = function () {" +"                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {" +"                    document.getElementById(\"txtState\").innerHTML = xmlhttp.responseText;" +"                }" +"            }," +"            xmlhttp.open(\"GET\", \"Switch\", true);" +"            xmlhttp.send(); " +"        }" +"    </script>" +"</head>" +"<body>" +"    <div id=\"txtState\">Unkwon</div>" +"    <input type=\"button\" value=\"Switch\" onclick=\"ledSwitch()\">" +"</body>" +"</html>";bool isLedTurnOpen = false; // 记录LED状态void setup()
{pinMode(2, OUTPUT);digitalWrite(2, HIGH); // 熄灭LEDSerial.begin(115200);Serial.println();Serial.printf("Connecting to %s ", ssid);WiFi.begin(ssid, password);while (WiFi.status() != WL_CONNECTED){delay(500);Serial.print(".");}Serial.println(" connected");server.begin();Serial.printf("Web server started, open %s in a web browser\n", WiFi.localIP().toString().c_str());
}void loop()
{WiFiClient client = server.available(); //尝试建立客户对象if (client)                             //如果当前有客户可用{boolean currentLineIsBlank = true;Serial.println("[Client connected]");while (client.connected()) //如果客户端建立连接{if (client.available()) //等待有可读数据{char c = client.read(); //读取一字节数据readString += c;        //拼接数据/************************************************/if (c == '\n' && currentLineIsBlank) //等待请求头接收完成(接收到空行){//比较接收到的请求数据if (readString.startsWith("GET / HTTP/1.1")) //如果是网页请求{client.print(responseHeaders); //向客户端输出网页响应client.print(myhtmlPage);      //向客户端输出网页内容client.print("\r\n");}else if (readString.startsWith("GET /Switch")) //如果是改变LED状态请求{if (isLedTurnOpen == false){digitalWrite(2, LOW); // 点亮LEDclient.print("LED has been turn on");isLedTurnOpen = true;}else{digitalWrite(2, HIGH); // 熄灭LEDclient.print("LED has been turn off");isLedTurnOpen = false;}}else{client.print("\r\n");}break;}if (c == '\n'){currentLineIsBlank = true; //开始新行}else if (c != '\r'){currentLineIsBlank = false; //正在接收某行中}/************************************************/}}delay(1);      //等待客户完成接收client.stop(); //结束当前连接:Serial.println("[Client disconnected]");Serial.println(readString); //打印输出来自客户的数据readString = "";}
}

参考2:

注意: wifiManager.resetSettings();
【LinkNode D1】ESP8266 连接到路由器上
http://jingyan.eeboard.com/article/75186

#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 aroundWiFiManager wifiManager;//reset saved settingswifiManager.resetSettings();//set custom ip for portalwifiManager.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 configurationwifiManager.autoConnect("LinkNodeAP");//or use this for auto generated name ESP + ChipID//wifiManager.autoConnect();//if you get here you have connected to the WiFiSerial.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 seconddigitalWrite(BUILTIN_LED, LOW);    // turn the LED off by making the voltage LOWdelay(1000);              // wait for a second
}

需要安装:

参考3:
Arduino IDE for ESP8266 教程(一) 局域网 网页查看数据 不控制
https://www.cnblogs.com/kekeoutlook/p/8284213.html

/** Copyright (c) 2015, Majenko Technologies* All rights reserved.** Redistribution and use in source and binary forms, with or without modification,* are permitted provided that the following conditions are met:** * Redistributions of source code must retain the above copyright notice, this*   list of conditions and the following disclaimer.** * Redistributions in binary form must reproduce the above copyright notice, this*   list of conditions and the following disclaimer in the documentation and/or*   other materials provided with the distribution.** * Neither the name of Majenko Technologies nor the names of its*   contributors may be used to endorse or promote products derived from*   this software without specific prior written permission.** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>const char *ssid = "LRTech";
const char *password = "lanrui2017";ESP8266WebServer server ( 80 );const int led = 13;void handleRoot() {digitalWrite ( led, 1 );char temp[400];int sec = millis() / 1000;int min = sec / 60;int hr = min / 60;snprintf ( temp, 400,"<html>\<head>\<meta http-equiv='refresh' content='5'/>\<title>ESP8266 Demo</title>\<style>\body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\</style>\</head>\<body>\<h1>Hello from ESP8266!</h1>\<p>Uptime: %02d:%02d:%02d</p>\<img src=\"/test.svg\" />\</body>\
</html>",hr, min % 60, sec % 60);server.send ( 200, "text/html", temp );digitalWrite ( led, 0 );
}void handleNotFound() {digitalWrite ( led, 1 );String message = "File Not Found\n\n";message += "URI: ";message += server.uri();message += "\nMethod: ";message += ( server.method() == HTTP_GET ) ? "GET" : "POST";message += "\nArguments: ";message += server.args();message += "\n";for ( uint8_t i = 0; i < server.args(); i++ ) {message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n";}server.send ( 404, "text/plain", message );digitalWrite ( led, 0 );
}void setup ( void ) {pinMode ( led, OUTPUT );digitalWrite ( led, 0 );Serial.begin ( 115200 );WiFi.begin ( ssid, password );Serial.println ( "" );// Wait for connectionwhile ( WiFi.status() != WL_CONNECTED ) {delay ( 500 );Serial.print ( "." );}Serial.println ( "" );Serial.print ( "Connected to " );Serial.println ( ssid );Serial.print ( "IP address: " );Serial.println ( WiFi.localIP() );if ( MDNS.begin ( "esp8266" ) ) {Serial.println ( "MDNS responder started" );}server.on ( "/", handleRoot );server.on ( "/test.svg", drawGraph );server.on ( "/inline", []() {server.send ( 200, "text/plain", "this works as well" );} );server.onNotFound ( handleNotFound );server.begin();Serial.println ( "HTTP server started" );
}void loop ( void ) {server.handleClient();
}void drawGraph() {String out = "";char temp[100];out += "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"400\" height=\"150\">\n";out += "<rect width=\"400\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"1\" stroke=\"rgb(0, 0, 0)\" />\n";out += "<g stroke=\"black\">\n";int y = rand() % 130;for (int x = 10; x < 390; x+= 10) {int y2 = rand() % 130;sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"1\" />\n", x, 140 - y, x + 10, 140 - y2);out += temp;y = y2;}out += "</g>\n</svg>\n";server.send ( 200, "image/svg+xml", out);
}

esp8266 配置网页相关推荐

  1. [arduino]ESP8266配置连接IoT阿里云平台(arduino D1 mini)

    [arduino]ESP8266配置连接IoT阿里云平台(arduino D1 mini) 前言 ESP8266配置(基础) ESP8266头文件配置 安装AliyunIoTSDK库 安装Arduin ...

  2. ESP8266实现网页交互

    前言: 物联网LOT(intermet of things)时代,万物互联,wifi芯片是非常重要的,乐鑫的高性价比的ESP8266芯片凭借低功耗低成本高集成度等优势在市场上占有较高的份额,为什么选用 ...

  3. Charles学习(三)之使用Map local代理本地静态资源以及配置网页代理在Mac模拟器调试iOS客户端...

    前言 问题一:我们在App内嵌H5开发的过程中,肯定会遇到一个问题就是我不想在chrome的控制台中调试,我想要在手机上调试,那么如何解决这个问题呢? 问题二:我们期待调试时达到的效果就是和Charl ...

  4. centos 7.6 —— Nginx 配置网页防盗链FPM参数优化

    centos 7.6 -- Nginx 配置网页防盗链&&FPM参数优化 一.网页防盗链 (1)防盗链端--服务端配置(192.168.75.134) 1.1 服务端配置DNS服务,域 ...

  5. 配置网页登陆虚拟带库显示报错

    配置网页登陆虚拟带库显示报错 网页报错 Apache提示You don't have permission to access / on this server问题解决 测试时遇到将一本地目录设置为一 ...

  6. 为 Esp8266 配置 Arduino 开发环境并测试WiFi

    为 Esp8266 配置 Arduino 开发环境 date: 2020-04-16 lastmod: 2021-09-21 安装驱动 为了让电脑可以正确识别开发板,需要装设备驱动(免驱插上就会自动安 ...

  7. esp8266舵机驱动_使用Arduino和ESP8266通过网页控制舵机

    在本文中,我们将尝试通过网页来控制舵机,通过滑动网页上对应的滑块,促使舵机做相应地运动.这样的尝试在做一些远程开关或者远程控制的小设备时非常有用,比如把 宠物定时喂食器 改造成网页控制的也是可以实现的 ...

  8. arduino开发ESP8266配置方法,入门必看,esp8266开发板库离线安装包package2.7.1

    公众号关注 "DLGG创客DIY" 设为"星标",重磅干货,第一时间送达. 群里经常有朋友问arduino开发ESP8266的配置方法,今天在之前的文章基础上, ...

  9. 200528更新arduino开发ESP8266配置方法,入门必看,esp8266开发板库离线安装包package2.7.1...

    公众号关注 "DLGG创客DIY" 设为"星标",重磅干货,第一时间送达. 群里经常有朋友问arduino开发ESP8266的配置方法,今天(200528)在之 ...

最新文章

  1. 自动驾驶架构与实现路径
  2. spark(一) build
  3. Matlab数据类型学习图解
  4. buntu linux下建立stm32开发环境: GCC安装以及工程Makefile建立
  5. 算法之旅 | 快速排序法
  6. python dataframe group by_Python DataFrame.groupby()聚合函数,分组级运算
  7. 开源的python机器学习模块
  8. matlab soble滤波,MATLAB 图像滤波去噪分析及其应用
  9. 搭建本地LNMP开发环境(6)-配置nginx和PHP
  10. 《活着》:永远不要相信苦难是值得的,​苦难就是苦难
  11. xp计算机workgroup无法访问,弹出“Workgroup无法访问”的提示?XP 工作组没有权限的解决办法...
  12. pta:人民币与美元汇率兑换程序(python)
  13. gre模考软件java.exe_【模考】GRE模考软件逆天版(考G神器)
  14. APP开发为什么选择云服务器?
  15. 膜拜!阿里内部学习的五大深入理解Java虚拟机PDF,真的强
  16. 漫画:三分钟学习一道位运算的面试题,万一遇到了呢?
  17. Shopee账户被冻结是什么原因?怎么解封?
  18. TOJ 1225 数据结构练习题——Huffman Coding
  19. 360加强网站拦截 附解决办法
  20. VMware虚拟机CentOS 7 系统安装通用天文包CASA 教程

热门文章

  1. HTML5画布(canvas)
  2. html5 canvas清空画布方法
  3. HTML5 Canvas动态绘制心型线和玫瑰线
  4. 性能监视器-无法从系统备份存储中重建性能计数器设置
  5. jeesite工作流使用
  6. Java方法中的要点
  7. 假期无聊冰河开发了一款国民级游戏!
  8. 玩着赚的加密游戏,大火中慧眼识珠
  9. 全球及中国无创吸脂仪行业投资分析及发展前景研究报告2021年版
  10. 杰理之浪涌测试注意事项【篇】