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

User avatar
By dnc40085
#19005
MicKeyCZ wrote:Hi Dnc40085,
no flame, but how often your battery powered device needs to scan wifi? :)
My current project calls wifi.sta.getap() frequently to get the RSSI to use as a sort of proximity detection.

Looking for "Home123" (does not exist) and found "Home" (exists).
this must be a bug in the sdk, I checked the string in the struct that holds the scan_config and it indeed is passing "Home123" to the wifi_station_scan function which then seems to ignore the trailing numbers, this needs further testing...

PANIC: unprotected error in call to Lua API (attempt to call a number value)
this one I can't figure out, the error seems to be occurring after both wifi_station_listap and wifi_scan_done functions have finished.

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?
It needed to be changed, the old format overwrote any duplicate SSIDs in the table and some might find that undesirable. Also, creating new functions would most likely decrease the available flash and/or heap.

I could always submit a PR that would allow switching the table format between new and old versions. :P
User avatar
By MicKeyCZ
#19032
dnc40085 wrote:
MicKeyCZ wrote:Hi Dnc40085,
no flame, but how often your battery powered device needs to scan wifi? :)
My current project calls wifi.sta.getap() frequently to get the RSSI to use as a sort of proximity detection.

Ok, that makes sense :)
After filling "scan_cfg.channel" scanning is faster, but I have to know the correct/current channel number.
Is not it another reason for updating to the newer SDK? :?:

Looking for "Home123" (does not exist) and found "Home" (exists).
this must be a bug in the sdk, I checked the string in the struct that holds the scan_config and it indeed is passing "Home123" to the wifi_station_scan function which then seems to ignore the trailing numbers, this needs further testing...

I can go through the table and check if contains my SSID, however with the old format of the table it was easier and faster ;)

PANIC: unprotected error in call to Lua API (attempt to call a number value)
this one I can't figure out, the error seems to be occurring after both wifi_station_listap and wifi_scan_done functions have finished.

So it is a mistake in my script or firmware (generated by http://frightanic.com/nodemcu-custom-build/ before 14 hours, based on dev096)?
I suppose you scan wifi more frequently.

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?
It needed to be changed, the old format overwrote any duplicate SSIDs in the table and some might find that undesirable. Also, creating new functions would most likely decrease the available flash and/or heap.

I could always submit a PR that would allow switching the table format between new and old versions. :P

As I wrote above, I understand the reason for the change. I do not have too many scripts for update, but ...
IMHO you should not change the default behavior of existing functions, new behavior should be configurable by parameters.
Similarly to adding a new parameter "cfg" to "wifi.sta.getap(cfg, function(table))".

Thx,
M
User avatar
By dnc40085
#19086
MicKeyCZ wrote:Ok, that makes sense :)
After filling "scan_cfg.channel" scanning is faster, but I have to know the correct/current channel number.
Is not it another reason for updating to the newer SDK? :?:
I found that a week ago and yes, I agree NodeMCU needs to be updated to v1.x SDK, but then so do others

So it is a mistake in my script or firmware (generated by http://frightanic.com/nodemcu-custom-build/ before 14 hours, based on dev096)?
I suppose you scan wifi more frequently.
it seems to be something in the tmr.alarm function that's causing the error. It doesn't like something about the way the "if found==..." code is written. when I repeatedly run "wifi.sta.getap()" one after another(as fast as I can press alt-L) I never get a crash.

As I wrote above, I understand the reason for the change. I do not have too many scripts for update, but ...
IMHO you should not change the default behavior of existing functions, new behavior should be configurable by parameters.
Similarly to adding a new parameter "cfg" to "wifi.sta.getap(cfg, function(table))".
When I added the parameter to set a scan configuration I made sure that it was backwards compatible with the old syntax, but then when I changed the output syntax I thought of it as a bug that needed to be fixed and didn't even think about preserving backward compatibility, my mistake.

To remedy this oversight, I've submitted a PR to the dev096 branch that should add functionality to allow switching between old(default) and new format once it's merged.
User avatar
By MicKeyCZ
#19092 Hi dnc40085,
thanks for the suggestion.
You're right, there is something wrong with "wifi.sta.getap" and "tmr.alarm" in my current firmware (no error with previous nodemcu_float_0.9.5_20150318.bin).
Simplified script:
Code: Select allwifi.setmode(wifi.STATIONAP)

function listap(t)
    print("list")
    --for k,v in pairs(t) do print(k, v) end
end
wifi.sta.getap(listap)

tmr.alarm(0, 1000, 1, function()
    print("alarm")
end)

and output:
Code: Select all> dofile('scan2.lua')
> alarm
alarm
list
alarm
alarm
alarm
tmr.stop(0)
> wifi.sta.getap(listap)
list
> wifi.sta.getap(listap)
list
> wifi.sta.getap(listap)
list
> wifi.sta.getap(listap)
list
> wifi.sta.getap(listap)
list
> dofile('scan2.lua')
> alarm
alarm
alarm
PANIC: unprotected error in call to Lua API (attempt to call a number value)
˘�í@4˙r)¶řz”h˙śůř

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


dnc40085 wrote:To remedy this oversight, I've submitted a PR to the dev096 branch that should add functionality to allow switching between old(default) and new format once it's merged.

Thank you for the PR, I really appreciate it ;)

M