Moderator: igrr
But IMHO, it is better to use a separate server for webpages, the micro-controller is just too limited in resources to serve up complex or large pages.
That is what hosting packages are for. Very inexpensive. And if you don't need a personalized domain name, free options are available. You would need to reference the pages' images/media residing on a separate server anyway as you would soon run out of flash memory to store the page's dependent files if you try do serve up everything on an ESP8266.
Good luck!
srv=net.createServer(net.TCP)
srv:listen(8266,function(conn)
conn:on("receive", function(client,request)
.
.
.
file.open("mypage.htm","r")
while true do
str = file.readline()
if str == nil then break end
client:send(buf);
end
file.close()
end)
end)
Create your html file (mypage.htm) and load it to the ESP8266 the same way init.lua is loaded.
I am not a big fan of NodeMCU since it does not leave much memory for your code and it leaks memory like a sieve.
Hope this gives you an idea how to do it. Good luck with your project.