The WLAN (WiFi) is a system feature of all SG devices, therefore it is enabled by default. The development boards include an on-board antenna by default, so no external antenna is needed to get started. When deploying your solution, you might want to consider using the external antenna to increase the wireless range.
On this page, we cover:
Note: Generally, code in either sections is applicable to both WLAN modes.
Using the WLAN class from network, you can change the name (SSID) and security settings (auth) of the access point.
import network ap = network.WLAN(network.AP_IF) # create access-point interface ap.config(essid='ESP-AP') # set the ESSID of the access point ap.config(password='micropython') ap.config(authmode=network.AUTH_WPA2_PSK) ap.config(max_clients=10) # set how many clients can connect to the network ap.active(True) # activate the interface
The device will not be able to access the internet, but you will be able to run a simple webserver. By default, the ip address will be configured to 192.168.4.1.
192.168.4.1
To connect it to an existing network, the WiFi class must be configured as a station:
import network wlan = network.WLAN(network.STA_IF) # create station interface wlan.active(True) # activate the interface wlan.scan() # scan for access points wlan.isconnected() # check if the station is connected to an AP wlan.connect('essid', 'password') # connect to an AP wlan.config('mac') # get the interface's MAC address wlan.ifconfig() # get the interface's IP/netmask/gw/DNS addresses
Note: For more details on the WLAN class, please refer to this link: https://docs.micropython.org/en/v1.19.1/library/network.WLAN.html
Connect a WiFi antenna to this microwave SWF type switch connector on your development board in order to use an external antenna for WiFi.
The microwave SWF type switch connector is a hardware connector with switch. By default, it is connected to on-board Wi-Fi chip antenna. If external antenna is connected to the SWF type switch connector, the connector will switch to exteranl antenna and is isolated from default on-board Wi-Fi chip antenna.
Note: Since BLE and Wi-Fi are sharing the same RF path, if external antenna is connected both Wi-Fi and BLE signals will go through the external antenna.