//// Parody on the first goal whenever messing with embedded systems, get a led to blink, example from wemos D1 Mini ESP12F 4mb ////
With a Twist, The blink should be manually performed. Via a web server on the unit. Web server the size of a thumbnail. What a time to be alive.
Below code is from a private repository shared between me and a friend 🙂
main.cpp
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266mDNS.h>
#include <ESP8266WebServer.h> // Include the WebServer library
#include “secret.h” //include WIFI SSID and PW
ESP8266WiFiMulti wifiMulti; // Create an instance of the ESP8266WiFiMulti class, called ‘wifiMulti’
ESP8266WebServer server(80); // Create a webserver object that listens for HTTP request on port 80
const int led = 2;
void handleLED();
void setup(void){
Serial.begin(9600); // Start the Serial communication to send messages to the computer
delay(10);
Serial.println(‘\n’);
pinMode(led, OUTPUT);
WiFi.begin(SSID_NAME, WIFIPASS); // Connect to the network
Serial.print(“Connecting to “);
Serial.print(SSID_NAME);
Serial.println(‘ ‘);
int i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
delay(1000);
Serial.print(“…”);
i++;
}
Serial.println(‘ ‘);
Serial.print(“Took “);
Serial.print(i);
Serial.print(” seconds to connect and receive response from DHCP.”);
Serial.println(‘\n’);
Serial.print(“Connected to “);
Serial.println(WiFi.SSID()); // Tell us what network we’re connected to
Serial.print(“IP address:\t”);
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
MDNS.notifyAPChange();
delay(1000);
if (MDNS.begin(“esp8266”)) { // Start the mDNS responder for esp8266.local
Serial.println(“mDNS responder started”);
} else {
Serial.println(“Error setting up MDNS responder!”);
}
server.on(“/”, HTTP_GET, handleRoot); // Call the ‘handleRoot’ function when a client requests URI “/”
server.on(“/LED”, HTTP_POST, handleLED); // Call the ‘handleLED’ function when a POST request is made to URI “/LED”
server.begin(); // Actually start the server
Serial.println(“HTTP server started”);
}
void loop(void){
server.handleClient(); // Listen for HTTP requests from clients
MDNS.update();
}
void handleRoot() { // When URI / is requested, send a web page with a button to toggle the LED
server.send(200, “text/html”, “<form action=\”/LED\” method=\”POST\”><input type=\”submit\” value=\”Toggle LED\”> </form> <br> <br> <form action=\”/DIST\” method=\”POST\”><input type=\”submit\” value=\”Measure distance\”></form>”);
}
void handleLED() { // If a POST request is made to URI /LED
digitalWrite(led,!digitalRead(led)); // Change the state of the LED
server.sendHeader(“Location”,”/”);
server.send(303); // Send it back to the browser with an HTTP status 303 (See Other) to redirect
}

