---
# System prepended metadata

title: IoT (8266 Web Server)

---

# IoT (8266 Web Server)

```
/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example runs directly on ESP8266 chip.

  Note: This requires ESP8266 support package:
    https://github.com/esp8266/Arduino

  Please be sure to select the right ESP8266 module
  in the Tools -> Board menu!

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266WebServer.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "nzMhH0FHvu7R17h0oFjaV2Am4DhvrtyR";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "WeWork"; //change to your own ssid
char pass[] = "P@ssw0rd"; //change to your own wifi password

ESP8266WebServer server(80);

uint8_t LEDpin = 2;
bool LEDstatus = LOW;


void setup()
{
  // Debug console
  Serial.begin(9600);

  pinMode(LEDpin, OUTPUT);

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.print("Attempting to connect to SSID: ");
  Serial.print(ssid);
  
  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(5000);
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());  

  server.on("/", handle_OnConnect);
  server.on("/on", handle_ledon);
  server.on("/off", handle_ledoff);

  server.begin();
  Serial.println("HTTP server started");

  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  server.handleClient();
  if(LEDstatus)
  {digitalWrite(LEDpin, HIGH);}
  else
  {digitalWrite(LEDpin, LOW);}
  Blynk.run();
}

void handle_OnConnect() {
  server.send(200, "text/html", "hello"); 
}

void handle_ledon() {
  LEDstatus = HIGH;
  server.send(200, "text/html", "On"); 
}

void handle_ledoff() {
  LEDstatus = LOW;
  server.send(200, "text/html", "Off"); 
}

```