WIFI
WiFi ( -- )
Select WiFi
vocabulary:
WIFI_MODE_APSTA WIFI_MODE_AP WIFI_MODE_STA WIFI_MODE_NULL WiFi.begin WiFi.config WiFi.disconnect WiFi.getTxPower WiFi.localIP WiFi.macAddress WiFi.mode WiFi.setTxPower WiFi.status
The esp32 WiFi programming model can be depicted as following picture:
default handler user handler ------------- --------------- --------------- | | event | | callback or | | | tcpip | ---------> | event | ----------> | application | | stack | | task | event | task | |-----------| |-------------| |-------------| /|\ | | | event | | | | | | --------------- | | | | | WiFi Driver |/__________________| | |\ API call | | |-------------|
Wifi.begin ( ssid-z password-z -- )
Initializes the WiFi library's network settings and provides the current status.
z" mySSID" z" myPASSWORD" Wifi.begin
WiFi.config ( ip dns gateway subnet -- )
WiFi.config
allows you to configure a static IP address as well as change the
DNS, gateway, and subnet addresses on the WiFi shield.
Unlike WiFi.begin
which automatically configures the WiFi shield to use DHCP,
WiFi.config
allows you to manually set the network address of the shield.
Calling WiFi.config
before WiFi.begin
forces to configure the WiFi
with the network addresses specified in WiFi.config
.
Parameters:
- ip: the IP address of the device
- dns: the address for a DNS server.
- gateway: the IP address of the network gateway
- subnet: the subnet mask of the network
Wifi.disconnect ( -- )
Disconnects the WiFi shield from the current network.
WiFi.getTxPower ( -- powerx4 )
Get power x4
WiFi.localIP ( -- ip )
Get local IP
WiFi.macAddress ( a -- )
Gets the MAC Address of your ESP32 WiFi port.
create mac 6 allot mac WiFi WiFi.macAddress
WiFi.status ( -- n )
Return the connection status:
- 255 WL_NO_SHIELD
assigned when no WiFi shield is present - 0 WL_IDLE_STATUS
it is a temporary status assigned whenWiFi.begin
is called and remains active until the number of attempts expires (resulting in WL_CONNECT_FAILED) or a connection is established (resulting in WL_CONNECTED) - 1 WL_NO_SSID_AVAIL
assigned when no SSID are available - 2 WL_SCAN_COMPLETED
assigned when the scan networks is completed - 3 WL_CONNECTED
assigned when connected to a WiFi network - 4 WL_CONNECT_FAILED
assigned when the connection fails for all the attempts - 5 WL_CONNECTION_LOST
assigned when the connection is lost - 6 WL_DISCONNECTED
assigned when disconnected from a network
Example:
WiFi.status . \ display status
WiFi.mode ( mode -- )
Constants:
- 0
WIFI_MODE_NULL
,
NULL mode: in this mode, the internal data struct is not allocated to the station and the AP, while both the station and AP interfaces are not initialized for RX/TX Wi-Fi data. Generally, this mode is used for Sniffer, or when you only want to stop both the STA and the AP to unload the whole Wi-Fi driver. - 1
WIFI_MODE_STA
,
Station mode: in this mode, will init the internal station data, while the station’s interface is ready for the RX and TX Wi-Fi data. - 2
WIFI_MODE_AP
,
AP mode: in this mode, init the internal AP data, while the AP’s interface is ready for RX/TX Wi-Fi data. Then, the Wi-Fi driver starts broad- casting beacons, and the AP is ready to get connected to other stations. - 3
WIFI_MODE_APSTA
,
Station-AP coexistence mode: in this mode, will simultaneously init both the station and the AP.This is done in station mode and AP mode. Please note that the channel of the external AP, which the ESP Station is connected to, has higher priority over the ESP AP channel.
WiFi.setTxPower ( powerx4 -- )
Set power x4