zoukankan      html  css  js  c++  java
  • esp8266 Server模式

    #include <ESP8266WiFi.h>
    #include <ESP8266WebServer.h>
    #include "index.h"
    ESP8266WebServer server(80);
    int LED_PIN=14;  //led灯脚
    void setup() {
      Serial.begin(115200);
      // put your setup code here, to run once:
      WiFi.begin("kangtine","87602261");//设置网络链接
      pinMode(LED_PIN,OUTPUT);
      while(WiFi.status()!=WL_CONNECTED){
          delay(500);
          Serial.print(".");
        }
        
        Serial.print("Wi-Fi connected,IP:");
        Serial.println(WiFi.localIP());
        server.on("/",rootRouter);  //路由设置
        server.on("/sw",[](){  //控制LED灯
            String state=server.arg("led");
            if(state=="on")
              digitalWrite(LED_PIN,LOW);
            if(state=="off")
              digitalWrite(LED_PIN,HIGH);
              server.send(200,"text/html","led is on <br>"+state+"</br>");
          });
         server.on("/index.html",rootRouter);  
         server.onNotFound([](){
            server.send(404,"text/plain","File Not found!");
          });
        server.begin();
        Serial.println("HTTP server started.");
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      server.handleClient();
    }
    
    void rootRouter(){
        server.send(200,"text/html",PAGE_INDEX);//将网页存储到flash中
      }
    const char PAGE_INDEX[] PROGMEM= R"=====(
      <!DOCTYPE html ">
    <html">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>ESP8266物联网</title>
    </head>
    
    <body>
      <h1>ESP8266物联网</h1>
      <p>你正在浏览ESP8266提供的信息</p>
    </body>
    </html>
    )=====";
  • 相关阅读:
    取指定长度的字符串(包括中英文),以"..."的方式显示
    js 常用函数
    js 规范
    js高级编程笔记2
    js高级编程笔记
    WinJS开发div中元素的水平和垂直居中metro
    WinJS开发iframe中Javascript执行错误metro
    MySql乱码
    正则表达式符号系统
    Java替换字符串中的回车换行
  • 原文地址:https://www.cnblogs.com/Lonelychampion/p/12228028.html
Copyright © 2011-2022 走看看