As the title says... Chat on...

User avatar
By MicKeyCZ
#19203 Ok, there is something wrong with callbacks, or in my misunderstanding of LUA (still LUA newbie) :D

scan2.lua:
Code: Select allwifi.setmode(wifi.STATIONAP)
function listap(t) print(tmr.now(), "list", t) end
tmr.alarm(0, 500, 1, function() print(tmr.now(), "alarm") end)

output:
Code: Select alldofile('scan2.lua')
> 6391624   alarm
6891613   alarm
7391647   alarm
wifi.sta.getap(listap)
7891616   alarm
> 8391743   alarm
8891676   alarm
9391687   alarm
9891701   alarm
10025270   list   table: 0x3fff6128
10391689   alarm
10891616   alarm
wifi.sta.getap(listap)
11391640   alarm
> 11891730   alarm
12391685   alarm
12891674   alarm
13391685   alarm
13547893   list   table: 0x3fff60e8
13891646   alarm
tmr.stop(0)
> wifi.sta.getap(listap)
> 22113567   list   table: 0x3fff60c0
dofile('scan2.lua')
> 25694647   alarm
26194658   alarm
wifi.sta.getap(listap)
> 26694676   list   nil
27194741   list   nil
27694714   list   nil
28194694   list   nil
28685958   list   table: 0x3fff6128
28694613   alarm
29194667   alarm
wifi.sta.getap(listap)
> 29694755   list   nil
30194703   list   nil
30694690   list   nil
31194705   list   nil
31648996   list   table: 0x3fff6128
31694622   alarm
32194664   alarm
32694654   alarm
tmr.stop(0)
>

"list nil" is printed in tmr.alarm interval.

M
User avatar
By dnc40085
#19220 Hmm interesting.
if you are willing, I have a firmware I'd like you to try out, it has a bunch of debug code added to the wifi and tmr modules which should help find where this error is coming from.

Please try it with your most recent code and with the code that produces the error:
PANIC: unprotected error in call to Lua API (attempt to call a number value)
Attachments
Firmware notes: upload to 0x00000, baud rate 115200, modules disabled(MQTT, COAP, U8G, WS2812, CJSON), wifi.sta.getap output select , debug enabled for wifi and tmr modules
(243.69 KiB) Downloaded 244 times
User avatar
By TerryE
#19226 @dnc40085, have a scan of the latest version of my Unofficial FAQ where I discuss this. There's definitely something dodgy with how these two callback wrappers garbage collect dereferenced Lua scripts that have been left in the registry.

Let me know if there's anything that you disagree about.
User avatar
By MicKeyCZ
#19235
dnc40085 wrote:Hmm interesting.
if you are willing, I have a firmware I'd like you to try out, it has a bunch of debug code added to the wifi and tmr modules which should help find where this error is coming from.

Please try it with your most recent code and with the code that produces the error:
PANIC: unprotected error in call to Lua API (attempt to call a number value)

@dnc40085: See attachements. I just edited or deleted some table entries ;)

@TerryE: Thanks for the FAQ, good job :)

M
Attachments
(4.36 KiB) Downloaded 521 times
(9.25 KiB) Downloaded 510 times