#include #include #include #include "AutoConnect.h" ESP8266WebServer server; AutoConnect portal(server); static const char mold_page[] PROGMEM = { "" "" "" "" "" "" "

" AUTOCONNECT_LINK(BAR_32) "

" "BUILT-IN LED
" "GPIO({{LED}}) : {{GPIO}}" "

lowhigh

" "" "" }; String getLEDPort(PageArgument& args) { return String(BUILTIN_LED); } String setColor(PageArgument& args) { return digitalRead(BUILTIN_LED) ? "Tomato" : "SlateBlue"; } String readLEDPort(PageArgument& args) { return digitalRead(BUILTIN_LED) ? "HIGH" : "LOW"; } PageElement elm_gpio(mold_page, { {"LED", getLEDPort}, {"COLOR", setColor}, {"GPIO", readLEDPort} }); PageBuilder root("/", { elm_gpio }); String gpio(PageArgument& args) { if (args.arg("v") == "low") digitalWrite(BUILTIN_LED, LOW); else if (args.arg("v") == "high") digitalWrite(BUILTIN_LED, HIGH); sendRedirect("/"); return ""; } PageElement elm_io("{{IO}}", { {"IO", gpio} }); PageBuilder io("/io", { elm_io }); void sendRedirect(String uri) { server.sendHeader("Location", uri, true); server.send(302, "text/plain", ""); server.client().stop(); io.cancel(); } bool atDetect(IPAddress softapIP) { Serial.println("Captive portal started, SoftAP IP:" + softapIP.toString()); return true; } void setup() { delay(1000); Serial.begin(115200); Serial.println(); pinMode(BUILTIN_LED, OUTPUT); // Put the home location of the web site. // But in usually, setting the home uri is not needed cause default location is "/". //portal.home("/"); // Starts user web site included the AutoConnect portal. portal.onDetect(atDetect); if (portal.begin()) { // Register the page request handlers. root.insert(server); io.insert(server); Serial.println("Started, IP:" + WiFi.localIP().toString()); } else { Serial.println("Connection failed."); while (true) { yield(); } } } void loop() { portal.handleClient(); if (WiFi.status() == WL_IDLE_STATUS) { ESP.reset(); delay(1000); } }