gateway=AP閘道
sunet=網路遮罩
/* Name: AP.ino Created: 2017/2/22 上午 02:56:01 Author: C.Y.Fang */ #include "ESP8266WiFi.h" //AP SSID const char *ssid = "ssid"; //AP password const char *password = "password"; //LED pin const int LED = SCK; //HTTP Server WiFiServer server(80); //local IP IPAddress local(192,168,10,254); //gateway IPAddress gateway(192,168,10,254); //subnet IPAddress subnet(255,255,255,0); void setup() { pinMode(LED,OUTPUT); Serial.begin(115200); WiFi.begin(); WiFi.mode(WIFI_AP); WiFi.softAP(ssid, password); WiFi.softAPConfig(local, gateway, subnet); server.begin(); } void loop() { WiFiClient client = server.available(); if (!client) return; while (!client.available()) delay(100); String request = client.readStringUntil('\r'); Serial.println(request); client.flush(); int value = request.indexOf("/LED=ON") != -1 ? HIGH : LOW; client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html; charset=utf-8"); client.println(""); client.println("<!DOCTYPE HTML>"); client.println("<html>"); client.print("Led status is: "); if (value == HIGH) client.print("On"); else client.print("Off"); client.println(" "); client.println("Click <a href=\"/LED=ON\">here</a> turn the LED on<br>"); client.println("Click <a href=\"/LED=OFF\">here</a> turn the LED off<br>"); client.println("</html>"); digitalWrite(LED, value); delay(2000); }