Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
1eea5ab1
Commit
1eea5ab1
authored
Jun 03, 2015
by
Vowstar
Browse files
Merge pull request #460 from dnc40085/dev096_wifi.sta.getap_output_select
Added option to wifi.sta.getap to allow changing output format
parents
fcde022c
353209fb
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/wifi.c
View file @
1eea5ab1
...
...
@@ -16,6 +16,7 @@
#include "smartconfig.h"
static
int
wifi_smart_succeed
=
LUA_NOREF
;
static
uint8
getap_output_format
=
0
;
static
void
wifi_smart_succeed_cb
(
void
*
arg
){
NODE_DBG
(
"wifi_smart_succeed_cb is called.
\n
"
);
...
...
@@ -71,13 +72,21 @@ static void wifi_scan_done(void *arg, STATUS status)
{
c_memcpy
(
ssid
,
bss_link
->
ssid
,
32
);
}
c_sprintf
(
temp
,
"%s,%d,%d,%d"
,
ssid
,
bss_link
->
rssi
,
bss_link
->
authmode
,
bss_link
->
channel
);
lua_pushstring
(
gL
,
temp
);
c_sprintf
(
temp
,
MACSTR
,
MAC2STR
(
bss_link
->
bssid
));
lua_setfield
(
gL
,
-
2
,
temp
);
// NODE_DBG(temp);
if
(
getap_output_format
==
1
)
//use new format(BSSID : SSID, RSSI, Authmode, Channel)
{
c_sprintf
(
temp
,
"%s,%d,%d,%d"
,
ssid
,
bss_link
->
rssi
,
bss_link
->
authmode
,
bss_link
->
channel
);
lua_pushstring
(
gL
,
temp
);
NODE_DBG
(
MACSTR
" : %s
\n
"
,
MAC2STR
(
bss_link
->
bssid
)
,
temp
);
c_sprintf
(
temp
,
MACSTR
,
MAC2STR
(
bss_link
->
bssid
));
lua_setfield
(
gL
,
-
2
,
temp
);
}
else
//use old format(SSID : Authmode, RSSI, BSSID, Channel)
{
c_sprintf
(
temp
,
"%d,%d,"
MACSTR
",%d"
,
bss_link
->
authmode
,
bss_link
->
rssi
,
MAC2STR
(
bss_link
->
bssid
),
bss_link
->
channel
);
lua_pushstring
(
gL
,
temp
);
lua_setfield
(
gL
,
-
2
,
ssid
);
NODE_DBG
(
"%s : %s
\n
"
,
ssid
,
temp
);
}
bss_link
=
bss_link
->
next
.
stqe_next
;
}
...
...
@@ -590,9 +599,14 @@ static int wifi_station_setauto( lua_State* L )
* scan and get ap list as a lua table into callback function.
* Syntax:
* wifi.sta.getap(function(table))
* wifi.sta.getap(format, function(table))
* wifi.sta.getap(cfg, function(table))
* wifi.sta.getap(cfg, format, function(table))
* Parameters:
* cfg: table that contains scan configuration
* Format:Select output table format.
* 0 for the old format (SSID : Authmode, RSSI, BSSID, Channel) (Default)
* 1 for the new format (BSSID : SSID, RSSI, Authmode, Channel)
* function(table): a callback function to receive ap table when scan is done
this function receive a table, the key is the ssid,
value is other info in format: authmode,rssi,bssid,channel
...
...
@@ -623,6 +637,7 @@ static int wifi_station_listap( lua_State* L )
}
gL
=
L
;
struct
scan_config
scan_cfg
;
getap_output_format
=
0
;
if
(
lua_type
(
L
,
1
)
==
LUA_TTABLE
)
{
...
...
@@ -704,16 +719,32 @@ static int wifi_station_listap( lua_State* L )
}
else
scan_cfg
.
show_hidden
=
0
;
if
(
lua_type
(
L
,
2
)
==
LUA_TFUNCTION
||
lua_type
(
L
,
2
)
==
LUA_TLIGHTFUNCTION
)
{
lua_pushnil
(
L
);
lua_insert
(
L
,
2
);
}
lua_pop
(
L
,
-
4
);
}
else
if
(
lua_type
(
L
,
1
)
==
LUA_TNUMBER
)
{
lua_pushnil
(
L
);
lua_insert
(
L
,
1
);
}
else
if
(
lua_type
(
L
,
1
)
==
LUA_TFUNCTION
||
lua_type
(
L
,
1
)
==
LUA_TLIGHTFUNCTION
)
{
lua_pushnil
(
L
);
lua_insert
(
L
,
1
);
lua_pushnil
(
L
);
lua_insert
(
L
,
1
);
}
else
if
(
lua_isnil
(
L
,
1
))
{
if
(
lua_type
(
L
,
2
)
==
LUA_TFUNCTION
||
lua_type
(
L
,
2
)
==
LUA_TLIGHTFUNCTION
)
{
lua_pushnil
(
L
);
lua_insert
(
L
,
2
);
}
}
else
{
...
...
@@ -721,9 +752,16 @@ static int wifi_station_listap( lua_State* L )
}
if
(
lua_type
(
L
,
2
)
==
LUA_TFUNCTION
||
lua_type
(
L
,
2
)
==
LUA_TLIGHTFUNCTION
)
if
(
lua_type
(
L
,
2
)
==
LUA_TNUMBER
)
//this section changes the output format
{
getap_output_format
=
luaL_checkinteger
(
L
,
2
);
if
(
getap_output_format
!=
0
&&
getap_output_format
!=
1
)
return
luaL_error
(
L
,
"wrong arg type"
);
}
NODE_DBG
(
"Use alternate output format: %d
\n
"
,
getap_output_format
);
if
(
lua_type
(
L
,
3
)
==
LUA_TFUNCTION
||
lua_type
(
L
,
3
)
==
LUA_TLIGHTFUNCTION
)
{
lua_pushvalue
(
L
,
2
);
// copy argument (func) to the top of stack
lua_pushvalue
(
L
,
3
);
// copy argument (func) to the top of stack
if
(
wifi_scan_succeed
!=
LUA_NOREF
)
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
wifi_scan_succeed
);
wifi_scan_succeed
=
luaL_ref
(
L
,
LUA_REGISTRYINDEX
);
...
...
@@ -832,8 +870,7 @@ static int wifi_ap_config( lua_State* L )
if
(
!
lua_isnil
(
L
,
-
1
))
{
config
.
authmode
=
(
uint8_t
)
luaL_checkinteger
(
L
,
-
1
);
NODE_DBG
(
config
.
authmode
);
NODE_DBG
(
"
\n
"
);
NODE_DBG
(
"%d
\n
"
,
config
.
authmode
);
}
else
{
...
...
@@ -848,8 +885,7 @@ static int wifi_ap_config( lua_State* L )
return
luaL_error
(
L
,
"channel:1~13"
);
config
.
channel
=
(
uint8_t
)
channel
;
NODE_DBG
(
config
.
channel
);
NODE_DBG
(
"
\n
"
);
NODE_DBG
(
"%d
\n
"
,
config
.
channel
);
}
else
{
...
...
@@ -860,7 +896,7 @@ static int wifi_ap_config( lua_State* L )
if
(
!
lua_isnil
(
L
,
-
1
))
{
config
.
ssid_hidden
=
(
uint8_t
)
luaL_checkinteger
(
L
,
-
1
);
NODE_DBG
(
config
.
ssid_hidden
);
NODE_DBG
(
"%d
\n
"
,
config
.
ssid_hidden
);
NODE_DBG
(
"
\n
"
);
}
else
...
...
@@ -876,8 +912,7 @@ static int wifi_ap_config( lua_State* L )
return
luaL_error
(
L
,
"max:1~4"
);
config
.
max_connection
=
(
uint8_t
)
max
;
NODE_DBG
(
config
.
max_connection
);
NODE_DBG
(
"
\n
"
);
NODE_DBG
(
"%d
\n
"
,
config
.
max_connection
);
}
else
{
...
...
@@ -892,8 +927,7 @@ static int wifi_ap_config( lua_State* L )
return
luaL_error
(
L
,
"beacon:100~60000"
);
config
.
beacon_interval
=
(
uint16_t
)
beacon
;
NODE_DBG
(
config
.
beacon_interval
);
NODE_DBG
(
"
\n
"
);
NODE_DBG
(
"%d
\n
"
,
config
.
beacon_interval
);
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment