Network Configuration¶
Wireless network configuration¶
The tool wpa_supplicant
is used for wireless network configuration. It’s a tool for WIFI connection and configuration, which mainly includes two programs: wpa_supplicant
and wpa_cli
.
Command Line¶
WIFI Enabled¶
echo 1 >/sys/class/rkwifi/driver
ifconfig wlan0 up
When it’s done, Running command ifconfig
, the wlan0
node can be seen.
Start wpa_supplicant Process¶
wpa_supplicant -B -i wlan0 -c /data/cfg/wpa_supplicant.conf
Creating the file: /data/cfg/wpa_supplicant.conf if it does not exist, the following configuration need to be added:
vi /data/cfg/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
Configure WIFI with wpa_cli¶
Common commands:
wpa_cli -i wlan0 scan // Search wifi network nearby
wpa_cli -i wlan0 scan_result // Print the searched WiFi network
wpa_cli -i wlan0 add_network // Add a network connection
If wireless network is encrypted by [WPA-PSK-CCMP+TKIP] [WPA2-PSK-CCMP+TKIP] [ESS] (wpa encryption), and the wifi name: name, wifi password: psk. The connecting operation is as follows:
wpa_cli -i wlan0 set_network 0 ssid '"name"'
wpa_cli -i wlan0 set_network 0 psk '"psk"'
wpa_cli -i wlan0 enable_network 0 //Enable WiFi
If wireless network is encrypted by [WEP] [ESS] (wep encryption), and the wifi name: name, wifi password: psk. The connecting operation is as follows:
wpa_cli -i wlan0 set_network 0 ssid '"name"'
wpa_cli -i wlan0 set_network 0 key_mgmt NONE
wpa_cli -i wlan0 set_network 0 wep_key0 '"psk"'
wpa_cli -i wlan0 enable_network 0
If wireless network is encrypted by [ESS] (no encryption),and the wifi name: name, the connecting operation is as follows:
wpa_cli -i wlan0 set_network 0 ssid '"name"'
wpa_cli -i wlan0 set_network 0 key_mgmt NONE
wpa_cli -i wlan0 enable_network 0
Save WIFI connection information:
wpa_cli -i wlan0 save_config
Resume the saved connection:
wpa_cli -i wlan0 list_network // List all saved connections
wpa_cli -i wlan0 select_network 0 // Connect the first saved connection
wpa_cli -i wlan0 enable_network 0 // Enable the first saved connection
Turn off WiFi:
ifconfig wlan0 down
WIFI configuration file¶
Modify the following files:
vi /data/cfg/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
Add following items:
network={
ssid="WiFi-AP" // WiFi name
psk="12345678" // WiFi password
key_mgmt=WPA-PSK // Encryption
# key_mgmt=NONE // No encryption
}
Re-load the above configurations:
wpa_cli reconfigure
Re-connection:
wpa_cli reconnect
Configure WIFI by mobile phone¶
There are many ways to use mobile phones to configure WiFi networks, either through Softap or Bluetooth. The integrated speech recognition SDK will also include its own methods, such as “小度之家 SDK”.
The built-in network configuration methods of ROC-RK3308-CC will be introduced here.
Configure WIFI Network with SoftAP¶
Download the APP: RkEcho.apk, or it can be found in SDK:SDK/external/app/RkEcho.apk
Buildroot configuration:
Source directory of softapServer:
/external/softapServer/ -- operations related to WIFI and APK
/external/softapDemo/ -- operations related to WiFi
Prepare a mobile phone to install apk RkEcho.apk, it’s indispensable.
Then, confirm the wpa_supplicant process has started
wpa_supplicant -B -i wlan0 -c /data/cfg/wpa_supplicant.conf
Configure WIFI Network as follows:
● Running the following commands:
softapServer Rockchip-Echo-123
Note: wifi AP must be named in the format Rockchip-Echo-xxx。
● After the AP is turned on, open the WiFi settings of the mobile phone and click on the connection to the AP just set up , such as Rckchip-Echo-123.
● When connection is done, open the apk installed in the mobile phone and conduct the following operation:
Open apk, click wifi setup -> CONFIRM -> 确认 -> wifi list -> click the network to be connected -> input password -> click OK.
● Start to use when the voice prompts to notify network has been connected!
● Check if network is connected:
# ping www.google.com
● Noted points:
When the command
softspServer Rockchip-Echo-123
has been executed, it cannot be withdrawn till the network config has been completed.Never setup a wrong AP name, otherwise apk will not enter the confirmation interface (Rockchip-Echo-xxx)
This function only supports Android phones currently.
IP address setting¶
Dynamically obtain IP address¶
WIFI dynamically obtains IP address , run the following commands:
udhcpc -i wlan0 -R
Ethernet dynamically obtains IP address , run the following commands:
udhcpc -i eth0 -R
Set static IP address¶
Steps of static IP address setting for Ethernet are as follows:
ip addr add 168.168.100.78/255.255.0.0 dev eth0 #ip address/subnet mask
ip route flush dev eth0
ip route add 168.168.0.1 dev eth0 #gateway
ip route add default via 168.168.0.1 dev eth0 #add default router
echo -e "nameserver 114.114.114.114\nnameserver 8.8.8.8" > /userdata/resolv.conf #set DNS
Steps of static IP address for WIFI are the same with above.