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
d5d8990b
Commit
d5d8990b
authored
Aug 17, 2017
by
Johny Mattsson
Committed by
GitHub
Aug 17, 2017
Browse files
Merge pull request #2021 from larsstenberg/dev-esp32-getmac
ESP32: added functions wifi.sta.getmac() and wifi.ap.getmac()
parents
4b5e1242
e6eb743b
Changes
5
Show whitespace changes
Inline
Side-by-side
components/modules/wifi_ap.c
View file @
d5d8990b
...
...
@@ -168,6 +168,10 @@ static int wifi_ap_config (lua_State *L)
0
:
luaL_error
(
L
,
"failed to set wifi config, code %d"
,
err
);
}
static
int
wifi_ap_getmac
(
lua_State
*
L
)
{
return
wifi_getmac
(
WIFI_IF_AP
,
L
);
}
static
int
wifi_ap_on
(
lua_State
*
L
)
{
...
...
@@ -179,6 +183,7 @@ const LUA_REG_TYPE wifi_ap_map[] =
{
{
LSTRKEY
(
"config"
),
LFUNCVAL
(
wifi_ap_config
)
},
{
LSTRKEY
(
"on"
),
LFUNCVAL
(
wifi_ap_on
)
},
{
LSTRKEY
(
"getmac"
),
LFUNCVAL
(
wifi_ap_getmac
)
},
{
LNILKEY
,
LNILVAL
}
};
components/modules/wifi_common.c
View file @
d5d8990b
...
...
@@ -77,3 +77,17 @@ int wifi_on (lua_State *L, const event_desc_t *table, unsigned n, int *event_cb)
return
0
;
}
int
wifi_getmac
(
wifi_interface_t
interface
,
lua_State
*
L
)
{
uint8_t
mac
[
6
];
esp_err_t
err
=
esp_wifi_get_mac
(
interface
,
mac
);
if
(
err
!=
ESP_OK
)
return
luaL_error
(
L
,
"failed to get mac, code %d"
,
err
);
char
mac_str
[
MAC_STR_SZ
];
macstr
(
mac_str
,
mac
);
lua_pushstring
(
L
,
mac_str
);
return
1
;
}
components/modules/wifi_common.h
View file @
d5d8990b
...
...
@@ -71,4 +71,6 @@ int wifi_on (lua_State *L, const event_desc_t *table, unsigned n, int *event_cb)
#define STR_WIFI_SECOND_CHAN_BELOW "HT40_BELOW"
extern
const
char
*
const
wifi_second_chan_names
[];
int
wifi_getmac
(
wifi_interface_t
interface
,
lua_State
*
L
);
#endif
components/modules/wifi_sta.c
View file @
d5d8990b
...
...
@@ -278,6 +278,10 @@ static int wifi_sta_getconfig (lua_State *L)
return
1
;
}
static
int
wifi_sta_getmac
(
lua_State
*
L
)
{
return
wifi_getmac
(
WIFI_IF_STA
,
L
);
}
static
void
on_scan_done
(
const
system_event_t
*
evt
)
{
...
...
@@ -385,6 +389,7 @@ const LUA_REG_TYPE wifi_sta_map[] = {
{
LSTRKEY
(
"connect"
),
LFUNCVAL
(
wifi_sta_connect
)
},
{
LSTRKEY
(
"disconnect"
),
LFUNCVAL
(
wifi_sta_disconnect
)
},
{
LSTRKEY
(
"getconfig"
),
LFUNCVAL
(
wifi_sta_getconfig
)
},
{
LSTRKEY
(
"getmac"
),
LFUNCVAL
(
wifi_sta_getmac
)
},
{
LSTRKEY
(
"on"
),
LFUNCVAL
(
wifi_sta_on
)
},
{
LSTRKEY
(
"scan"
),
LFUNCVAL
(
wifi_sta_scan
)
},
...
...
docs/en/modules/wifi.md
View file @
d5d8990b
...
...
@@ -320,6 +320,17 @@ end)
wifi
.
sta
.
on
(
"got_ip"
,
nil
)
```
## wifi.sta.getmac()
Gets MAC address in station mode.
#### Syntax
`wifi.sta.getmac()`
#### Parameters
None
## wifi.sta.scan()
Scan for available networks.
...
...
@@ -436,3 +447,16 @@ Event information provided for each event is as follows:
-
`probe_req`
: information about the probing client
-
`from`
: MAC address of the probing client
-
`rssi`
: Received Signal Strength Indicator value
## wifi.ap.getmac()
Gets MAC address in access point mode.
#### Syntax
`wifi.ap.getmac()`
#### Parameters
None
#### Returns
MAC address as string e.g. "18:fe:34:a2:d7:34"
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