Initialization and Connection
Inkplate2 uses ESP32 to handle WiFi connections. This page demonstrates how to connect your Inkplate board to an existing WiFi network.
WiFi Connection Example
from inkplate2 import Inkplate
import network
import time
# WiFi credentials
SSID = "YOUR_SSID_HERE"
PASSWORD = "YOUR_PASSWORD_HERE"
inkplate = Inkplate()
inkplate.begin()
# Connect to a WiFi network using given SSID and PASSWORD.
sta_if = network.WLAN(network.STA_IF)
connected = False
if not sta_if.isconnected():
inkplate.println("Connecting to network...")
sta_if.active(True)
try:
sta_if.connect(SSID, PASSWORD)
except Exception as e:
print(f"Wi-Fi connect error: {e}\n")
print("Check your credentials!")
else:
timeout = 30 # seconds
start = time.ticks_ms()
while not sta_if.isconnected():
if time.ticks_diff(time.ticks_ms(), start) > timeout * 1000:
print("Failed to connect within timeout")
break
time.sleep(0.5)
else:
connected = True
else:
connected = True
if connected:
inkplate.print(f"CONNECTED: \n{sta_if.ifconfig()}")
inkplate.display()
network.WLAN()
Create a WLAN network interface object and connect to WiFi access point
Function parameters:
| Type | Name | Description |
|---|---|---|
int | interface_id | Set to network.STA_IF for connecting to access point, or network.STA_AP to allow other WiFi clients to connect |
WLAN.active()
Create a WLAN network interface object and connect to WiFi access point
Returns value: Returns current state if no argument is provided
Function parameters:
| Type | Name | Description |
|---|---|---|
bool | is_active | Activate/Deactivate network interface if arguments is passed |
WLAN.connect()
Connect to the specified wireless network, using the specified key (only works in STA interface)
Function parameters:
| Type | Name | Description |
|---|---|---|
string | ssid | Network SSID |
string | key | Network password |
WLAN.isconnected()
Check the connection status
Returns type: Bool
Returns value: Returns True if connected to a WiFi access point and has a valid IP address. In AP mode returns True when a station is connected, otherwise False
WLAN.ifconfig()
Get/Set network interface parameters: IP address, subnet mask, gateway and DNS server
Returns type: Tuple
Returns value: When called with no arguments, returns a 4-tuple with the above information
Function parameters:
| Type | Name | Description |
|---|---|---|
Tuple | (ip, subnet, gateway, dns) | Network parameters |