HTTP webServer


#include 
#include 
#include 


#ifndef APSSID
#define APSSID "your-ssid"
#define APPSK  "your-password"
#endif

const char* ssid = APSSID;
const char* password = APPSK;

ESP8266WebServer server(80);//设置web服务器访问端口

void handleRoot(){//根目录发送主页
  server.send(200, "text/html", "\
            \
              \
            \
              

wifi setting

\
\ wifi name:
\ \
\ wifi password:
\ \
\ \
\ \ "); } void getDemo(){//get 访问 demo地址 Serial.println(server.uri()); Serial.println(server.arg("name")); Serial.println(server.arg("password")); server.send(200, "text/html", "\ \ \ \

======OK======

\ \ "); }//==================================================== void handleNotFound(){//访问 地址不存在返回404 server.send(200, "text/html", "\ \ \ \

======ERROR======

\ \ "); } void setup(){ Serial.begin(115200); WiFi.mode(WIFI_AP); WiFi.softAP(ssid, password); server.on("/", handleRoot);//注册访问根目录回调函数 server.on("/demo",getDemo);//注册访问demo回调函数 server.onNotFound(handleNotFound);//注册无地址访问函数 server.begin();//启动服务器 Serial.println(""); Serial.println("HTTP server started"); } void loop() { server.handleClient();//运行服务器 }

你可能感兴趣的:(HTTP webServer)