Post your best Lua script examples here

User avatar
By alonewolfx2
#4185 here is heap result on the start with webserver
Code: Select all
NodeMcu 0.9.2 build 20141207  powered by Lua 5.1.4
> print(node.heap())
8840


yes8s wrote:I've been testing this implementation for a few days now and for the most part it works great. I did make a couple of little modifications to better handle post requests and I'm also running a few additional functions for my applications.

When I embed lua code into the pht file I get a reset when I request the page from a browser. I've narrowed it down to the docode function being the cause. If I replace the function to just print heap to the console and return back the non decoded text, it is ok. I'm suspecting it may be a memory issue.

The heap is at about 5kb at the docode function that has been stripped back (as explained above). Obviously, when the original function is used the heap usage would be greater due to additional code and variables.

I'm curious, what is your heap at when you get to this function? Can somebody do a print heap inside the function and report?

Memory is starting to become an issue when you try to build an application that has a server and other functions and variables. The server part alone on my esp consumes over half the heap. I'm worried we've hit the wall too early.
User avatar
By alonewolfx2
#4187 its always crashing and restarting when click any links. on the chrome. (get or post and home in html page.)
but if browse in internet explorer its fine. have you any idea?
User avatar
By gerardwr
#4265
Erni wrote:I had a look at the newest (I wish there was a version number ) init.lua
If you put this code after line 81
Code: Select allfor k,v in pairs(reqdata) do
print (k,v)
end

You get a nice output.

Hello erni,

Thanks for sharing the result, is good for inspiration for us all.

Yes, this is a good solution, limiting the output to what you need at the serial port.

As a alternative you could print reqdata as total to the console, and do the parsing of the parameters in the URL on the connected MCU. Advantage could be that it does not slow the Lua interpreter down, and you do not have to handle multi-line input on your MCU.

When debugging I sent the entire HTTP request header to the console, at 9600 baud that takes a second or so.

I do not use a connected MCU but do everything on the ESP, preferably in a .PHT or .Lua file, so I do not have to change the init.lua often. To process a URL, including the parameters I intend to define a global var (ref. $_GET in PHP) that contains the full URL. In a .PHT or .LUA page I then can use the URL, get params from it, etc. Your code comes in handy for that ;) .

Nice going, have fun.

UPDATE : A new nodemcu firmware is released today, including a uart module. It has a uart.write function in it.
User avatar
By vincent1971
#4310 Is it possible to send the data from an input box in html to the lua server?

Example in html.

<!DOCTYPE html>
<html>
<body>

<form>
First name:<br>
<input type="text" name="firstname">
<br>
Last name:<br>
<input type="text" name="lastname">
</form>
</body>
</html>