# K230 Linux WiFi Usage Guide

## Overview

This document describes how to configure and use WiFi on the K230 development board.

## Connecting to a WiFi Hotspot

> **Note**: Some devices only support 2.4GHz WiFi. Please do not connect to hotspots that combine 2.4GHz and 5GHz.

Three methods for connecting to a WiFi hotspot are provided below. Choose the one that best suits your needs.

### Method 1: Configure via Environment Variables

Use the `fw_setenv` command to set the WiFi SSID and password, then reboot the system for the configuration to take effect.

```bash
fw_setenv wlanssid wifi_test
fw_setenv wlanpass 12345678
reboot
```

### Method 2: Use the sta.sh Script

Use the system-provided `sta.sh` script to quickly connect to WiFi:

```bash
sta.sh wlan0 wifi_test 12345678
```

> **Note**: This script encapsulates common WiFi connection commands and is the recommended convenient connection method.

### Method 3: Manual Configuration

Taking K230-Canmv as an example, the board is equipped with the AP6212 WiFi module by default. After the system starts, follow these steps to manually configure WiFi:

```bash
# View network interfaces
ifconfig -a

# Bring up the network interface
ifconfig wlan0 up

# Start the wpa_supplicant service
wpa_supplicant -D nl80211 -i wlan0 -c /etc/wpa_supplicant.conf -B

# Scan for hotspots
wpa_cli -i wlan0 scan

# Print scan results
wpa_cli -i wlan0 scan_result

# Add network configuration
network_id=$(wpa_cli -i wlan0 add_network)

# Set SSID
wpa_cli -i wlan0 set_network $network_id ssid '"wifi_test"'

# Set password
wpa_cli -i wlan0 set_network $network_id psk '"12345678"'

# Select the network to connect to
wpa_cli -i wlan0 select_network $network_id

# Obtain an IP address
udhcpc -i wlan0 -q
```

> **Tip**: After a successful connection, you can use the `ping` command to test network connectivity.
