Update to the wifi module (#1497)
* Removed inline documentation for several functions and update comments Since documentation is now part of the repository, the inline documentation just adds to the already huge wifi.c * Wifi module: add new functionality, update documentation Functions Added: wifi.getdefaultmode(): returns default wifi opmode wifi.sta.apchange(): select alternate cached AP wifi.sta.apinfo(): get cached AP list wifi.sta.aplimit(): set cached AP limit wifi.sta.getapindex(): get index of currently configured AP wifi.sta.getdefaultconfig(): get default station configuration wifi.ap.getdefaultconfig(): get default AP configuration functions modified: wifi.setmode: saving mode to flash is now optional wifi.sta.config: now accepts table as an argument and save config to flash is now optional wifi.sta.getconfig: added option to return table wifi.ap.config: save config to flash is now optional wifi.ap.getconfig: added option to return table Documentation changes: - Modified documentation to reflect above changes - Removed unnecessary inline documentation from `wifi.c` - Updated documentation for `wifi.sta.disconnect`to address issue #1480 - Fixed inaccurate documentation for function `wifi.sleeptype` - Added more details to `wifi.nullmodesleep()` * Move function `wifi.sleeptype()` to `wifi.sta.sleeptype()` * Fixed problem where wifi.x.getconfig() returned invalid strings when ssid or password were set to maximum length. * fix error in documentation for `wifi.sta.getapindex` * Renamed some wifi functions wifi.sta.apinfo -> getapinfo wifi.sta.aplimit -> setaplimit wifi.sta.apchange -> changeap also organized the wifi_station_map array
This commit is contained in:
parent
77b2e85d09
commit
73773fd8a5
File diff suppressed because it is too large
Load Diff
|
@ -13,6 +13,9 @@
|
||||||
#include "c_stdio.h"
|
#include "c_stdio.h"
|
||||||
#include "task/task.h"
|
#include "task/task.h"
|
||||||
|
|
||||||
|
//#define WIFI_DEBUG
|
||||||
|
//#define EVENT_DEBUG
|
||||||
|
|
||||||
void wifi_add_sprintf_field(lua_State* L, char* name, char* string, ...);
|
void wifi_add_sprintf_field(lua_State* L, char* name, char* string, ...);
|
||||||
void wifi_add_int_field(lua_State* L, char* name, lua_Integer integer);
|
void wifi_add_int_field(lua_State* L, char* name, lua_Integer integer);
|
||||||
|
|
||||||
|
@ -37,7 +40,13 @@ static inline void unregister_lua_cb(lua_State* L, int* cb_ref)
|
||||||
|
|
||||||
void wifi_change_default_host_name(void);
|
void wifi_change_default_host_name(void);
|
||||||
|
|
||||||
#ifdef NODE_DEBUG
|
#if defined(WIFI_DEBUG) || defined(NODE_DEBUG)
|
||||||
|
#define WIFI_DBG(...) c_printf(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define WIFI_DBG(...) //c_printf(__VA_ARGS__)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(EVENT_DEBUG) || defined(NODE_DEBUG)
|
||||||
#define EVENT_DBG(...) c_printf(__VA_ARGS__)
|
#define EVENT_DBG(...) c_printf(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define EVENT_DBG(...) //c_printf(__VA_ARGS__)
|
#define EVENT_DBG(...) //c_printf(__VA_ARGS__)
|
||||||
|
|
|
@ -24,6 +24,23 @@ Gets the current WiFi channel.
|
||||||
#### Returns
|
#### Returns
|
||||||
current WiFi channel
|
current WiFi channel
|
||||||
|
|
||||||
|
## wifi.getdefaultmode()
|
||||||
|
|
||||||
|
Gets default WiFi operation mode.
|
||||||
|
|
||||||
|
#### Syntax
|
||||||
|
`wifi.getdefaultmode()`
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
`nil`
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
The WiFi mode, as one of the `wifi.STATION`, `wifi.SOFTAP`, `wifi.STATIONAP` or `wifi.NULLMODE` constants.
|
||||||
|
|
||||||
|
#### See also
|
||||||
|
[`wifi.getmode()`](#wifigetmode)
|
||||||
|
[`wifi.setmode()`](#wifisetmode)
|
||||||
|
|
||||||
## wifi.getmode()
|
## wifi.getmode()
|
||||||
|
|
||||||
Gets WiFi operation mode.
|
Gets WiFi operation mode.
|
||||||
|
@ -38,6 +55,7 @@ Gets WiFi operation mode.
|
||||||
The WiFi mode, as one of the `wifi.STATION`, `wifi.SOFTAP`, `wifi.STATIONAP` or `wifi.NULLMODE` constants.
|
The WiFi mode, as one of the `wifi.STATION`, `wifi.SOFTAP`, `wifi.STATIONAP` or `wifi.NULLMODE` constants.
|
||||||
|
|
||||||
#### See also
|
#### See also
|
||||||
|
[`wifi.getdefaultmode()`](#wifigetdefaultmode)
|
||||||
[`wifi.setmode()`](#wifisetmode)
|
[`wifi.setmode()`](#wifisetmode)
|
||||||
|
|
||||||
## wifi.getphymode()
|
## wifi.getphymode()
|
||||||
|
@ -70,15 +88,17 @@ When using the combined Station + AP mode, the same channel will be used for bot
|
||||||
NOTE: WiFi Mode configuration will be retained until changed even if device is turned off.
|
NOTE: WiFi Mode configuration will be retained until changed even if device is turned off.
|
||||||
|
|
||||||
#### Syntax
|
#### Syntax
|
||||||
`wifi.setmode(mode)`
|
`wifi.setmode(mode[, save])`
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
`mode` value should be one of
|
- `mode` value should be one of
|
||||||
|
|
||||||
- `wifi.STATION` for when the device is connected to a WiFi router. This is often done to give the device access to the Internet.
|
- `wifi.STATION` for when the device is connected to a WiFi router. This is often done to give the device access to the Internet.
|
||||||
- `wifi.SOFTAP` for when the device is acting *only* as an access point. This will allow you to see the device in the list of WiFi networks (unless you hide the SSID, of course). In this mode your computer can connect to the device, creating a local area network. Unless you change the value, the NodeMCU device will be given a local IP address of 192.168.4.1 and assign your computer the next available IP address, such as 192.168.4.2.
|
- `wifi.SOFTAP` for when the device is acting *only* as an access point. This will allow you to see the device in the list of WiFi networks (unless you hide the SSID, of course). In this mode your computer can connect to the device, creating a local area network. Unless you change the value, the NodeMCU device will be given a local IP address of 192.168.4.1 and assign your computer the next available IP address, such as 192.168.4.2.
|
||||||
- `wifi.STATIONAP` is the combination of `wifi.STATION` and `wifi.SOFTAP`. It allows you to create a local WiFi connection *and* connect to another WiFi router.
|
- `wifi.STATIONAP` is the combination of `wifi.STATION` and `wifi.SOFTAP`. It allows you to create a local WiFi connection *and* connect to another WiFi router.
|
||||||
- `wifi.NULLMODE` to switch off WiFi
|
- `wifi.NULLMODE` changing WiFi mode to NULL_MODE will put wifi into a low power state similar to MODEM_SLEEP, provided `wifi.nullmodesleep(false)` has not been called.
|
||||||
|
- `save` choose whether or not to save wifi mode to flash
|
||||||
|
- `true` WiFi mode configuration **will** be retained through power cycle. (Default)
|
||||||
|
- `false` WiFi mode configuration **will not** be retained through power cycle.
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
current mode after setup
|
current mode after setup
|
||||||
|
@ -90,6 +110,7 @@ wifi.setmode(wifi.STATION)
|
||||||
|
|
||||||
#### See also
|
#### See also
|
||||||
[`wifi.getmode()`](#wifigetmode)
|
[`wifi.getmode()`](#wifigetmode)
|
||||||
|
[`wifi.getdefaultmode()`](#wifigetdefaultmode)
|
||||||
|
|
||||||
## wifi.setphymode()
|
## wifi.setphymode()
|
||||||
|
|
||||||
|
@ -132,37 +153,21 @@ physical mode after setup
|
||||||
|
|
||||||
Configures whether or not WiFi automatically goes to sleep in NULL_MODE. Enabled by default.
|
Configures whether or not WiFi automatically goes to sleep in NULL_MODE. Enabled by default.
|
||||||
|
|
||||||
|
!!! note
|
||||||
|
This function **does not** store it's setting in flash, if auto sleep in NULL_MODE is not desired, `wifi.nullmodesleep(false)` must be called after powerup, restart, or wake from deep sleep.
|
||||||
|
|
||||||
#### Syntax
|
#### Syntax
|
||||||
`wifi.nullmodesleep(enable)`
|
`wifi.nullmodesleep([enable])`
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
- `enable`
|
- `enable`
|
||||||
- true: Enable WiFi auto sleep in NULL_MODE. (Default setting)
|
- `true` Enable WiFi auto sleep in NULL_MODE. (Default setting)
|
||||||
- false: Disable WiFi auto sleep in NULL_MODE.
|
- `false` Disable WiFi auto sleep in NULL_MODE.
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
Current/new NULL_MODE sleep setting.
|
- `sleep_enabled` Current/New NULL_MODE sleep setting
|
||||||
|
- If `wifi.nullmodesleep()` is called with no arguments, current setting is returned.
|
||||||
## wifi.sleeptype()
|
- If `wifi.nullmodesleep()` is called with `enable` argument, confirmation of new setting is returned.
|
||||||
|
|
||||||
Configures the WiFi modem sleep type.
|
|
||||||
|
|
||||||
#### Syntax
|
|
||||||
`wifi.sleeptype(type_wanted)`
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
`type_wanted` one of the following:
|
|
||||||
|
|
||||||
- `wifi.NONE_SLEEP` to keep the modem on at all times
|
|
||||||
- `wifi.LIGHT_SLEEP` to allow the modem to power down under some circumstances
|
|
||||||
- `wifi.MODEM_SLEEP` to power down the modem as much as possible
|
|
||||||
|
|
||||||
#### Returns
|
|
||||||
The actual sleep mode set, as one of `wifi.NONE_SLEEP`, `wifi.LIGHT_SLEEP` or `wifi.MODEM_SLEEP`.
|
|
||||||
|
|
||||||
#### See also
|
|
||||||
- [`node.dsleep()`](node.md#nodedsleep)
|
|
||||||
- [`rtctime.dsleep()`](rtctime.md#rtctimedsleep)
|
|
||||||
|
|
||||||
## wifi.startsmart()
|
## wifi.startsmart()
|
||||||
|
|
||||||
|
@ -241,61 +246,95 @@ wifi.sta.autoconnect(1)
|
||||||
- [`wifi.sta.connect()`](#wifistaconnect)
|
- [`wifi.sta.connect()`](#wifistaconnect)
|
||||||
- [`wifi.sta.disconnect()`](#wifistadisconnect)
|
- [`wifi.sta.disconnect()`](#wifistadisconnect)
|
||||||
|
|
||||||
|
## wifi.sta.changeap()
|
||||||
|
|
||||||
|
Select Access Point from list returned by `wifi.sta.getapinfo()`
|
||||||
|
|
||||||
|
#### Syntax
|
||||||
|
`wifi.sta.changeap(ap_index)`
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
`ap_index` Index of Access Point you would like to change to. (Range:1-5)
|
||||||
|
- Corresponds to index used by [`wifi.sta.getapinfo()`](#wifistagetapinfo) and [`wifi.sta.getapindex()`](#wifistagetapindex)
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
- `true` Success
|
||||||
|
- `false` Failure
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```lua
|
||||||
|
wifi.sta.changeap(4)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### See also
|
||||||
|
- [`wifi.sta.getapinfo()`](#wifistagetapinfo)
|
||||||
|
- [`wifi.sta.getapindex()`](#wifistagetapindex)
|
||||||
|
|
||||||
## wifi.sta.config()
|
## wifi.sta.config()
|
||||||
|
|
||||||
Sets the WiFi station configuration.
|
Sets the WiFi station configuration.
|
||||||
|
|
||||||
NOTE: Station configuration will be retained until changed even if device is turned off.
|
|
||||||
|
|
||||||
#### Syntax
|
#### Syntax
|
||||||
`wifi.sta.config(ssid, password[, auto[, bssid]])`
|
`wifi.sta.config(station_config)`
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
- `station_config` table containing configuration data for station
|
||||||
- `ssid` string which is less than 32 bytes.
|
- `ssid` string which is less than 32 bytes.
|
||||||
- `password` string which is 8-64 or 0 bytes. Empty string indicates an open WiFi access point.
|
- `pwd` string which is 8-64 or 0 bytes. Empty string indicates an open WiFi access point.
|
||||||
- `auto` defaults to 1
|
- `auto` defaults to true
|
||||||
- 0 to disable auto connect and remain disconnected from access point
|
- `true` to enable auto connect and connect to access point, hence with `auto=true` there's no need to call [`wifi.sta.connect()`](#wifistaconnect)
|
||||||
- 1 to enable auto connect and connect to access point, hence with `auto=1` there's no need to call [`wifi.sta.connect()`](#wifistaconnect) later
|
- `false` to disable auto connect and remain disconnected from access point
|
||||||
- `bssid` string that contains the MAC address of the access point (optional)
|
- `bssid` string that contains the MAC address of the access point (optional)
|
||||||
- You can set BSSID if you have multiple access points with the same SSID.
|
- You can set BSSID if you have multiple access points with the same SSID.
|
||||||
- Note: if you set BSSID for a specific SSID and would like to configure station to connect to the same SSID only without the BSSID requirement, you MUST first configure to station to a different SSID first, then connect to the desired SSID
|
- Note: if you set BSSID for a specific SSID and would like to configure station to connect to the same SSID only without the BSSID requirement, you MUST first configure to station to a different SSID first, then connect to the desired SSID
|
||||||
- The following formats are valid:
|
- The following formats are valid:
|
||||||
- "DE-C1-A5-51-F1-ED"
|
- "DE:C1:A5:51:F1:ED"
|
||||||
- "AC-1D-1C-B1-0B-22"
|
- "AC-1D-1C-B1-0B-22"
|
||||||
- "DE AD BE EF 7A C0"
|
- "DE AD BE EF 7A C0"
|
||||||
|
- `save` Save station configuration to flash.
|
||||||
|
- `true` configuration **will** be retained through power cycle.
|
||||||
|
- `false` configuration **will not** be retained through power cycle. (Default)
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
`nil`
|
- `true` Success
|
||||||
|
- `false` Failure
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- Connect to access point automatically when in range, `auto` defaults to 1
|
--connect to Access Point (DO NOT save config to flash)
|
||||||
wifi.sta.config("myssid", "password")
|
station_cfg={}
|
||||||
|
station_cfg.ssid="NODE-AABBCC"
|
||||||
|
station_cfg.pwd="password"
|
||||||
|
wifi.sta.config(station_cfg)
|
||||||
|
|
||||||
-- Connect to Unsecured access point automatically when in range, `auto` defaults to 1
|
--connect to Access Point (DO save config to flash)
|
||||||
wifi.sta.config("myssid", "")
|
station_cfg={}
|
||||||
|
station_cfg.ssid="NODE-AABBCC"
|
||||||
|
station_cfg.pwd="password"
|
||||||
|
station_cfg.save=true
|
||||||
|
wifi.sta.config(station_cfg)
|
||||||
|
|
||||||
-- Connect to access point, User decides when to connect/disconnect to/from AP due to `auto=0`
|
--connect to Access Point with specific MAC address
|
||||||
wifi.sta.config("myssid", "mypassword", 0)
|
station_cfg={}
|
||||||
wifi.sta.connect()
|
station_cfg.ssid="NODE-AABBCC"
|
||||||
-- ... do some WiFi stuff
|
station_cfg.pwd="password"
|
||||||
wifi.sta.disconnect()
|
station_cfg.bssid="AA:BB:CC:DD:EE:FF"
|
||||||
|
wifi.sta.config(station_cfg)
|
||||||
|
|
||||||
-- Connect to specific access point automatically when in range, `auto` defaults to 1
|
--configure station but don't connect to Access point
|
||||||
wifi.sta.config("myssid", "mypassword", "12:34:56:78:90:12")
|
station_cfg={}
|
||||||
|
station_cfg.ssid="NODE-AABBCC"
|
||||||
|
station_cfg.pwd="password"
|
||||||
|
station_cfg.auto=false
|
||||||
|
wifi.sta.config(station_cfg)
|
||||||
|
|
||||||
-- Connect to specific access point, User decides when to connect/disconnect to/from AP due to `auto=0`
|
|
||||||
wifi.sta.config("myssid", "mypassword", 0, "12:34:56:78:90:12")
|
|
||||||
wifi.sta.connect()
|
|
||||||
-- ... do some WiFi stuff
|
|
||||||
wifi.sta.disconnect()
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### See also
|
#### See also
|
||||||
- [`wifi.sta.connect()`](#wifistaconnect)
|
- [`wifi.sta.connect()`](#wifistaconnect)
|
||||||
- [`wifi.sta.disconnect()`](#wifistadisconnect)
|
- [`wifi.sta.disconnect()`](#wifistadisconnect)
|
||||||
|
- [`wifi.sta.apinfo()`](#wifistaapinfo)
|
||||||
|
|
||||||
## wifi.sta.connect()
|
## wifi.sta.connect()
|
||||||
|
|
||||||
|
@ -318,6 +357,10 @@ none
|
||||||
|
|
||||||
Disconnects from AP in station mode.
|
Disconnects from AP in station mode.
|
||||||
|
|
||||||
|
!!! note
|
||||||
|
Please note that disconnecting from Access Point does not reduce power consumption.
|
||||||
|
If power saving is your goal, please refer to the description for `wifi.NULLMODE` in the function [`wifi.setmode()`](#wifisetmode) for more details.
|
||||||
|
|
||||||
#### Syntax
|
#### Syntax
|
||||||
`wifi.sta.disconnect()`
|
`wifi.sta.disconnect()`
|
||||||
|
|
||||||
|
@ -535,6 +578,88 @@ wifi.sta.getap(scan_cfg, 1, listap)
|
||||||
#### See also
|
#### See also
|
||||||
[`wifi.sta.getip()`](#wifistagetip)
|
[`wifi.sta.getip()`](#wifistagetip)
|
||||||
|
|
||||||
|
## wifi.sta.getapindex()
|
||||||
|
|
||||||
|
Get index of current Access Point stored in AP cache.
|
||||||
|
|
||||||
|
|
||||||
|
#### Syntax
|
||||||
|
`wifi.sta.getapindex()`
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
none
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
`current_index` index of currently selected Access Point. (Range:1-5)
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```lua
|
||||||
|
print("the index of the currently selected AP is: "..wifi.sta.getapindex())
|
||||||
|
```
|
||||||
|
|
||||||
|
#### See also
|
||||||
|
- [`wifi.sta.getapindex()`](#wifistagetapindex)
|
||||||
|
- [`wifi.sta.apinfo()`](#wifistaapinfo)
|
||||||
|
- [`wifi.sta.apchange()`](#wifistaapchange)
|
||||||
|
|
||||||
|
## wifi.sta.getapinfo()
|
||||||
|
|
||||||
|
Get information of APs cached by ESP8266 station.
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
Any Access Points configured with save disabled `wifi.sta.config({save=false})` will populate this list (appearing to overwrite APs stored in flash) until restart.
|
||||||
|
|
||||||
|
#### Syntax
|
||||||
|
`wifi.sta.getapinfo()`
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
`nil`
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
- `ap_info`
|
||||||
|
- `qty` quantity of APs returned
|
||||||
|
- `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
|
||||||
|
- If no password was configured, the `pwd` field will be `nil`
|
||||||
|
- `bssid` MAC address of Access Point
|
||||||
|
- If no MAC address was configured, the `bssid` field will be `nil`
|
||||||
|
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```lua
|
||||||
|
--print stored access point info
|
||||||
|
do
|
||||||
|
for k,v in pairs(wifi.sta.getapinfo()) do
|
||||||
|
if (type(v)=="table") then
|
||||||
|
print(" "..k.." : "..type(v))
|
||||||
|
for k,v in pairs(v) do
|
||||||
|
print("\t\t"..k.." : "..v)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
print(" "..k.." : "..v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--print stored access point info(formatted)
|
||||||
|
do
|
||||||
|
local x=wifi.sta.getapinfo()
|
||||||
|
local y=wifi.sta.getapindex()
|
||||||
|
print("\n Number of APs stored in flash:", x.qty)
|
||||||
|
print(string.format(" %-6s %-32s %-64s %-18s", "index:", "SSID:", "Password:", "BSSID:"))
|
||||||
|
for i=1, (x.qty), 1 do
|
||||||
|
print(string.format(" %s%-6d %-32s %-64s %-18s",(i==y and ">" or " "), i, x[i].ssid, x[i].pwd and x[i].pwd or type(nil), x[i].bssid and x[i].bssid or type(nil)))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
#### See also
|
||||||
|
- [`wifi.sta.getapindex()`](#wifistagetapindex)
|
||||||
|
- [`wifi.sta.setaplimit()`](#wifistasetaplimit)
|
||||||
|
- [`wifi.sta.changeap()`](#wifistachangeap)
|
||||||
|
- [`wifi.sta.config()`](#wifistaconfig)
|
||||||
|
|
||||||
## wifi.sta.getbroadcast()
|
## wifi.sta.getbroadcast()
|
||||||
|
|
||||||
Gets the broadcast address in station mode.
|
Gets the broadcast address in station mode.
|
||||||
|
@ -560,17 +685,33 @@ Gets the WiFi station configuration.
|
||||||
`wifi.sta.getconfig()`
|
`wifi.sta.getconfig()`
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
none
|
- `return_table`
|
||||||
|
- `true` returns data in a table
|
||||||
|
- `false` returns data in the old format (default)
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
ssid, password, bssid_set, bssid
|
If `return_table` is `true`:
|
||||||
|
- `config_table`
|
||||||
|
- `ssid` ssid of Access Point.
|
||||||
|
- `pwd` password to Access Point.
|
||||||
|
- If no password was configured, the `pwd` field will be `nil`
|
||||||
|
- `bssid` MAC address of Access Point
|
||||||
|
- If no MAC address was configured, the `bssid` field will be `nil`
|
||||||
|
|
||||||
Note: If bssid_set is equal to 0 then bssid is irrelevant
|
If `return_table` is `false`:
|
||||||
|
- ssid, password, bssid_set, bssid
|
||||||
|
- Note: If `bssid_set` is equal to `0` then `bssid` is irrelevant,
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
--Get current Station configuration
|
--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 "")))
|
||||||
|
end
|
||||||
|
|
||||||
|
--Get current Station configuration (OLD FORMAT)
|
||||||
ssid, password, bssid_set, bssid=wifi.sta.getconfig()
|
ssid, password, bssid_set, bssid=wifi.sta.getconfig()
|
||||||
print("\nCurrent Station configuration:\nSSID : "..ssid
|
print("\nCurrent Station configuration:\nSSID : "..ssid
|
||||||
.."\nPassword : "..password
|
.."\nPassword : "..password
|
||||||
|
@ -580,6 +721,55 @@ ssid, password, bssid_set, bssid=nil, nil, nil, nil
|
||||||
```
|
```
|
||||||
|
|
||||||
#### See also
|
#### See also
|
||||||
|
- [`wifi.sta.getdefaultconfig()`](#wifistagetdefaultconfig)
|
||||||
|
- [`wifi.sta.connect()`](#wifistaconnect)
|
||||||
|
- [`wifi.sta.disconnect()`](#wifistadisconnect)
|
||||||
|
|
||||||
|
## wifi.sta.getdefaultconfig()
|
||||||
|
|
||||||
|
Gets the default WiFi station configuration stored in flash.
|
||||||
|
|
||||||
|
#### Syntax
|
||||||
|
`wifi.sta.getdefaultconfig(return_table)`
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
- `return_table`
|
||||||
|
- `true` returns data in a table
|
||||||
|
- `false` returns data in the old format (default)
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
If `return_table` is `true`:
|
||||||
|
- `config_table`
|
||||||
|
- `ssid` ssid of Access Point.
|
||||||
|
- `pwd` password to Access Point.
|
||||||
|
- If no password was configured, the `pwd` field will be `nil`
|
||||||
|
- `bssid` MAC address of Access Point
|
||||||
|
- If no MAC address was configured, the `bssid` field will be `nil`
|
||||||
|
|
||||||
|
If `return_table` is `false`:
|
||||||
|
- ssid, password, bssid_set, bssid
|
||||||
|
- Note: If `bssid_set` is equal to `0` then `bssid` is irrelevant,
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
```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 "")))
|
||||||
|
end
|
||||||
|
|
||||||
|
--Get default Station configuration (OLD FORMAT)
|
||||||
|
ssid, password, bssid_set, bssid=wifi.sta.getdefaultconfig()
|
||||||
|
print("\nCurrent Station configuration:\nSSID : "..ssid
|
||||||
|
.."\nPassword : "..password
|
||||||
|
.."\nBSSID_set : "..bssid_set
|
||||||
|
.."\nBSSID: "..bssid.."\n")
|
||||||
|
ssid, password, bssid_set, bssid=nil, nil, nil, nil
|
||||||
|
```
|
||||||
|
|
||||||
|
#### See also
|
||||||
|
- [`wifi.sta.getconfig()`](#wifistagetconfig)
|
||||||
- [`wifi.sta.connect()`](#wifistaconnect)
|
- [`wifi.sta.connect()`](#wifistaconnect)
|
||||||
- [`wifi.sta.disconnect()`](#wifistadisconnect)
|
- [`wifi.sta.disconnect()`](#wifistadisconnect)
|
||||||
|
|
||||||
|
@ -667,6 +857,32 @@ RSSI=wifi.sta.getrssi()
|
||||||
print("RSSI is", RSSI)
|
print("RSSI is", RSSI)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## wifi.sta.setaplimit()
|
||||||
|
|
||||||
|
Set Maximum number of Access Points to store in flash.
|
||||||
|
- This value is written to flash
|
||||||
|
|
||||||
|
!!! Attention
|
||||||
|
If 5 Access Points are stored and AP limit is set to 4, the AP at index 5 will remain until [`node.restore()`](node.md#noderestore) is called or AP limit is set to 5 and AP is overwritten.
|
||||||
|
|
||||||
|
#### Syntax
|
||||||
|
`wifi.sta.setaplimit(qty)`
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
`qty` Quantity of Access Points to store in flash. Range: 1-5 (Default: 5)
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
- `true` Success
|
||||||
|
- `false` Failure
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```lua
|
||||||
|
wifi.sta.setaplimit(true)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### See also
|
||||||
|
- [`wifi.sta.getapinfo()`](#wifistagetapinfo)
|
||||||
|
|
||||||
## wifi.sta.sethostname()
|
## wifi.sta.sethostname()
|
||||||
|
|
||||||
Sets station hostname.
|
Sets station hostname.
|
||||||
|
@ -732,6 +948,26 @@ print(wifi.sta.setmac("DE:AD:BE:EF:7A:C0"))
|
||||||
#### See also
|
#### See also
|
||||||
[`wifi.sta.setip()`](#wifistasetip)
|
[`wifi.sta.setip()`](#wifistasetip)
|
||||||
|
|
||||||
|
## wifi.sta.sleeptype()
|
||||||
|
|
||||||
|
Configures the WiFi modem sleep type to be used while station is connected to an Access Point.
|
||||||
|
|
||||||
|
!!! note
|
||||||
|
Does not apply to `wifi.SOFTAP`, `wifi.STATIONAP` or `wifi.NULLMODE`.
|
||||||
|
|
||||||
|
#### Syntax
|
||||||
|
`wifi.sta.sleeptype(type_wanted)`
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
`type_wanted` one of the following:
|
||||||
|
|
||||||
|
- `wifi.NONE_SLEEP` to keep the modem on at all times
|
||||||
|
- `wifi.LIGHT_SLEEP` to allow the CPU to power down under some circumstances
|
||||||
|
- `wifi.MODEM_SLEEP` to power down the modem as much as possible
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
The actual sleep mode set, as one of `wifi.NONE_SLEEP`, `wifi.LIGHT_SLEEP` or `wifi.MODEM_SLEEP`.
|
||||||
|
|
||||||
## wifi.sta.status()
|
## wifi.sta.status()
|
||||||
|
|
||||||
Gets the current status in station mode.
|
Gets the current status in station mode.
|
||||||
|
@ -758,22 +994,26 @@ number: 0~5
|
||||||
|
|
||||||
Sets SSID and password in AP mode. Be sure to make the password at least 8 characters long! If you don't it will default to *no* password and not set the SSID! It will still work as an access point but use a default SSID like e.g. NODE-9997C3.
|
Sets SSID and password in AP mode. Be sure to make the password at least 8 characters long! If you don't it will default to *no* password and not set the SSID! It will still work as an access point but use a default SSID like e.g. NODE-9997C3.
|
||||||
|
|
||||||
NOTE: SoftAP Configuration will be retained until changed even if device is turned off.
|
|
||||||
|
|
||||||
#### Syntax
|
#### Syntax
|
||||||
`wifi.ap.config(cfg)`
|
`wifi.ap.config(cfg)`
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
- `cfg` table to hold configuration
|
||||||
- `ssid` SSID chars 1-32
|
- `ssid` SSID chars 1-32
|
||||||
- `pwd` password chars 8-64
|
- `pwd` password chars 8-64
|
||||||
- `auth` authentication method, one of `wifi.OPEN` (default), `wifi.WPA_PSK`, `wifi.WPA2_PSK`, `wifi.WPA_WPA2_PSK`
|
- `auth` authentication method, one of `wifi.OPEN` (default), `wifi.WPA_PSK`, `wifi.WPA2_PSK`, `wifi.WPA_WPA2_PSK`
|
||||||
- `channel` channel number 1-14 default = 6
|
- `channel` channel number 1-14 default = 6
|
||||||
- `hidden` 0 = not hidden, 1 = hidden, default 0
|
- `hidden` false = not hidden, true = hidden, default = false
|
||||||
- `max` maximal number of connections 1-4 default=4
|
- `max` maximum number of connections 1-4 default=4
|
||||||
- `beacon` beacon interval time in range 100-60000, default = 100
|
- `beacon` beacon interval time in range 100-60000, default = 100
|
||||||
|
- `save` save configuration to flash.
|
||||||
|
- `true` configuration **will** be retained through power cycle. (Default)
|
||||||
|
- `false` configuration **will not** be retained through power cycle.
|
||||||
|
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
`nil`
|
- `true` Success
|
||||||
|
- `false` Failure
|
||||||
|
|
||||||
#### Example:
|
#### Example:
|
||||||
```lua
|
```lua
|
||||||
|
@ -871,6 +1111,102 @@ for mac,ip in pairs(wifi.ap.getclient()) do
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## wifi.ap.getconfig()
|
||||||
|
|
||||||
|
Gets the current SoftAP configuration.
|
||||||
|
|
||||||
|
#### Syntax
|
||||||
|
`wifi.ap.getconfig(return_table)`
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
- `return_table`
|
||||||
|
- `true` returns data in a table
|
||||||
|
- `false` returns data in the old format (default)
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
If `return_table` is true:
|
||||||
|
- `config_table`
|
||||||
|
- `ssid` Network name
|
||||||
|
- `pwd` Password
|
||||||
|
- If no password was configured, the `pwd` field will be `nil`
|
||||||
|
- `auth` Authentication Method (`wifi.OPEN`, `wifi.WPA_PSK`, `wifi.WPA2_PSK` or `wifi.WPA_WPA2_PSK`)
|
||||||
|
- `channel` Channel number
|
||||||
|
- `hidden` `false` = not hidden, `true` = hidden
|
||||||
|
- `max` Maximum number of client connections
|
||||||
|
- `beacon` Beacon interval
|
||||||
|
|
||||||
|
If `return_table` is false:
|
||||||
|
ssid, password
|
||||||
|
Note: If bssid_set is equal to 0 then bssid is irrelevant
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
```lua
|
||||||
|
--Get SoftAP configuration table (NEW FORMAT)
|
||||||
|
do
|
||||||
|
print("\n Current SoftAP configuration:")
|
||||||
|
for k,v in pairs(wifi.ap.getconfig(true)) do
|
||||||
|
print(" "..k.." :",v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--Get current SoftAP configuration (OLD FORMAT)
|
||||||
|
do
|
||||||
|
local ssid, password=wifi.ap.getconfig()
|
||||||
|
print("\n Current SoftAP configuration:\n SSID : "..ssid..
|
||||||
|
"\n Password :",password)
|
||||||
|
ssid, password=nil, nil
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
## wifi.ap.getdefaultconfig()
|
||||||
|
|
||||||
|
Gets the default SoftAP configuration stored in flash.
|
||||||
|
|
||||||
|
#### Syntax
|
||||||
|
`wifi.ap.getdefaultconfig(return_table)`
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
- `return_table`
|
||||||
|
- `true` returns data in a table
|
||||||
|
- `false` returns data in the old format (default)
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
If `return_table` is true:
|
||||||
|
- `config_table`
|
||||||
|
- `ssid` Network name
|
||||||
|
- `pwd` Password
|
||||||
|
- If no password was configured, the `pwd` field will be `nil`
|
||||||
|
- `auth` Authentication Method (`wifi.OPEN`, `wifi.WPA_PSK`, `wifi.WPA2_PSK` or `wifi.WPA_WPA2_PSK`)
|
||||||
|
- `channel` Channel number
|
||||||
|
- `hidden` `false` = not hidden, `true` = hidden
|
||||||
|
- `max` Maximum number of client connections
|
||||||
|
- `beacon` Beacon interval
|
||||||
|
|
||||||
|
If `return_table` is false:
|
||||||
|
ssid, password
|
||||||
|
Note: If bssid_set is equal to 0 then bssid is irrelevant
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
```lua
|
||||||
|
--Get default SoftAP configuration table (NEW FORMAT)
|
||||||
|
do
|
||||||
|
print("\n Default SoftAP configuration:")
|
||||||
|
for k,v in pairs(wifi.ap.getdefaultconfig(true)) do
|
||||||
|
print(" "..k.." :",v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--Get default SoftAP configuration (OLD FORMAT)
|
||||||
|
do
|
||||||
|
local ssid, password=wifi.ap.getdefaultconfig()
|
||||||
|
print("\n Default SoftAP configuration:\n SSID : "..ssid..
|
||||||
|
"\n Password :",password)
|
||||||
|
ssid, password=nil, nil
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
## wifi.ap.getip()
|
## wifi.ap.getip()
|
||||||
|
|
||||||
Gets IP address, netmask and gateway in AP mode.
|
Gets IP address, netmask and gateway in AP mode.
|
||||||
|
|
Loading…
Reference in New Issue