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

User avatar
By dnc40085
#19292 @MicKeyCZ thank you for the attachments
Code: Select all    TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
        TMR_DBG: User callback begin
15990942    alarm
        TMR_DBG: User callback end
    TMR_DBG: END FUNCTION: alarm_timer_common
wifi.sta.getap(listap)

    WIFI_DBG: BEGIN FUNCTION: wifi_station_listap
        WIFI_DBG: getap_output_format=0
        WIFI_DBG: wifi_station_scan is called, scan_cfg not used
    WIFI_DBG: END FUNCTION: wifi_station_listap
>   
TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
        TMR_DBG: User callback begin
16491130    list    nil
        TMR_DBG: User callback end
    TMR_DBG: END FUNCTION: alarm_timer_common

    TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
        TMR_DBG: User callback begin
16991009    list    nil
        TMR_DBG: User callback end
    TMR_DBG: END FUNCTION: alarm_timer_common

    TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
        TMR_DBG: User callback begin
17491103    list    nil
        TMR_DBG: User callback end
    TMR_DBG: END FUNCTION: alarm_timer_common

    TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
        TMR_DBG: User callback begin
17991088    list    nil
        TMR_DBG: User callback end
    TMR_DBG: END FUNCTION: alarm_timer_common

    WIFI_DBG: BEGIN FUNCTION: wifi_scan_done is called.
        WIFI_DBG: Create a new table on the stack
        WIFI_DBG: Add entry to table: Key:"Home"  Value:"1,-79,xx:xx:xx:xx:xx:xx,6"
    [4 entries deleted, sry :-) ]
        WIFI_DBG: User callback begin
18402095    list    table: 0x3fff7500
        WIFI_DBG: User callback end
    WIFI_DBG: END FUNCTION: wifi_scan_done END

    TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
        TMR_DBG: User callback begin
18490934    alarm
        TMR_DBG: User callback end
    TMR_DBG: END FUNCTION: alarm_timer_common
Interesting... somewhere along the line the reference for the tmr.alarm callback in the LUA_REGISTRYINDEX gets temporarily overridden by the reference for the wifi.sta.getap callback, that's definitely a problem.

Code: Select all    TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
        TMR_DBG: User callback begin
PANIC: unprotected error in call to Lua API (attempt to call a number value)
With this one, somewhere the user's callback function gets overwritten with a LUA_TNUMBER type with the value of 1.

I have no idea what's causing this problem. It's even more confusing that two different errors are coming from the same function.
User avatar
By MicKeyCZ
#19357
dnc40085 wrote:It's even more confusing that two different errors are coming from the same function.

There is a little difference.
In the first case, "wifi.sta.getap(..." is called after "tmr.alarm(..." and outside "dofile(...".
In the second case, "wifi.sta.getap(..." is called before "tmr.alarm(..." and inside "dofile(...".

So, I tried this
scan3.lua:
Code: Select allwifi.setmode(wifi.STATIONAP)
function listap(t) print(tmr.now(), "list", t) end
tmr.alarm(0, 1000, 1, function() print(tmr.now(), "alarm") end)
wifi.sta.getap(listap)

and there is no PANIC, just "list nil" :D
Code: Select alldofile('scan3.lua')
   TMR_DBG: BEGIN FUNCTION: tmr_alarm
      TMR_DBG: id=0
      TMR_DBG: interval=1000
      TMR_DBG: repeat=1
   TMR_DBG: END FUNCTION: tmr_alarm
   WIFI_DBG: BEGIN FUNCTION: wifi_station_listap
      WIFI_DBG: getap_output_format=0
      WIFI_DBG: wifi_station_scan is called, scan_cfg not used
   WIFI_DBG: END FUNCTION: wifi_station_listap
>    TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
      TMR_DBG: User callback begin
7462193   alarm
      TMR_DBG: User callback end
   TMR_DBG: END FUNCTION: alarm_timer_common
   TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
      TMR_DBG: User callback begin
