Skip to content

Commit 2e33abe

Browse files
dnc40085marcelstoer
authored andcommitted
Modify wifi.sta.get*config() to return AP's MAC (#2026)
* Modified wifi.sta.get*config() to return AP's MAC even if bssid_set==0 * Improved documentation for wifi.sta.getapinfo, fixes #2025
1 parent c01f653 commit 2e33abe

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

app/modules/wifi.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,13 +666,14 @@ static int wifi_station_getconfig( lua_State* L, bool get_flash_cfg)
666666
lua_setfield(L, -2, "pwd");
667667
}
668668

669-
if(sta_conf.bssid_set==1)
670-
{
671-
memset(temp, 0, sizeof(temp));
672-
c_sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid));
673-
lua_pushstring( L, temp);
674-
lua_setfield(L, -2, "bssid");
675-
}
669+
lua_pushboolean(L, sta_conf.bssid_set);
670+
lua_setfield(L, -2, "bssid_set");
671+
672+
memset(temp, 0, sizeof(temp));
673+
c_sprintf(temp, MACSTR, MAC2STR(sta_conf.bssid));
674+
lua_pushstring( L, temp);
675+
lua_setfield(L, -2, "bssid");
676+
676677
return 1;
677678
}
678679
else

docs/en/modules/wifi.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ Get information of APs cached by ESP8266 station.
662662
- `1-5` index of AP. (the index corresponds to index used by [`wifi.sta.changeap()`](#wifistachangeap) and [`wifi.sta.getapindex()`](#wifistagetapindex))
663663
- `ssid` ssid of Access Point
664664
- `pwd` password for Access Point, `nil` if no password was configured
665-
- `bssid` MAC address of Access Point, `nil` if no MAC address was configured
665+
- `bssid` MAC address of Access Point
666+
- `nil` will be returned if no MAC address was configured during station configuration.
666667

667668
#### Example
668669
```lua
@@ -733,7 +734,9 @@ If `return_table` is `true`:
733734
- `config_table`
734735
- `ssid` ssid of Access Point.
735736
- `pwd` password to Access Point, `nil` if no password was configured
736-
- `bssid` MAC address of Access Point, `nil` if no MAC address was configured
737+
- `bssid_set` will return `true` if the station was configured specifically to connect to the AP with the matching `bssid`.
738+
- `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.
739+
737740

738741
If `return_table` is `false`:
739742

@@ -744,8 +747,8 @@ If `return_table` is `false`:
744747
```lua
745748
--Get current Station configuration (NEW FORMAT)
746749
do
747-
local def_sta_config=wifi.sta.getconfig(true)
748-
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 "")))
750+
local sta_config=wifi.sta.getconfig(true)
751+
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")))
749752
end
750753

751754
--Get current Station configuration (OLD FORMAT)
@@ -780,7 +783,8 @@ If `return_table` is `true`:
780783
- `config_table`
781784
- `ssid` ssid of Access Point.
782785
- `pwd` password to Access Point, `nil` if no password was configured
783-
- `bssid` MAC address of Access Point, `nil` if no MAC address was configured
786+
- `bssid_set` will return `true` if the station was configured specifically to connect to the AP with the matching `bssid`.
787+
- `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.
784788

785789
If `return_table` is `false`:
786790

@@ -791,8 +795,8 @@ If `return_table` is `false`:
791795
```lua
792796
--Get default Station configuration (NEW FORMAT)
793797
do
794-
local def_sta_config=wifi.sta.getdefaultconfig(true)
795-
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 "")))
798+
local def_sta_config=wifi.sta.getdefaultconfig(true)
799+
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")))
796800
end
797801

798802
--Get default Station configuration (OLD FORMAT)

0 commit comments

Comments
 (0)