Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By atrus
#17410 I've seen the example webserver, but all the returned html/text has been hardcoded. Is there any way to serve separate webpages?
User avatar
By Dave S
#17411 You should check out the forum post http://www.esp8266.com/viewtopic.php?f=34&t=376. The ESP-HTTPD Project supports serving static pages. You will need to use the SDK.

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!
User avatar
By atrus
#17423 I'm not trying to serve excessively large or complex pages, just trying to keep the stuff the webserver serves separate from the webserver itself.
User avatar
By Dave S
#17510 You should be able to serve up a page using lua NodeMCU something like (listening on port 8266):
Code: Select allsrv=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.