Post your best Lua script examples here

User avatar
By Hoksmur
#6328 Hi.
Can you help me?
I ran http://www.esp8266.com/viewtopic.php?f=19&t=702&start=30#p4467 code and connect to esp telnet and browser (both), - chip doesnt answer and rebooting. Of cours, 'bigfile.html' exist on embedded filesystem.
I'd want send data more than 1460 byte. As I see - people from the forum did it. My esp8266 works in STA mode, router (DIR-615) has set MTU limit 1400.
And - my code. I'm trying to write web server, but not like a lhttpd, only for few 'files' with user messages into.
Attachments
(2.07 KiB) Downloaded 294 times
User avatar
By Hoksmur
#6823 Hi.
New iteration of my idea. Here is GitHub now.
Example for index.pht
Code: Select all<html><head><title>esp8266</title></head>
<body><h1>uLuaNode sample page</h1><hr>
Free mem: <b><?lua return tostring(node.heap()) ?></b><br>
<b>Called as </b><?lua local s1,s2,s3; s1,s2,s3=... return tostring(s1) ?><br>
<b>Parameters: </b><?lua local s1,s2,s3; s1,s2,s3=... return tostring(s2) ?><br>
<b>API message: </b><?lua local s1,s2,s3; s1,s2,s3=... return tostring(s3) ?><br>
<a href="/?param1=test"> Link for test paremeters</a><br>
GPIO0(lua #3): <?lua return gpio.read(3)?><br>
GPIO2(lua #4): <?lua return gpio.read(4)?><br>
</body></html>

There are two values for free memory:
first - from script into page
second - from user function.
test.png
User avatar
By micke_s
#7232 I thing i have a bugfix to the code.

#when a long file is requested we got a file.open error.
Code: Select allChanged:
if file.open(fname, "r") then
to:
if string.len(fname) <= 24 and file.open(fname, "r") then