Simple standalone http server made with esp8266 and nodemcu

The following code is a standalone http server made with esp8266 and nodemcu written in lua.
The esp8266 is in wifi.SOFTAP mode (SoftAP is an abbreviated term for “software enabled access point.” This is software enabling a computer which hasn’t been specifically made to be a router into a wireless access point. It is often used interchangeably with the term “virtual router”.)

You can connect connect your smarthone with the esp8266 direct without any router or other network infrasructure. Just load the following code as init.lua on you eso8266 flash ram and reset.

print("WIFI control")

print("ESP8266 mode is: " .. wifi.getmode())

if ssid and password then
  print("ESP8266 SSID is: " .. cfg.ssid .. " and PASSWORD is: " .. cfg.password)

print("ESP8266 AP IP now is: " .. wifi.ap.getip())

c:on("receive", function(c, pl)
  c:send("HTTP/1.1 200 OK\r\n") 
  c:send("Connection: close\r\n\r\n")
  c:send(" ")
  c:send(" ")

ESP8266 Wireless control setup

") majorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed =; c:send("NodeMCU "..majorVer.."."..minorVer.."."..devVer.."

") bat = adc.readvdd33()/1000 c:send("Battery "..bat.."

") remain, used, total=file.fsinfo() c:send("File system info:
Total : "" Bytes
Used : "..used.." Bytes
Remain: "..remain.." Bytes
") c:close() end) end)

The following circuit shows the min. configuration for your esp8266 to get the best stability.

If you ues a board with GPIO16 (Not ESP-01) you can connect the GPIO16 with REST to use the dsleep function. Otherwise your esp8266 will not wake up after execution of dsleep.

Connect the esp8266 to the wireless network

For the IoT you can use a cheap esp8266 microcontroller with WiFi onboard. To connect the esp8266 to the wireless network you can use the following lua snippet that will work with the nodemcu firmware.

After connecting to the internet, you can create a TCP/IP server or client to send and receive data from your esp8266 microcontroller.