Post your best Lua script examples here

User avatar
By to1140
#8606 Sorry to ask an entry level question -- I copied lhttpd.lua (renamed init.lua),index.pht,index.html to ESP8266; ran lhttpd.lua having no problem. But, attempting http://.../index.pht in Windows got time out. Is there instruction somewhere on how to use lhttpd? Thanks.



ozayturay wrote:Using ESPlorer v0.1 build 206 on a ESP03 module I'm getting unexpected symbol error. The only modification i made is renaming init.lua file to lhttpd.lua

Code: Select allNodeMCU 0.9.5 build 20150118  powered by Lua 5.1.4

> for n,s in pairs(file.list()) do print(n.." size: "..s) end
log.txt size: 17
index.html size: 230
lhttpd.lua size: 3020
index.pht size: 848

> dofile("lhttpd.lua")
lhttpd.lua:1: unexpected symbol near '?'



Any ideas?
User avatar
By to1140
#8672 Thank you for your reply. Yes, I noticed earlier post.

Here is what I got -- after the MemUsage, there is nothing in the web browser side.
--------------------
> SENT: node.restart()
node.restart()
> ???A??Z.???L2????H?NodeMcu 0.9.5 build 20150105 powered by Lua 5.1.4
lua: cannot open init.lua
> SENT: dofile("lhttpd.lua")
dofile("lhttpd.lua")
> GET:index.html, MemUsage:2200 (5632)
GET:favicon.ico, MemUsage:1896 (5488)
GET:favicon.ico, MemUsage:2104 (5056)
--------------------------

Thanks.



gerardwr wrote:
to1140 wrote:Any ideas?

viewtopic.php?f=19&t=702&start=40#p7860[/quote]
User avatar
By to1140
#8867 I asked the question in earlier post that I cannot get anything output to web browser side on using lhttpd.lua. Does anyone know if this is related to the following.

I can use client:send(...) only once. For example, the following code only sends out "Test send" to the browser.
---------------
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local buf = "";

--buf = buf.."<h1>Test send</h1><hr>"
--buf = buf.."<p>This is test1.</p>"
--buf = buf.."<p>This is test2.</p>"
--client:send(buf);

client:send("<h1>Test send</h1><hr>");
client:send("<p>This is test1.</p>");
client:send("<p>This is test2.</p>");

conn:on("sent",function(conn) conn:close(); conn = nil; end)
end)
end)
---------------

The firmware version is: NodeMcu 0.9.5 build 20150105 powered by Lua 5.1.4, which is the default of https://github.com/nodemcu/nodemcu-flasher. (Following the "Flash the Firmware" instructions on https://github.com/nodemcu/nodemcu-firmware to the latest firmware version didn't work.)

Thank you.