Skip to content

Commit

Permalink
Modify wifi.sta.get*config() to return AP's MAC (#2026)
Browse files Browse the repository at this point in the history
* Modified wifi.sta.get*config() to return AP's MAC even if bssid_set==0
* Improved documentation for wifi.sta.getapinfo, fixes #2025
  • Loading branch information
dnc40085 authored and marcelstoer committed Jul 8, 2017
1 parent c01f653 commit 2e33abe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
15 changes: 8 additions & 7 deletions app/modules/wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,13 +666,14 @@ static int wifi_station_getconfig( lua_State* L, bool get_flash_cfg)
lua_setfield(L, -2, "pwd");
}

if(sta_conf.bssid_set==1)
{
memset(temp, 0, sizeof(temp));
c_sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid));
lua_pushstring( L, temp);
lua_setfield(L, -2, "bssid");
}
lua_pushboolean(L, sta_conf.bssid_set);
lua_setfield(L, -2, "bssid_set");

memset(temp, 0, sizeof(temp));
c_sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid));
lua_pushstring( L, temp);
lua_setfield(L, -2, "bssid");

return 1;
}
else
Expand Down
18 changes: 11 additions & 7 deletions docs/en/modules/wifi.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ Get information of APs cached by ESP8266 station.
- `1-5` index of AP. (the index corresponds to index used by [`wifi.sta.changeap()`](#wifistachangeap) and [`wifi.sta.getapindex()`](#wifistagetapindex))
- `ssid` ssid of Access Point
- `pwd` password for Access Point, `nil` if no password was configured
- `bssid` MAC address of Access Point, `nil` if no MAC address was configured
- `bssid` MAC address of Access Point
- `nil` will be returned if no MAC address was configured during station configuration.

#### Example
```lua
Expand Down Expand Up @@ -733,7 +734,9 @@ If `return_table` is `true`:
- `config_table`
- `ssid` ssid of Access Point.
- `pwd` password to Access Point, `nil` if no password was configured
- `bssid` MAC address of Access Point, `nil` if no MAC address was configured
- `bssid_set` will return `true` if the station was configured specifically to connect to the AP with the matching `bssid`.
- `bssid` If a connection has been made to the configured AP this field will contain the AP's MAC address. Otherwise "ff:ff:ff:ff:ff:ff" will be returned.


If `return_table` is `false`:

Expand All @@ -744,8 +747,8 @@ If `return_table` is `false`:
```lua
--Get current Station configuration (NEW FORMAT)
do
local def_sta_config=wifi.sta.getconfig(true)
print(string.format("\tDefault station config\n\tssid:\"%s\"\tpassword:\"%s\"%s", def_sta_config.ssid, def_sta_config.pwd, (type(def_sta_config.bssid)=="string" and "\tbssid:\""..def_sta_config.bssid.."\"" or "")))
local sta_config=wifi.sta.getconfig(true)
print(string.format("\tCurrent station config\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false")))
end

--Get current Station configuration (OLD FORMAT)
Expand Down Expand Up @@ -780,7 +783,8 @@ If `return_table` is `true`:
- `config_table`
- `ssid` ssid of Access Point.
- `pwd` password to Access Point, `nil` if no password was configured
- `bssid` MAC address of Access Point, `nil` if no MAC address was configured
- `bssid_set` will return `true` if the station was configured specifically to connect to the AP with the matching `bssid`.
- `bssid` If a connection has been made to the configured AP this field will contain the AP's MAC address. Otherwise "ff:ff:ff:ff:ff:ff" will be returned.

If `return_table` is `false`:

Expand All @@ -791,8 +795,8 @@ If `return_table` is `false`:
```lua
--Get default Station configuration (NEW FORMAT)
do
local def_sta_config=wifi.sta.getdefaultconfig(true)
print(string.format("\tDefault station config\n\tssid:\"%s\"\tpassword:\"%s\"%s", def_sta_config.ssid, def_sta_config.pwd, (type(def_sta_config.bssid)=="string" and "\tbssid:\""..def_sta_config.bssid.."\"" or "")))
local def_sta_config=wifi.sta.getdefaultconfig(true)
print(string.format("\tDefault station config\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", def_sta_config.ssid, def_sta_config.pwd, def_sta_config.bssid, (def_sta_config.bssid_set and "true" or "false")))
end

--Get default Station configuration (OLD FORMAT)
Expand Down

0 comments on commit 2e33abe

Please sign in to comment.