6.5.2 Establishing the Wi-Fi Connection

The default initialization code installs the WILCS02 driver when the kernel detects the WILCS02-SD board, and sets it to SoftAP mode upon booting up. An NGINX web server is running to host the web server which allows the users to provide the target AP credentials. Users can connect a STA device (PC or mobile phone) to the WILCS02 SoftAP and input the target AP’s SSID and Pass phrase through a webpage to configure the WILCS02 to run in STA mode to connect to the target network.

The following figure illustrates the kernel detecting the WILCS02 SDIO card and installing the WILCS02 driver.
Figure 6-4. Kernel Showing Detection of the WILCS02 and Driver Installation
The following is the sequence of the establishing the Wi-Fi® connection :
  1. During the initialization, /etc/init.d/S85start-wlan automatically runs and executes /root/Start_AP.sh, which runs the hostapd application in the background to configure the Wi-Fi device to set as SoftAP.
    1. script /root/Start_AP.sh: This script initiates the Wi-Fi interface and use hostapd to set the device to softAP mode.
    2. /etc/init.d/S80dhcp-server: Runs as a DHCP server to distribute IP addresses to the connected clients (STA).
    3. /root/websocket: Use this to create web socket connection to receive the network credential information from the web server.
  2. The script /root/Start_AP.sh initializes the Wi-Fi interface, configures the device to SoftAP mode, starts necessary services like hostapd and DHCP, and sets up a WebSocket daemon for network credential communication.
    #!/bin/sh
    if lsmod | grep -q "wilc_sdio" ; then
            echo "1.############## WILCS02-SDIO module is available ##############"
    else
            echo "1. Inserting the wilcs02-sdio module"
            modprobe wilc-sdio
            if lsmod | grep -q "wilc_sdio";  then
                    echo "WILCS02-SDIO module insterted successfully"
            else
                    echo "WILCS02-SDIO module insert failed"
                    exit 0
            fi
    fi
    echo "2.############## Bringing up the wlan0 interface ##############"
    while true
    do
        if ifconfig wlan0 &> /dev/nulL
        then
            echo "wlan0 interface exists"
            break
        else
            echo "wlan0 interface does not exist"
        fi
    
        sleep 5  # Adjust the sleep duration as needed
    done
    ifconfig wlan0 up
    if ifconfig | grep -q "wlan0" ; then
            echo "Wireless LAN interface is UP!"
    else
            echo "Wireless LAN interface has FAILED"
            exit 0
    fi
    
    echo "3.############## Starting the Host AP deamon ##############"
    hostapd /etc/wilc_hostapd_open.conf -B &
    if ps | grep -q "hostapd" ;
    then
            echo "hostapd process has started successfully"
    else
            echo "hostapd has failed to start"
            exit 0
    fi
    echo "4.############## Configuring the AP IP Address to 192.168.0.1 ##############"
    ifconfig wlan0 192.168.0.1
    echo "5.############## Starting the DHCP server ##############"
    /etc/init.d/S80dhcp-server restart
    echo "6.############## Starting the WEB scoket deamon ##############"
    cd /root
    ./websocket &
    echo "Now, The device comes up as an Access Point(AP) mode"
  3. After the platform boot up, the users can use PC or mobile phone and perform the following:
    1. Scan Wi-Fi and discover SSID microchip -SoftAP.
    2. Connect PC or mobile phone to the WILCS02 SoftAP
      • SSID: microchip-SoftAP
      • Security: Open
    Figure 6-5. Discover SoftAP by Phone
  4. Use a browser to access 192.168.1.1. The user can see a network provisioning webpage.
  5. Input the SSID and the “Pass phrase” of the target AP. Click Connect.
    Figure 6-6. Network Provisioning Webpage (new)
  6. The websocket process receive the target AP’s credentials. It reboots the platform to run in Station mode to connect the target AP. The websocket process adds the /etc/run_sta file to the system so that the platform can run in Station mode when it boots up.
    Note:
    1. The user can remove the file /etc/run_sta and reboot to set the platform to the SoftAP mode again (if necessary).
    2. There is a known issue where a hard reboot may require re-initializing the WILC-SDIO operation at this step.
    Figure 6-7. Console Log Showing WebSocket Receive AP Credentials
    Figure 6-8. Console Log Showing Device is Rebooted
  7. The script /root/Start_STA.sh is executed when the platform boots up to run the platform in Station mode and connect to the target AP. This script initiates the Wi-Fi interface and use wpa_supplicant to connect the device to the target AP. udhcpc runs as a DHCP client to obtain IP address.
    #!/bin/bash
    sh /root/check_linkstat.sh & 
    ifconfig wlan0 up
    wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf &
    udhcpc -i wlan0 &
  8. The LED (D5) on the SAMA5D27-SOM1-EK1 evaluation board indicates the Wi-Fi connection status. When the platform successfully to connects to the target AP, the LED (D5) on the board turns ON in blue color.
    • Blinking Blue: The device is attempting to connect to the target AP.
    • Solid Blue: The device has successfully connected to the target AP.
    Figure 6-9. Console Log Showing the Device Connect AP
  9. Checking Network Connectivity – The user can check the network connectivity using the following commands:
    • iwconfig
    • ifconfig
    Figure 6-10. Console Log of Command iwconfig and ifconfig