Function | Definition |
---|---|
wifi.startap() | Setup wifi in soft Access Point (AP) Mode, enable DHCP function |
wifi.startsta() | Setup wifi in Station Mode (STA), begin to connect a AP |
wifi.scan() | Scan APs |
wifi.stop() | Close all the Wi-Fi connections, Both in station mode and soft ap mode |
wifi.powersave() | Enable IEEE power save mode |
wifi.ap.getip() | Get ip address in soft AP mode |
wifi.ap.getipadv() | Get advanced net information in soft AP mode: DHCP mode, ip address, gateway, netmask, dns, MAC, broad cast address |
wifi.ap.stop() | Close all the Wi-Fi connections in soft ap mode |
wifi.sta.getip() | Get ip address in STA mode |
wifi.sta.getipadv() | Get advanced net information in STA mode: DHCP mode, ip address, gateway, netmask, dns, MAC, broad cast address |
wifi.sta.getlink() | Get the connected AP information in STA mode:Connect status, WiFi signal strength, ssid, bssid. |
wifi.sta.stop() | Close all the Wi-Fi connections in STA mode |
Description
Setup wifi in soft Access Point (AP) Mode, enable DHCP function.
Syntax
wifi.startap(cfg)
wifi.startap(cfg,func_cb)
Parameters
cfg: lua table, contains the configurations for soft AP mode.
cfg.ssid: soft AP’s ssid
cfg.pwd: soft AP’s password. It will be an open WiFi if cfg.pwd is empty
cfg.ip: optional. The local ip address of the module, It’s “11.11.11.1” in default.
cfg.netmask:optional. Netmask. It’s “255.255.255.0” in default.
cfg.gateway:optional. Gateway. It’s “11.11.11.1” in default.
cfg.dnsSrv:optional. DNS server address. It’s “11.11.11.1” in default.
cfg.retry_interval:optional. retry interval in micro seconds. It’s 1000ms in default.
func_cb: The callback function when the soft AP is setup successfully or the soft AP is shut down. Function prototype is: func_cb(info). “info” is the information indicates the event: ‘STATION_UP’, ‘STATION_DOWN’, ‘AP_UP’, ‘AP_DOWN’, ‘ERROR’
Returns
nil
Examples
-cfg={}
-cfg.ssid="WiFiMCU_Wireless"; cfg.pwd=""
-wifi.startap(cfg)
Description
Setup wifi in Station Mode (STA), begin to connect a AP.
Syntax
wifi.startsta(cfg)
wifi.startsta(cfg, func_cb)
Parameters
cfg: lua table, contains the configurations for soft AP mode.
cfg.ssid: AP’s ssid
cfg.pwd: AP’s password
cfg.dhcp: optional. Set dhcp function: ‘enable’ is to enable the dhcp function. WiFiMCU will get ip automatically. ‘disable’ is to disable the dhcp function. It’s ’enable’ in default.
cfg.ip: optional. The local ip address of the module. If cfg.dhcp is ‘disable’ this parameter must be assigned.
cfg.netmask:optional. Netmask. If cfg.dhcp is ‘disable’ this parameter must be assigned.
cfg.gateway:optional. Gateway. If cfg.dhcp is ‘disable’ this parameter must be assigned.
cfg.dnsSrv:optional. DNS server address. If cfg.dhcp is ‘disable’ this parameter must be assigned.
cfg.retry_interval:optional. retry interval in micro seconds. If cfg.dhcp is ‘disable’ this parameter must be assigned.
func_cb: The callback function when WiFiMCU had connected to the AP successfully, or WiFiMCU is disconnected to from the AP. Function prototype is: func_cb(info). “info” is the information indicates the event: ‘STATION_UP’, ‘STATION_DOWN’, ‘AP_UP’, ‘AP_DOWN’, ‘ERROR’
Returns
nil
Examples
-cfg={}
-cfg.ssid="Doit"; cfg.pwd="123456789"
-wifi.startsta(cfg)
Description
Scan AP list and return a Lua table contains the results.
Syntax
wifi.scan(fun_cb(t))
Parameters
func_cb(t): The callback function when scan is finished. ‘t’ is a Lua table in which the keys are the APs' ssid and values are strings in format (“ mac, signal strength, channel, authmode”)
Returns
nil
Examples
-function listap(t) if t then for k,v in pairs(t) do print(k.."\t"..v);end else print('no ap') end end
-wifi.scan(listap)
CMCC-WEB 00:23:89:22:98:B0,90,11,OPEN
MERCURY_44B6 C0:61:18:21:44:B6,75,6,WPA2 AES
Tomato 8C:28:06:1E:01:54,100,11,WPA2 AES
ChinaNet-mALi 8C:E0:81:30:C1:95,65,10,WPA2 AES
Wireless 00:25:12:62:A6:36,57,6,OPEN
CMCC 00:23:89:22:98:B1,87,11,WPA2 AES
CMCC-FREE 00:23:89:96:02:03,60,11,OPEN
Doit BC:D1:77:32:E7:2E,100,1,WPA2 AES
Description
Close all the Wi-Fi connections, Both in station mode and soft ap mode.
Syntax
wifi.stop()
Parameters
nil
Returns
nil
See also
wifi.ap.stop()
wifi.sta.stop()
Examples
-wifi.stop()
Description
Enable IEEE power save mode.
Syntax
wifi. powersave ()
Parameters
nil
Returns
nil
Examples
-wifi. powersave ()
Description
Get ip address in AP mode
Syntax
ip=wifi. ap.getip()
Parameters
nil
Returns
ip: The module ip in soft AP mode.
Examples
-ip=wifi.ap.getip ()
-print(ip)
11.11.11.1
Description
Get advanced net information in soft AP mode: DHCP mode, ip address, gate way, net mast, dns, MAC, broad cast address.
Syntax
dhcp,ip,gw,nm,dns,mac,bip =wifi. ap.getipadv()
Parameters
nil
Returns
dhcp: DHCP mode. in soft AP mode, it will be always “DHCP_Server”
ip: ip address.
gw: gateway address.
nm: netmask.
dns: dns address.
mac: MAC address.
bip: broadcast ip address.
Examples
-dhcp,ip,gw,nm,dns,mac,bip =wifi.ap.getipadv()
-print(dhcp,ip,gw,nm,dns,mac,bip)
DHCP_Server 11.11.11.1 11.11.11.1 255.255.255.0 208.67.222.222 c89346501a62 255.255.255.255
Description
Close all the Wi-Fi connections in soft ap mode.
Syntax
wifi.ap.stop()
Parameters
nil
Returns
nil
See also
wifi.stop()
wifi.sta.stop()
Examples
-wifi.ap.stop()
Description
Get ip address in STA mode.
Syntax
ip=wifi. sta.getip()
Parameters
nil
Returns
ip: The module ip in STA mode.
Examples
-ip=wifi.sta.getip ()
-print(ip)
192.168.1.108
Description
Get advanced net information in STA mode: DHCP mode, ip address, gateway, netmask, dns, MAC, broad cast address.
Syntax
dhcp,ip,gw,nm,dns,mac,bip =wifi. sta.getipadv()
Parameters
nil
Returns
dhcp: DHCP mode. in STA mode, “DHCP_Server” or “DHCP_Client” or DHCP_Disable
ip: ip address.
gw: gateway address.
nm: netmask.
dns: dns address.
mac: MAC address.
bip: broadcast ip address.
Examples
-dhcp,ip,gw,nm,dns,mac,bip =wifi.sta.getipadv()
-print(dhcp,ip,gw,nm,dns,mac,bip)
DHCP_Client 192.168.1.108 192.168.1.1 255.255.255.0 192.168.1.1 c89346501a62 255.255.255.255
Description
Get the connected AP information in STA mode:Connect status, WiFi signal strength, ssid, bssid.
Syntax
status,strength,ssid,bssid=wifi.sta.getlink()
Parameters
nil
Returns
status: The connecting status. if connected it’s “connected” else it’s “disconnected”. It will be nil for strength/ssid/bssid if it’s “disconnected”.
strength: The signal strength.
ssid:The connected AP’s ssid.
bssid: The connected AP’s bssid.
Examples
-status,strength,ssid,bssid=wifi.sta.getlink()
-print(status,strength,ssid,bssid)
connected 62 Doit BC:D1:77:32:E7:2E
Description
Close all the Wi-Fi connections inSTA mode.
Syntax
wifi.sta.stop()
Parameters
nil
Returns
nil
See also
wifi.stop()
wifi.ap.stop()
Examples
-wifi.sta.stop()