Post your best Lua script examples here

User avatar
By xtal
#39731 NodeMCU/LUA SDK 1.5.0 and 1.5.1 have not tried other.....

I have tried several variations of this with same results...

------------------------------------------
-- Function for RSSI----------------------

local function listap(t)
for k,v in pairs(t) do
print(k.." : "..v)
vt.sbuf = vt.sbuf ..k.." : "..v
end
listap=nil
collectgarbage()
end

-- code snip -----------------------------


elseif cmd=="Baud" then
if vt.baud==9600 then
vt.baud=38400
elseif vt.baud==38400 then
vt.baud=115200
elseif vt.baud==115200 then
vt.baud=9600
end
uart.setup(0,vt.baud,8,0,1)
elseif cmd=="Adc" then vt.adc = adc.read(0)

elseif cmd=="Rssi" then
if cmd=="Rssi" then
cmx = cmd
cmd = "--"
print("---- RSSI ----")
--uart.write(0."--SSID--")
wifi.sta.getap(listap)
listap=nil

end


I'm trying to use the above code , the PROBLEM is

the first time I click the Rssi button the code
prints ---- RSSI ---- and print the rssi/etc and sbuf is up dated....

any later Rssi click just prints ---- RSSI ---- and nothing else
it is not hung ? / clicking other buttons work....

What do I need to do ?????
User avatar
By xtal
#39841 Solved - workaround
Leaving function inline seems to work ok ... the following works
wifi.sta.getap(function(t)
for key,value in pairs(t) do
enc, rssi, bssid, chan = string.match(value,
"(%d),(-?%d+),(%x%x:%x%x:%x%x:%x%x:%x%x:%x%x),(%d+)")
a=string.sub (value, 0 , 1 ) -- auth = 0 = open
vt.sbuf = vt.sbuf..rssi.." - "..enc.." - "..bssid.." - "..chan.." - "..key.."\r\n"
end
end)