8462195   alarm
      TMR_DBG: User callback end
   TMR_DBG: END FUNCTION: alarm_timer_common
   WIFI_DBG: BEGIN FUNCTION: wifi_scan_done is called.
      WIFI_DBG: Create a new table on the stack
      WIFI_DBG: Add entry to table: Key:"Home"  Value:"1,-84,xx:xx:xx:xx:xx:xx,6"
      WIFI_DBG: User callback begin
8658120   list   table: 0x3fff7548
      WIFI_DBG: User callback end
   WIFI_DBG: END FUNCTION: wifi_scan_done END
   TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
      TMR_DBG: User callback begin
9462066   alarm
      TMR_DBG: User callback end
   TMR_DBG: END FUNCTION: alarm_timer_common
   TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
      TMR_DBG: User callback begin
10462019   alarm
      TMR_DBG: User callback end
   TMR_DBG: END FUNCTION: alarm_timer_common
tmr.stop(0)
> dofile('scan3.lua')
   TMR_DBG: BEGIN FUNCTION: tmr_alarm
      TMR_DBG: id=0
      TMR_DBG: interval=1000
      TMR_DBG: repeat=1
   TMR_DBG: END FUNCTION: tmr_alarm
   WIFI_DBG: BEGIN FUNCTION: wifi_station_listap
      WIFI_DBG: getap_output_format=0
      WIFI_DBG: wifi_station_scan is called, scan_cfg not used
   WIFI_DBG: END FUNCTION: wifi_station_listap
>    TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
      TMR_DBG: User callback begin
14079103   list   nil
      TMR_DBG: User callback end
   TMR_DBG: END FUNCTION: alarm_timer_common
   TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
      TMR_DBG: User callback begin
15079103   list   nil
      TMR_DBG: User callback end
   TMR_DBG: END FUNCTION: alarm_timer_common
   WIFI_DBG: BEGIN FUNCTION: wifi_scan_done is called.
      WIFI_DBG: Create a new table on the stack
      WIFI_DBG: Add entry to table: Key:"Home"  Value:"1,-84,xx:xx:xx:xx:xx:xx,6"
      WIFI_DBG: User callback begin
15261102   list   table: 0x3fff7500
      WIFI_DBG: User callback end
   WIFI_DBG: END FUNCTION: wifi_scan_done END
   TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
      TMR_DBG: User callback begin
16078967   alarm
      TMR_DBG: User callback end
   TMR_DBG: END FUNCTION: alarm_timer_common
   TMR_DBG: START FUNCTION: alarm_timer_common (called by timer:0)
      TMR_DBG: User callback begin
17078924   alarm
      TMR_DBG: User callback end
   TMR_DBG: END FUNCTION: alarm_timer_common
tmr.stop(0)

M
User avatar
By dnc40085
#19401
MicKeyCZ wrote:There is a little difference.
In the first case, "wifi.sta.getap(..." is called after "tmr.alarm(..." and outside "dofile(...".
In the second case, "wifi.sta.getap(..." is called before "tmr.alarm(..." and inside "dofile(...".
My apologies, I didn't clarify what it was that I was talking about.

What I was referring to was the NodeMCU source function `alarm_timer_common()` and the problem that it's having with the "LUA_REGISTRYINDEX" and the `wifi_station_listap` function.
In one case it fails by calling the callback for wifi_station_listap instead of it's own.
The other case being that it fails by the callback(LUA_TFUNCTION) being replaced entirely by a number(LUA_TNUMBER) which is always "1".

The whole thing is just confusing, the only common thing between the two functions is that they both store their callbacks in the "LUA_REGISTRYINDEX", Other than that they are in separate modules that don't even refer to each other

But then I bet it wouldn't confuse me if I knew more about the "LUA_REGISTRYINDEX" than just "It's a place to store references to lua values". :lol:

On a side note: That pull request was merged today, I updated the dev096 wiki to reflect the changes