zoukankan      html  css  js  c++  java
  • Arduino IDE for ESP8266 项目云盒子 (1)AP直接模式

    手机直接连接esp8266辐射的WIFI,通信。

     https://item.taobao.com/item.htm?spm=a230r.1.14.20.eYblO3&id=521945102409&ns=1&abbucket=7#detail

    #include <ESP8266WiFi.h>
     
    const char *ssid = "Charlie Testing AP";
    const char *password = "12345678";
    WiFiServer server(80);
    void setup()
    {
      Serial.begin(115200);
      Serial.println();
     
      Serial.print("Setting soft-AP ... ");
       
    IPAddress softLocal(192,168,128,1);   
    IPAddress softGateway(192,168,128,1);
    IPAddress softSubnet(255,255,255,0);
     
    WiFi.softAPConfig(softLocal, softGateway, softSubnet);  
     
        WiFi.softAP(ssid, password);
       
       IPAddress myIP = WiFi.softAPIP();
      Serial.print("AP IP address: ");
      Serial.println(myIP);
     server.begin();
     Serial.printf("Web server started, open %s in a web browser
    ", WiFi.localIP().toString().c_str());
     
    }
     
    void loop()
    {
     WiFiClient client = server.available();
     if (client)
      {
        Serial.println("
    [Client connected]");
        while (client.connected())
        {
          // read line by line what the client (web browser) is requesting
          if (client.available())
          {
            String line = client.readStringUntil('
    ');
            Serial.print(line);
            // wait for end of client's request, that is marked with an empty line
            if (line.length() == 1 && line[0] == '
    ')
            {
              client.println(prepareHtmlPage());
     
               
              break;
            }
          }
        }
        delay(1); // give the web browser time to receive the data
     
        // close the connection:
        client.stop();
        Serial.println("[Client disonnected]");
      }
     
     
    }
     
    // prepare a web page to be send to a client (web browser)
    String prepareHtmlPage()
    {
      String htmlPage =
         String("HTTP/1.1 200 OK
    ") +
                "Content-Type: text/html
    " +
                "Connection: close
    " +  // the connection will be closed after completion of the response
                "Refresh: 5
    " +  // refresh the page automatically every 5 sec
                "
    " +
                "<!DOCTYPE HTML>" +
                "<html>" +
                "Analog input:  " + String(analogRead(A0)) +
                "</html>" +
                "
    ";
      return htmlPage;<br>}
    

      

  • 相关阅读:
    V2EX 上收藏Top200
    在heroku上部署gost代理服务端
    nano编辑器使用教程
    Amazon EC2免费VPS防止超额被扣钱三大方法:流量 硬盘读写 运行时长
    Go语言开发环境配置
    HTML5 and CSS3 开发
    使用 Eclipse PhoneGap 构建 Android 应用程序入门
    脚本之家
    CSS网页布局全精通
    使用面向 iOS 的本机插件扩展 PhoneGap
  • 原文地址:https://www.cnblogs.com/kekeoutlook/p/8306670.html
Copyright © 2011-2022 走看看