ESP8266 Web Server (Without Arduino)

99,097

167

14

Introduction: ESP8266 Web Server (Without Arduino)

About: Author, Blogger, Electronics Enthusiast and Entrepreneur. For complete Electronics Projects and Tutorials go to: http://randomnerdtutorials.com/start-here

Hey there,

A few weeks ago I've created a project with an ESP8266 called: ESP8266 Web Server without an Arduino.

That's exactly what you're going to build, if you follow all the steps in this Instructable.

It's amazing what you can do with this $4 WiFi Module.

The video below shows the final result of this project.

Step 1: Components

This project requires just a few components:

  • 1x ESP8266 (eBay link)
  • 1x FTDI Programmer (eBay link)
  • 2x LEDs
  • 2x Resistors
  • 1x Breadboard
  • Some jumper wires

Step 2: Flashing NodeMCU

For this project your need to flash your ESP8266 with NodeMCU.

Follow the circuit presented in this step and use the NodeMCU flasher to flash NodeMCU.

Flashing your ESP8266 with a new firmware is pretty straight forward, but if you need an in depth tutorial follow this blog post: How to Flash NodeMCU Firmware on the ESP8266.

Step 3: Uploading Lua Code

You need to upload this code into your ESP8266. Click here to do download the Lua code.

To upload Lua code to your ESP8266 I highly recommend using the ESPlorer IDE that you can download here.

Note: Your file should be named “init.lua“ and you need to replace line #2 with your network details

Step 4: Final Circuit

Follow the schematics in this step to build your web server.

Step 5: Accessing Your Web Server (Demonstration)

To access your web server type in the URL bar your ESP8266 IP address.

And below you can watch the final result!

No you can control your LEDs (or any output) with your smartphone, tablet or laptop.

I hope you enjoyed this project, if you want to learn more about the ESP8266 check out my eBook: Home Automation Using ESP8266 or visit my blog.

Thanks for reading,

-Rui from Random Nerd Tutorials

