Current Lua downloadable firmware will be posted here

User avatar
By zeroday
#3086
picstart1 wrote:The code below only calls blink one time
Code: Select allled = 8
i=1
ledstate=0

gpio.mode(led,gpio.OUTPUT)

tmr.alarm(1000,1,blink())


function blink()
print(i)
if ledstate==0 then
  gpio.write(led,gpio.HIGH)
  ledstate=1
 else
 gpio.write(led,gpio.LOW)
 ledstate=0
 end
i=i+1
if i==10 then
 print("stop")
 tmr.stop()
end
print("blinked")
end

the code below works
Code: Select allled = 8
i=1
ledstate=0

gpio.mode(led,gpio.OUTPUT)

tmr.alarm(1000,1,
function ()
print(i)
if ledstate==0 then
  gpio.write(led,gpio.HIGH)
  ledstate=1
 else
 gpio.write(led,gpio.LOW)
 ledstate=0
 end
i=i+1
if i==10 then
 print("stop")
 tmr.stop()
end
print("blinked")
end

)


The only difference is the function isn't named and is inline with tmr.alarm
Is this my error or a bug?


trying to put function definition before tmr.alarm() call may be?
I don't get my unit handy, can't test it.
User avatar
By alonewolfx2
#3089 i am trying to send telnet.lua example and i am getting this error. what am i suppose to do?

Code: Select allNodeMcu 0.9.2 build 20141120 powered by Lua 5.1.4
> function startServer()
>> print("AP connected IP:")
>> print(wifi.sta.getip())
>> sv=net.createServer(net.TCP)
>> sv:listen(8080, function(conn)
>> print("Console connected.")
>> function s_output(str)
>> if (conn~=nil) then
>> conn:send(str)
>> end
>> end
>> node.output(s_output,1)
>> conn:on("receive", function(conn, pl)
>> node.input(pl)
>> if (conn==nil) then
>> print("conn is nil.")
>> end
lua: not enough memory
PANIC: unprotected error in call to Lua API (not enough memory)
User avatar
By scargill
#3090 You are RIGHT - but it's taking FAR too long to recover the heap.

So here are the values I'm getting, hitting refresh on the page every second..
5896
5496
5080
4688
4304 (wait 30 secs)
4688
4304 (wait 3 minues)
5856 (- note not as high as it was originally
5080
4688 (wait 5 minutes)
5856
5080
...etc

and at 3100 - the next refresh - the board resets...



zeroday wrote:
scargill wrote:I was getting SO excited...

So I took the new webserver example, added a counter - and checked for an argument like http://www.mysite.com/?myarg=HELLO

Looked up the LUA docs - found the way to do it and


> mycounter=0
> srv=net.createServer(net.TCP)
> srv:listen(80,function(conn)
>> conn:on("receive",function(conn,payload)
>> if string.find(payload,"?myarg=") then
>> mycounter=mycounter+1
>> m="<br/>Value= " .. string.sub(payload,string.find(payload,"?myarg=")+7,string.find(payload,"HTTP")-2)
>> else
>> m=""
>> end
>> conn:send("<h1> Hello, this is Pete's web page.</h1>How are you today.<br/> Count=" .. mycounter .. m)
>> end)
>> conn:on("sent",function(conn) conn:close() end)
>> end)
>



Absolutely GREAT... but ran it a dozen times, the counter worked, the argument came back and then.... I have NO idea why it crashed.



> c_GORSvfJSz.Szfn
Pete's LUA module 0.1
NodeMcu 0.9.2 build 20141120 powered by Lua 5.1.4
>
Loading functions
Connecting
Connected to.loft-east.IP:.0.0.0.0
OK


Try run it 5 times, take a break, another 5 times, take a break...
the lua in this firmware isn't fast enough to collect memory back.

or, can you also
Code: Select allprint(node.heap())
every time when a client connected? to see how much ram left when it crash.