esp8266 web server code example

Example 1: esp8266 wifi example

// Initialize the output variables as outputs
pinMode(output5, OUTPUT);
pinMode(output4, OUTPUT);
// Set outputs to LOW
digitalWrite(output5, LOW);
digitalWrite(output4, LOW);

Example 2: esp8266 wifi example

client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");

Example 3: esp8266 wifi example

<!DOCTYPE html><html>

Example 4: esp8266 wifi example

// Assign output variables to GPIO pins
const int output5 = 5;
const int output4 = 4;

Example 5: esp8266 wifi example

// turns the GPIOs on and off
if (header.indexOf("GET /5/on") >= 0) {
  Serial.println("GPIO 5 on");
  output5State = "on";
  digitalWrite(output5, HIGH);
} else if (header.indexOf("GET /5/off") >= 0) {
  Serial.println("GPIO 5 off");
  output5State = "off";
  digitalWrite(output5, LOW);
} else if (header.indexOf("GET /4/on") >= 0) {
  Serial.println("GPIO 4 on");
  output4State = "on";
  digitalWrite(output4, HIGH);
} else if (header.indexOf("GET /4/off") >= 0) {
  Serial.println("GPIO 4 off");
  output4State = "off";
  digitalWrite(output4, LOW);
}

Example 6: esp8266 wifi example

// Clear the header variable
header = "";
// Close the connection
client.stop();

Tags:

Misc Example