Share

    Recommendations

    • Creative Misuse Contest

      Creative Misuse Contest
    • Fix It! Contest

      Fix It! Contest
    • Metalworking Contest

      Metalworking Contest

    14 Discussions

    Hey guys. I tried this project. But have issue with Esplorer. When I try to flash nodeMCU It works like perfect. The Led On the ESP Flash Synchronous with the led on the FTDI But when I tried to connect The ESP With Esploarer The thing doesnt work. It says Connecting to MCU and waits like 5 minutes and Program doesnt respond my clicks. And Im tried to many ways but never works true. I'm done the wiring like 20 times maybe :D Pulled The gpio0 To Low and high but ıt doesnt work. can anyone help me ? Thanks

    An excellent demonstration. From the look of things it will only have enough connections for just two devices (LED's).

    Am I correct in thinking this or could you add more lines of control with this device ?

    Richard

    Fanstatic post! Thanks for sharing! Hey, I'd like to make the ON and OFF buttons bigger (e.g. 0.5in. X 0.5in.) but, I am no coder. Any suggestions?

    Thanks for the woderful post , I have followed the steps you have instructed and I am able to control home appliances.

    but when i want to try my hands on esp12 I am not able to access all gpios i have followed this link

    http://www.esp8266.com/wiki/doku.php?id=esp8266_gpio_pin_allocations and modified lua code accordingly but gpio 12/13/14/15 are not working as gpio any solution pls let me know.

    Thanks

    Praveen Kumar

    Thanks for your post- iT WORKS

    Modified code - to work without WIFI- STANDALONE AP

    AccessPoint with WEBSERVER (No HOME WIFI or Network Needed)

    I have modified the above script (init.lua) adding a few lines to
    make the esp into an Access point and webserver. Now with script flashed
    into the esp8266 with name as init.lua the ESP you will be able to
    connect from your browser or Mobile directly to the ESP without having
    to go through your HOME WIFI.

    This is standalone webserver and access point. You will have to
    connect to the ESP ACCESS POINT and then type 192.168.4.1 which is the
    default address of the ESP Access point. All other devices connecting to
    the ESP8266_xxxx Access point will be given a IP address from the ESP.

    print(“Ready to start soft ap”)

    local str=wifi.ap.getmac();

    local ssidTemp=string.format(“%s%s%s”,string.sub(str,10,11),string.sub(str,13,14),string.sub(str,16,17));

    cfg={}

    cfg.ssid=”ESP8266_”..ssidTemp;

    cfg.pwd=””

    wifi.ap.config(cfg)

    wifi.sta.getip()

    led1 = 3

    led2 = 4

    gpio.mode(led1, gpio.OUTPUT)

    gpio.mode(led2, gpio.OUTPUT)

    srv=net.createServer(net.TCP)

    srv:listen(80,function(conn)

    conn:on(“receive”, function(client,request)

    local buf = “”;

    local _, _, method, path, vars = string.find(request, “([A-Z]+) (.+)?(.+) HTTP”);

    if(method == nil)then

    _, _, method, path = string.find(request, “([A-Z]+) (.+) HTTP”);

    end

    local _GET = {}

    if (vars ~= nil)then

    for k, v in string.gmatch(vars, “(%w+)=(%w+)&*”) do

    _GET[k] = v

    end

    end

    buf = buf..” AP WEBSERVER “;

    buf = buf..”GPIO0 ONOFF“;

    buf = buf..”GPIO2 ONOFF“;

    local _on,_off = “”,””

    if(_GET.pin == “ON1”)then

    gpio.write(led1, gpio.HIGH);

    elseif(_GET.pin == “OFF1”)then

    gpio.write(led1, gpio.LOW);

    elseif(_GET.pin == “ON2”)then

    gpio.write(led2, gpio.HIGH);

    elseif(_GET.pin == “OFF2”)then

    gpio.write(led2, gpio.LOW);

    end

    client:send(buf);

    client:close();

    collectgarbage();

    end)

    end)

    Connections while Programming the ESP8266-NodeMCU

    ESP8266 UNO

    VCC 3.3V

    CH_PD 3.3V

    GND GND

    GPIO1 GND

    TX TX

    RX RX

    Connections while Programming the ESP8266-Lua Script

    ESP8266 UNO

    VCC 3.3V

    CH_PD 3.3V

    GND GND

    GPIO1 OPEN

    TX TX

    RX RX

    Thanks for your post- iT WORKS

    Modified code - to work without WIFI- STANDALONE AP

    AccessPoint with WEBSERVER (No HOME WIFI or Network Needed)

    I have modified the above script (init.lua) adding a few lines to
    make the esp into an Access point and webserver. Now with script flashed
    into the esp8266 with name as init.lua the ESP you will be able to
    connect from your browser or Mobile directly to the ESP without having
    to go through your HOME WIFI.

    This is standalone webserver and access point. You will have to
    connect to the ESP ACCESS POINT and then type 192.168.4.1 which is the
    default address of the ESP Access point. All other devices connecting to
    the ESP8266_xxxx Access point will be given a IP address from the ESP.

    print(“Ready to start soft ap”)

    local str=wifi.ap.getmac();

    local ssidTemp=string.format(“%s%s%s”,string.sub(str,10,11),string.sub(str,13,14),string.sub(str,16,17));

    cfg={}

    cfg.ssid=”ESP8266_”..ssidTemp;

    cfg.pwd=””

    wifi.ap.config(cfg)

    wifi.sta.getip()

    led1 = 3

    led2 = 4

    gpio.mode(led1, gpio.OUTPUT)

    gpio.mode(led2, gpio.OUTPUT)

    srv=net.createServer(net.TCP)

    srv:listen(80,function(conn)

    conn:on(“receive”, function(client,request)

    local buf = “”;

    local _, _, method, path, vars = string.find(request, “([A-Z]+) (.+)?(.+) HTTP”);

    if(method == nil)then

    _, _, method, path = string.find(request, “([A-Z]+) (.+) HTTP”);

    end

    local _GET = {}

    if (vars ~= nil)then

    for k, v in string.gmatch(vars, “(%w+)=(%w+)&*”) do

    _GET[k] = v

    end

    end

    buf = buf..” AP WEBSERVER “;

    buf = buf..”GPIO0 ONOFF“;

    buf = buf..”GPIO2 ONOFF“;

    local _on,_off = “”,””

    if(_GET.pin == “ON1”)then

    gpio.write(led1, gpio.HIGH);

    elseif(_GET.pin == “OFF1”)then

    gpio.write(led1, gpio.LOW);

    elseif(_GET.pin == “ON2”)then

    gpio.write(led2, gpio.HIGH);

    elseif(_GET.pin == “OFF2”)then

    gpio.write(led2, gpio.LOW);

    end

    client:send(buf);

    client:close();

    collectgarbage();

    end)

    end)

    Connections while Programming the ESP8266-NodeMCU

    ESP8266 UNO

    VCC 3.3V

    CH_PD 3.3V

    GND GND

    GPIO1 GND

    TX TX

    RX RX

    Connections while Programming the ESP8266-Lua Script

    ESP8266 UNO

    VCC 3.3V

    CH_PD 3.3V

    GND GND

    GPIO1 OPEN

    TX TX

    RX RX

    0
    None
    TomG26

    2 years ago

    I got it to work just fine. However, the ESP8266 does not seem to respond to ARP broadcast requests. APR works fine with AT command set firmware, but not with NodeMCU Lua.

    0
    None
    JGUIJ

    2 years ago

    next step: not only on/off but dimming the lights :-)

    0
    None
    JGUIJ

    2 years ago

    Great! At last the first web server I run on ESP without externals! Successfully!

    Thanks.

    Hi. Your project is very interesting, i follow all your step, flashed firmware, with no issue, but i have a problem uploading init.lua with esplorer. The program stuck in busy state and nothing is uploaded. What's wrong? Regards, Andrea.

    Hi, Rui... i am using arduino as a usb to serial programmer in case of FTDI programmer,please tell me the connection of arduino and esp8266 for uploadin lua code in esp8266....and also the power connection for esp8266...

    Great thing ..im gonna try ordering these with velleman later