#include // https://github.com/tzapu/WiFiManager #include ESP8266WebServer server(80); const int led = 13; const int strobe_pin = 2; void handleRoot(); void strobe_on(); void setup() { pinMode(led, OUTPUT); pinMode(strobe_pin, OUTPUT); digitalWrite(led, 0); WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP // put your setup code here, to run once: Serial.begin(115200); // WiFi.mode(WiFi_STA); // it is a good practice to make sure your code sets wifi mode how you want it. //WiFiManager, Local intialization. Once its business is done, there is no need to keep it around WiFiManager wm; //reset settings - wipe credentials for testing //wm.resetSettings(); // Automatically connect using saved credentials, // if connection fails, it starts an access point with the specified name ( "AutoConnectAP"), // if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect()) // then goes into a blocking loop awaiting configuration and will return success result bool res; // res = wm.autoConnect(); // auto generated AP name from chipid // res = wm.autoConnect("AutoConnectAP"); // anonymous ap res = wm.autoConnect("AutoConnectAP", "password"); // password protected ap if (!res) { Serial.println("Failed to connect"); // ESP.restart(); } else { //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); } server.on("/", handleRoot); server.on("/on", strobe_on); server.on("/off", strobe_off); server.begin(); Serial.println("HTTP server started"); } void loop() { // put your main code here, to run repeatedly: server.handleClient(); } void handleRoot() { digitalWrite(led, 1); const char MYHTML[] PROGMEM = "" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "
\n" " \n" " \n" "
\n" " \n" " \n"; server.send(200, "text/html", MYHTML); digitalWrite(led, 0); } void strobe_on() { digitalWrite(strobe_pin, 1); server.send(200, "text/plain", "stobe on"); } void strobe_off() { digitalWrite(strobe_pin, 0); server.send(200, "text/plain", "stobe off"); }