Since | Origin / Contributor | Maintainer | Source |
---|---|---|---|
2015-05-12 | Zeroday | dnc40085 | wifi.c |
The NodeMCU WiFi control is spread across several tables:
wifi
for overall WiFi configurationwifi.sta
for station mode functionswifi.ap
for wireless access point (WAP or simply AP) functionswifi.ap.dhcp
for DHCP server controlwifi.eventmon
for wifi event monitor
Gets the current WiFi channel.
wifi.getchannel()
nil
current WiFi channel
Gets WiFi operation mode.
wifi.getmode()
nil
The WiFi mode, as one of the wifi.STATION
, wifi.SOFTAP
, wifi.STATIONAP
or wifi.NULLMODE
constants.
Gets WiFi physical mode.
wifi.getphymode()
none
The current physical mode as one of wifi.PHYMODE_B
, wifi.PHYMODE_G
or wifi.PHYMODE_N
.
Wake up WiFi from suspended state or cancel pending wifi suspension
wifi.resume([resume_cb])
-
resume_cb
Callback to execute when WiFi wakes from suspension. !!! note "Note:"Any previously provided callbacks will be replaced!
nil
--Resume wifi from timed or indefinite sleep
wifi.resume()
--Resume wifi from timed or indefinite sleep w/ resume callback
wifi.resume(function() print("WiFi resume") end)
wifi.suspend()
node.sleep()
node.dsleep()
Configures the WiFi mode to use. NodeMCU can run in one of four WiFi modes:
- Station mode, where the NodeMCU device joins an existing network
- Access point (AP) mode, where it creates its own network that others can join
- Station + AP mode, where it both creates its own network while at the same time being joined to another existing network
- WiFi off
When using the combined Station + AP mode, the same channel will be used for both networks as the radio can only listen on a single channel.
NOTE: WiFi Mode configuration will be retained until changed even if device is turned off.
wifi.setmode(mode)
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.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 ofwifi.STATION
andwifi.SOFTAP
. It allows you to create a local WiFi connection and connect to another WiFi router.wifi.NULLMODE
to switch off WiFi
current mode after setup
wifi.setmode(wifi.STATION)
Sets WiFi physical mode.
wifi.PHYMODE_B
802.11b, more range, low Transfer rate, more current drawwifi.PHYMODE_G
802.11g, medium range, medium transfer rate, medium current drawwifi.PHYMODE_N
802.11n, least range, fast transfer rate, least current draw (STATION ONLY) Information from the Espressif datasheet v4.3
Parameters | Typical Power Usage |
---|---|
Tx 802.11b, CCK 11Mbps, P OUT=+17dBm | 170 mA |
Tx 802.11g, OFDM 54Mbps, P OUT =+15dBm | 140 mA |
Tx 802.11n, MCS7 65Mbps, P OUT =+13dBm | 120 mA |
Rx 802.11b, 1024 bytes packet length, -80dBm | 50 mA |
Rx 802.11g, 1024 bytes packet length, -70dBm | 56 mA |
Rx 802.11n, 1024 bytes packet length, -65dBm | 56 mA |
wifi.setphymode(mode)
mode
one of the following
wifi.PHYMODE_B
wifi.PHYMODE_G
wifi.PHYMODE_N
physical mode after setup
Configures the WiFi modem sleep type.
wifi.sleeptype(type_wanted)
type_wanted
one of the following:
wifi.NONE_SLEEP
to keep the modem on at all timeswifi.LIGHT_SLEEP
to allow the modem to power down under some circumstanceswifi.MODEM_SLEEP
to power down the modem as much as possible
The actual sleep mode set, as one of wifi.NONE_SLEEP
, wifi.LIGHT_SLEEP
or wifi.MODEM_SLEEP
.
Starts to auto configuration, if success set up SSID and password automatically.
Intended for use with SmartConfig apps, such as Espressif's Android & iOS app.
Only usable in wifi.STATION
mode.
!!! important
SmartConfig is disabled by default and can be enabled by setting `WIFI_SMART_ENABLE` in [`user_config.h`](https://github.com/nodemcu/nodemcu-firmware/blob/dev/app/include/user_config.h#L96) before you build the firmware.
wifi.startsmart(type, callback)
type
0 for ESP_TOUCH, or 1 for AIR_KISS.callback
a callback function of the formfunction(ssid, password) end
which gets called after configuration.
nil
wifi.setmode(wifi.STATION)
wifi.startsmart(0,
function(ssid, password)
print(string.format("Success. SSID:%s ; PASSWORD:%s", ssid, password))
end
)
Stops the smart configuring process.
wifi.stopsmart()
none
nil
Suspend Wifi to reduce current consumption. This function is also useful for preventing WiFi stack related crashes when executing functions or tasks that take longer than ~500ms
wifi.suspend({duration[, suspend_cb, resume_cb, preserve_mode]})
duration
Suspend duration in microseconds(μs). If a suspend duration of0
is specified, suspension will be indefinite (Range: 0 or 50000 - 268435454 μs)suspend_cb
Callback to execute when WiFi is suspended. (Optional)resume_cb
Callback to execute when WiFi wakes from suspension. (Optional)preserve_mode
preserve current WiFi mode through node sleep. (Optional, Default: true)- If true, Station and StationAP modes will automatically reconnect to previously configured Access Point when NodeMCU resumes.
- If false, discard WiFi mode and leave NodeMCU in
wifi.NULL_MODE
. WiFi mode will be restored to original mode on restart.
suspend_state
if no parameters are provided, current WiFi suspension state will be returned- States:
0
WiFi is awake.1
WiFi suspension is pending. (Waiting for idle task)2
WiFi is suspended.
--get current wifi suspension state
print(wifi.suspend())
--Suspend WiFi for 10 seconds with suspend/resume callbacks
cfg={}
cfg.duration=10*1000*1000
cfg.resume_cb=function() print("WiFi resume") end
cfg.suspend_cb=function() print("WiFi suspended") end
wifi.suspend(cfg)
--Suspend WiFi for 10 seconds with suspend/resume callbacks and discard WiFi mode
cfg={}
cfg.duration=10*1000*1000
cfg.resume_cb=function() print("WiFi resume") end
cfg.suspend_cb=function() print("WiFfi suspended") end
cfg.preserve_mode=false
wifi.suspend(cfg)
wifi.resume()
node.sleep()
node.dsleep()
Auto connects to AP in station mode.
wifi.sta.autoconnect(auto)
auto
0 to disable auto connecting, 1 to enable auto connecting
nil
wifi.sta.autoconnect(1)
Sets the WiFi station configuration.
NOTE: Station configuration will be retained until changed even if device is turned off.
wifi.sta.config(ssid, password[, auto[, bssid]])
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.auto
defaults to 1- 0 to disable auto connect and remain disconnected from access point
- 1 to enable auto connect and connect to access point, hence with
auto=1
there's no need to callwifi.sta.connect()
later
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.
- 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:
- "DE-C1-A5-51-F1-ED"
- "AC-1D-1C-B1-0B-22"
- "DE AD BE EF 7A C0"
nil
-- Connect to access point automatically when in range, `auto` defaults to 1
wifi.sta.config("myssid", "password")
-- Connect to Unsecured access point automatically when in range, `auto` defaults to 1
wifi.sta.config("myssid", "")
-- Connect to access point, User decides when to connect/disconnect to/from AP due to `auto=0`
wifi.sta.config("myssid", "mypassword", 0)
wifi.sta.connect()
-- ... do some WiFi stuff
wifi.sta.disconnect()
-- Connect to specific access point automatically when in range, `auto` defaults to 1
wifi.sta.config("myssid", "mypassword", "12:34:56:78:90:12")
-- 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()
Connects to the configured AP in station mode. You only ever need to call this if auto-connect was disabled in wifi.sta.config()
.
wifi.sta.connect()
none
nil
Disconnects from AP in station mode.
wifi.sta.disconnect()
none
nil
Registers callbacks for WiFi station status events.
wifi.sta.eventMonReg(wifi_status[, function([previous_state])])
wifi_status
WiFi status you would like to set a callback for:wifi.STA_IDLE
wifi.STA_CONNECTING
wifi.STA_WRONGPWD
wifi.STA_APNOTFOUND
wifi.STA_FAIL
wifi.STA_GOTIP
function
callback function to perform when event occurs- Note: leaving field blank unregisters callback.
previous_state
previous wifi_state(0 - 5)
nil
--register callback
wifi.sta.eventMonReg(wifi.STA_IDLE, function() print("STATION_IDLE") end)
wifi.sta.eventMonReg(wifi.STA_CONNECTING, function() print("STATION_CONNECTING") end)
wifi.sta.eventMonReg(wifi.STA_WRONGPWD, function() print("STATION_WRONG_PASSWORD") end)
wifi.sta.eventMonReg(wifi.STA_APNOTFOUND, function() print("STATION_NO_AP_FOUND") end)
wifi.sta.eventMonReg(wifi.STA_FAIL, function() print("STATION_CONNECT_FAIL") end)
wifi.sta.eventMonReg(wifi.STA_GOTIP, function() print("STATION_GOT_IP") end)
--register callback: use previous state
wifi.sta.eventMonReg(wifi.STA_CONNECTING, function(previous_State)
if(previous_State==wifi.STA_GOTIP) then
print("Station lost connection with access point\n\tAttempting to reconnect...")
else
print("STATION_CONNECTING")
end
end)
--unregister callback
wifi.sta.eventMonReg(wifi.STA_IDLE)
wifi.sta.eventMonStart()
wifi.sta.eventMonStop()
wifi.eventmon.register()
wifi.eventmon.unregister()
Starts WiFi station event monitor.
wifi.sta.eventMonStart([ms])
ms
interval between checks in milliseconds, defaults to 150ms if not provided.
nil
--start WiFi event monitor with default interval
wifi.sta.eventMonStart()
--start WiFi event monitor with 100ms interval
wifi.sta.eventMonStart(100)
Stops WiFi station event monitor.
wifi.sta.eventMonStop([unregister_all])
unregister_all
enter 1 to unregister all previously registered functions.- Note: leave blank to leave callbacks registered
nil
--stop WiFi event monitor
wifi.sta.eventMonStop()
--stop WiFi event monitor and unregister all callbacks
wifi.sta.eventMonStop(1)
Scans AP list as a Lua table into callback function.
wifi.sta.getap([[cfg], format,] callback(table))
cfg
table that contains scan configurationssid
SSID == nil, don't filter SSIDbssid
BSSID == nil, don't filter BSSIDchannel
channel == 0, scan all channels, otherwise scan set channel (default is 0)show_hidden
show_hidden == 1, get info for router with hidden SSID (default is 0)
format
select output table format, defaults to 0- 0: old format (SSID : Authmode, RSSI, BSSID, Channel), any duplicate SSIDs will be discarded
- 1: new format (BSSID : SSID, RSSI, auth mode, Channel)
callback(table)
a callback function to receive the AP table when the scan is done. This function receives a table, the key is the BSSID, the value is other info in format: SSID, RSSID, auth mode, channel.
nil
-- print AP list in old format (format not defined)
function listap(t)
for k,v in pairs(t) do
print(k.." : "..v)
end
end
wifi.sta.getap(listap)
-- Print AP list that is easier to read
function listap(t) -- (SSID : Authmode, RSSI, BSSID, Channel)
print("\n"..string.format("%32s","SSID").."\tBSSID\t\t\t\t RSSI\t\tAUTHMODE\tCHANNEL")
for ssid,v in pairs(t) do
local authmode, rssi, bssid, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]+)")
print(string.format("%32s",ssid).."\t"..bssid.."\t "..rssi.."\t\t"..authmode.."\t\t\t"..channel)
end
end
wifi.sta.getap(listap)
-- print AP list in new format
function listap(t)
for k,v in pairs(t) do
print(k.." : "..v)
end
end
wifi.sta.getap(1, listap)
-- Print AP list that is easier to read
function listap(t) -- (SSID : Authmode, RSSI, BSSID, Channel)
print("\n\t\t\tSSID\t\t\t\t\tBSSID\t\t\t RSSI\t\tAUTHMODE\t\tCHANNEL")
for bssid,v in pairs(t) do
local ssid, rssi, authmode, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]*)")
print(string.format("%32s",ssid).."\t"..bssid.."\t "..rssi.."\t\t"..authmode.."\t\t\t"..channel)
end
end
wifi.sta.getap(1, listap)
--check for specific AP
function listap(t)
print("\n\t\t\tSSID\t\t\t\t\tBSSID\t\t\t RSSI\t\tAUTHMODE\t\tCHANNEL")
for bssid,v in pairs(t) do
local ssid, rssi, authmode, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]*)")
print(string.format("%32s",ssid).."\t"..bssid.."\t "..rssi.."\t\t"..authmode.."\t\t\t"..channel)
end
end
scan_cfg = {}
scan_cfg.ssid = "myssid"
scan_cfg.bssid = "AA:AA:AA:AA:AA:AA"
scan_cfg.channel = 0
scan_cfg.show_hidden = 1
wifi.sta.getap(scan_cfg, 1, listap)
--get RSSI for currently configured AP
function listap(t)
for bssid,v in pairs(t) do
local ssid, rssi, authmode, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]*)")
print("CURRENT RSSI IS: "..rssi)
end
end
ssid, tmp, bssid_set, bssid=wifi.sta.getconfig()
scan_cfg = {}
scan_cfg.ssid = ssid
if bssid_set == 1 then scan_cfg.bssid = bssid else scan_cfg.bssid = nil end
scan_cfg.channel = wifi.getchannel()
scan_cfg.show_hidden = 0
ssid, tmp, bssid_set, bssid=nil, nil, nil, nil
wifi.sta.getap(scan_cfg, 1, listap)
Gets the broadcast address in station mode.
wifi.sta.getbroadcast()
nil
broadcast address as string, for example "192.168.0.255",
returns nil
if IP address = "0.0.0.0".
Gets the WiFi station configuration.
wifi.sta.getconfig()
none
ssid, password, bssid_set, bssid
Note: If bssid_set is equal to 0 then bssid is irrelevant
--Get current Station configuration
ssid, password, bssid_set, bssid=wifi.sta.getconfig()
print("\nCurrent Station configuration:\nSSID : "..ssid
.."\nPassword : "..password
.."\nBSSID_set : "..bssid_set
.."\nBSSID: "..bssid.."\n")
ssid, password, bssid_set, bssid=nil, nil, nil, nil
Gets current station hostname.
wifi.sta.gethostname()
none
currently configured hostname
print("Current hostname is: \""..wifi.sta.gethostname().."\"")
Gets IP address, netmask, and gateway address in station mode.
wifi.sta.getip()
none
IP address, netmask, gateway address as string, for example "192.168.0.111". Returns nil
if IP = "0.0.0.0".
-- print current IP address, netmask, gateway
print(wifi.sta.getip())
-- 192.168.0.111 255.255.255.0 192.168.0.1
ip = wifi.sta.getip()
print(ip)
-- 192.168.0.111
ip, nm = wifi.sta.getip()
print(nm)
-- 255.255.255.0
Gets MAC address in station mode.
wifi.sta.getmac()
none
MAC address as string e.g. "18:fe:34:a2:d7:34"
Get RSSI(Received Signal Strength Indicator) of the Access Point which ESP8266 station connected to.
wifi.sta.getrssi()
none
- If station is connected to an access point,
rssi
is returned. - If station is not connected to an access point,
nil
is returned.
RSSI=wifi.sta.getrssi()
print("RSSI is", RSSI)
Sets station hostname.
wifi.sta.sethostname(hostname)
hostname
must only contain letters, numbers and hyphens('-') and be 32 characters or less with first and last character being alphanumeric
nil
if (wifi.sta.sethostname("NodeMCU") == true) then
print("hostname was successfully changed")
else
print("hostname was not changed")
end
Sets IP address, netmask, gateway address in station mode.
wifi.sta.setip(cfg)
cfg
table contain IP address, netmask, and gateway
{
ip = "192.168.0.111",
netmask = "255.255.255.0",
gateway = "192.168.0.1"
}
true if success, false otherwise
Sets MAC address in station mode.
wifi.sta.setmac(mac)
MAC address in string e.g. "DE:AD:BE:EF:7A:C0"
true if success, false otherwise
print(wifi.sta.setmac("DE:AD:BE:EF:7A:C0"))
Gets the current status in station mode.
wifi.sta.status()
nil
number: 0~5
- 0: STA_IDLE,
- 1: STA_CONNECTING,
- 2: STA_WRONGPWD,
- 3: STA_APNOTFOUND,
- 4: STA_FAIL,
- 5: STA_GOTIP.
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.
wifi.ap.config(cfg)
ssid
SSID chars 1-32pwd
password chars 8-64auth
authentication method, one ofwifi.OPEN
(default),wifi.WPA_PSK
,wifi.WPA2_PSK
,wifi.WPA_WPA2_PSK
channel
channel number 1-14 default = 6hidden
0 = not hidden, 1 = hidden, default 0max
maximal number of connections 1-4 default=4beacon
beacon interval time in range 100-60000, default = 100
nil
cfg={}
cfg.ssid="myssid"
cfg.pwd="mypassword"
wifi.ap.config(cfg)
Deauths (forcibly removes) a client from the ESP access point by sending a corresponding IEEE802.11 management packet (first) and removing the client from it's data structures (afterwards).
The IEEE802.11 reason code used is 2 for "Previous authentication no longer valid"(AUTH_EXPIRE).
wifi.ap.deauth([MAC])
MAC
address of station to be deauthed.- Note: if this field is left blank, all currently connected stations will get deauthed.
Returns true unless called while the ESP is in the STATION opmode
allowed_mac_list={"18:fe:34:00:00:00", "18:fe:34:00:00:01"}
wifi.eventmon.register(wifi.eventmon.AP_STACONNECTED, function(T)
print("\n\tAP - STATION CONNECTED".."\n\tMAC: "..T.MAC.."\n\tAID: "..T.AID)
if(allowed_mac_list~=nil) then
for _, v in pairs(allowed_mac_list) do
if(v == T.MAC) then return end
end
end
wifi.ap.deauth(T.MAC)
print("\tStation DeAuthed!")
end)
wifi.eventmon.register()
wifi.eventmon.reason()
Gets broadcast address in AP mode.
wifi.ap.getbroadcast()
none
broadcast address in string, for example "192.168.0.255",
returns nil
if IP address = "0.0.0.0".
bc = wifi.ap.getbroadcast()
print(bc)
-- 192.168.0.255
Gets table of clients connected to device in AP mode.
wifi.ap.getclient()
none
table of connected clients
table={}
table=wifi.ap.getclient()
for mac,ip in pairs(table) do
print(mac,ip)
end
-- or shorter
for mac,ip in pairs(wifi.ap.getclient()) do
print(mac,ip)
end
Gets IP address, netmask and gateway in AP mode.
wifi.ap.getip()
none
IP address, netmask, gateway address as string, for example "192.168.0.111", returns nil
if IP address = "0.0.0.0".
-- print current ip, netmask, gateway
print(wifi.ap.getip())
-- 192.168.4.1 255.255.255.0 192.168.4.1
ip = wifi.ap.getip()
print(ip)
-- 192.168.4.1
ip, nm = wifi.ap.getip()
print(nm)
-- 255.255.255.0
ip, nm, gw = wifi.ap.getip()
print(gw)
-- 192.168.4.1
Gets MAC address in AP mode.
wifi.ap.getmac()
none
MAC address as string, for example "1A-33-44-FE-55-BB"
Sets IP address, netmask and gateway address in AP mode.
wifi.ap.setip(cfg)
cfg
table contain IP address, netmask, and gateway
true if successful, false otherwise
cfg =
{
ip="192.168.1.1",
netmask="255.255.255.0",
gateway="192.168.1.1"
}
wifi.ap.setip(cfg)
Sets MAC address in AP mode.
wifi.ap.setmac(mac)
MAC address in byte string, for example "AC-1D-1C-B1-0B-22"
true if success, false otherwise
print(wifi.ap.setmac("AC-1D-1C-B1-0B-22"))
Configure the dhcp service. Currently only supports setting the start address of the dhcp address pool.
wifi.ap.dhcp.config(dhcp_config)
dhcp_config
table containing the start-IP of the DHCP address pool, eg. "192.168.1.100"
pool_startip
, pool_endip
dhcp_config ={}
dhcp_config.start = "192.168.1.100"
wifi.ap.dhcp.config(dhcp_config)
Starts the DHCP service.
wifi.ap.dhcp.start()
none
boolean indicating success
Stops the DHCP service.
wifi.ap.dhcp.stop()
none
boolean indicating success
Note: The functions wifi.sta.eventMon___()
and wifi.eventmon.___()
are completely seperate and can be used independently of one another.
Register/unregister callbacks for WiFi event monitor.
wifi.eventmon.register(Event[, function(T)])
Event: WiFi event you would like to set a callback for.
- Valid WiFi events:
- wifi.eventmon.STA_CONNECTED
- wifi.eventmon.STA_DISCONNECTED
- wifi.eventmon.STA_AUTHMODE_CHANGE
- wifi.eventmon.STA_GOT_IP
- wifi.eventmon.STA_DHCP_TIMEOUT
- wifi.eventmon.AP_STACONNECTED
- wifi.eventmon.AP_STADISCONNECTED
- wifi.eventmon.AP_PROBEREQRECVED
Function:
nil
Callback:
T: Table returned by event.
wifi.eventmon.STA_CONNECTED
Station is connected to access point.SSID
: SSID of access point.BSSID
: BSSID of access point.channel
: The channel the access point is on.
wifi.eventmon.STA_DISCONNECT
: Station was disconnected from access point.SSID
: SSID of access point.BSSID
: BSSID of access point.REASON
: See wifi.eventmon.reason below.
wifi.eventmon.STA_AUTHMODE_CHANGE
: Access point has changed authorization mode.old_auth_mode
: Old wifi authorization mode.new_auth_mode
: New wifi authorization mode.
wifi.eventmon.STA_GOT_IP
: Station got an IP address.IP
: The IP address assigned to the station.netmask
: Subnet mask.gateway
: The IP address of the access point the station is connected to.
wifi.eventmon.STA_DHCP_TIMEOUT
: Station DHCP request has timed out.- Blank table is returned.
wifi.eventmon.AP_STACONNECTED
: A new client has connected to the access point.MAC
: MAC address of client that has connected.AID
: SDK provides no details concerning this return value.
wifi.eventmon.AP_STADISCONNECTED
: A client has disconnected from the access point.MAC
: MAC address of client that has disconnected.AID
: SDK provides no details concerning this return value.
wifi.eventmon.AP_PROBEREQRECVED
: A probe request was received.MAC
: MAC address of the client that is probing the access point.RSSI
: Received Signal Strength Indicator of client.
wifi.eventmon.register(wifi.eventmon.STA_CONNECTED, function(T)
print("\n\tSTA - CONNECTED".."\n\tSSID: "..T.SSID.."\n\tBSSID: "..
T.BSSID.."\n\tChannel: "..T.channel)
end)
wifi.eventmon.register(wifi.eventmon.STA_DISCONNECTED, function(T)
print("\n\tSTA - DISCONNECTED".."\n\tSSID: "..T.SSID.."\n\tBSSID: "..
T.BSSID.."\n\treason: "..T.reason)
end)
wifi.eventmon.register(wifi.eventmon.STA_AUTHMODE_CHANGE, Function(T)
print("\n\tSTA - AUTHMODE CHANGE".."\n\told_auth_mode: "..
T.old_auth_mode.."\n\tnew_auth_mode: "..T.new_auth_mode)
end)
wifi.eventmon.register(wifi.eventmon.STA_GOT_IP, function(T)
print("\n\tSTA - GOT IP".."\n\tStation IP: "..T.IP.."\n\tSubnet mask: "..
T.netmask.."\n\tGateway IP: "..T.gateway)
end)
wifi.eventmon.register(wifi.eventmon.STA_DHCP_TIMEOUT, function()
print("\n\tSTA - DHCP TIMEOUT")
end)
wifi.eventmon.register(wifi.eventmon.AP_STACONNECTED, function(T)
print("\n\tAP - STATION CONNECTED".."\n\tMAC: "..T.MAC.."\n\tAID: "..T.AID)
end)
wifi.eventmon.register(wifi.eventmon.AP_STADISCONNECTED, function(T)
print("\n\tAP - STATION DISCONNECTED".."\n\tMAC: "..T.MAC.."\n\tAID: "..T.AID)
end)
wifi.eventmon.register(wifi.eventmon.AP_PROBEREQRECVED, function(T)
print("\n\tAP - STATION DISCONNECTED".."\n\tMAC: ".. T.MAC.."\n\tRSSI: "..T.RSSI)
end)
Unregister callbacks for WiFi event monitor.
wifi.eventmon.unregister(Event)
Event: WiFi event you would like to set a callback for.
- Valid WiFi events:
- wifi.eventmon.STA_CONNECTED
- wifi.eventmon.STA_DISCONNECTED
- wifi.eventmon.STA_AUTHMODE_CHANGE
- wifi.eventmon.STA_GOT_IP
- wifi.eventmon.STA_DHCP_TIMEOUT
- wifi.eventmon.AP_STACONNECTED
- wifi.eventmon.AP_STADISCONNECTED
- wifi.eventmon.AP_PROBEREQRECVED
nil
wifi.eventmon.unregister(wifi.eventmon.STA_CONNECTED)
Table containing disconnect reasons.
Disconnect reason | value |
---|---|
wifi.eventmon.reason.UNSPECIFIED | 1 |
wifi.eventmon.reason.AUTH_EXPIRE | 2 |
wifi.eventmon.reason.AUTH_LEAVE | 3 |
wifi.eventmon.reason.ASSOC_EXPIRE | 4 |
wifi.eventmon.reason.ASSOC_TOOMANY | 5 |
wifi.eventmon.reason.NOT_AUTHED | 6 |
wifi.eventmon.reason.NOT_ASSOCED | 7 |
wifi.eventmon.reason.ASSOC_LEAVE | 8 |
wifi.eventmon.reason.ASSOC_NOT_AUTHED | 9 |
wifi.eventmon.reason.DISASSOC_PWRCAP_BAD | 10 |
wifi.eventmon.reason.DISASSOC_SUPCHAN_BAD | 11 |
wifi.eventmon.reason.IE_INVALID | 13 |
wifi.eventmon.reason.MIC_FAILURE | 14 |
wifi.eventmon.reason.4WAY_HANDSHAKE_TIMEOUT | 15 |
wifi.eventmon.reason.GROUP_KEY_UPDATE_TIMEOUT | 16 |
wifi.eventmon.reason.IE_IN_4WAY_DIFFERS | 17 |
wifi.eventmon.reason.GROUP_CIPHER_INVALID | 18 |
wifi.eventmon.reason.PAIRWISE_CIPHER_INVALID | 19 |
wifi.eventmon.reason.AKMP_INVALID | 20 |
wifi.eventmon.reason.UNSUPP_RSN_IE_VERSION | 21 |
wifi.eventmon.reason.INVALID_RSN_IE_CAP | 22 |
wifi.eventmon.reason.802_1X_AUTH_FAILED | 23 |
wifi.eventmon.reason.CIPHER_SUITE_REJECTED | 24 |
wifi.eventmon.reason.BEACON_TIMEOUT | 200 |
wifi.eventmon.reason.NO_AP_FOUND | 201 |
wifi.eventmon.reason.AUTH_FAIL | 202 |
wifi.eventmon.reason.ASSOC_FAIL | 203 |
wifi.eventmon.reason.HANDSHAKE_TIMEOUT | 204 |