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

User avatar
By danbicks
#18945 Hi dnc40085,

Why is there a problem in scan for access point delay?

My sketch does exactly that, scans for a list, looks through and if the access point I am looking for is found attempts connection. I suppose if it takes 3 seconds to scan and find a list for some this may be a problem, but for many of my apps is fine.

I have played with nodemcu, and like the fact that you can re script on the fly. Only problem I have with this is that it consumes to much system resources.

Thanks

Dans
User avatar
By dnc40085
#18959
danbicks wrote:Why is there a problem in scan for access point delay?
If you're setting up an AP it's not really much of an issue aside from the unnecessary memory used to temporarily store the AP info.

However, if you're on battery power every mS counts and scanning for all APs then processing the list takes about 2.5 seconds, while scanning for a specific access point on a specific channel only takes about 130 milliseconds. that combined with manually assigning an ip(so there is no waiting for a DHCP lease), the difference could potentially add days or even weeks to battery life.
User avatar
By MicKeyCZ
#18998 Hi Dnc40085,
no flame, but how often your battery powered device needs to scan wifi? :)

I flashed new firmware "NodeMCU 0.9.6 build 20150405", format, update my testing file "scan.lua":
Code: Select allssid = 'Home123'
found = nil
wifi.setmode(wifi.STATIONAP)

scan_cfg = {}
scan_cfg.ssid = ssid

wifi.sta.getap(scan_cfg, function(t)
    print(t)
    found = 'really???'
    for k,v in pairs(t) do print(k, v) end
end)

tmr.alarm(0, 500, 1, function()
    if (found == nil) then
        print('scanning...')
    else
        tmr.stop(0)
        if (found == false) then
            print('not found')
        else
            print('found', ssid, found)
        end
    end
end)

and I got this output (bssid edited):
Code: Select allŕ˙@ú)Ď(˙ťÍ�ü�óá

NodeMCU 0.9.6 build 20150405  powered by Lua 5.1.4
lua: cannot open init.lua
> dofile('scan.lua')
> scanning...
scanning...
scanning...
scanning...
table: 0x3fff6150
xx:xx:xx:xx:xx:xx   Home,-83,1,6
found   Home123   really???
dofile('scan.lua')
> scanning...
scanning...
scanning...
scanning...
scanning...
PANIC: unprotected error in call to Lua API (attempt to call a number value)
�{íˇś‹h˙ů 4śřá

NodeMCU 0.9.6 build 20150405  powered by Lua 5.1.4
lua: cannot open init.lua
> dofile('scan.lua')
> scanning...
scanning...
scanning...
scanning...
table: 0x3fff6150
xx:xx:xx:xx:xx:xx   Home,-83,1,6
found   Home123   really???
dofile('scan.lua')
> scanning...
scanning...
scanning...
scanning...
scanning...
PANIC: unprotected error in call to Lua API (attempt to call a number value)
Í‹ű ŤyIlţyR†ü>çř

NodeMCU 0.9.6 build 20150405  powered by Lua 5.1.4
lua: cannot open init.lua
>

Scanning takes the same time as in my previous code.
Every second "dofile('scan.lua')" fails.
Looking for "Home123" (does not exist) and found "Home" (exists).

Bugs or new features? :D

M

Edit:
I understand the reason for exchanging SSID and BSSID in the table, but is it really necessary to change the behavior of the function instead of creating new ones?