3.1.12.1 Execution

main.c - Initialize the ATWINC15x0 and connect to the AP using WPS.

  1. Code summary:
    Case 1: WEP Security Method
    • To test WEP security, modify MAIN_WLAN_DEVICE_NAME, MAIN_WLAN_WEP_KEY_INDEX and MAIN_WLAN_WEP_KEY_40 or MAIN_WLAN_WEP_KEY_104 in main.h.
      /** security information for Wi-Fi connection */
      #define MAIN_WLAN_DEVICE_NAME           "DEMO_AP" /**< Destination SSID */
      #define MAIN_WLAN_WEP_KEY_INDEX         1 /**< WEP key index */
      /**< 64 bit WEP key. In case of WEP64, 10 hexadecimal (base 16) characters (0-9 and A-F) ) */
      #define MAIN_WLAN_WEP_KEY_40            "1234567890" 
      /**< 128 bit WEP key. In case of WEP128, 26 hexadecimal (base 16) characters (0-9 and A-F) ) */
      #define MAIN_WLAN_WEP_KEY_104           "1234567890abcdef1234567890" 
    • When pressing the SW0 button on the SAM D21, it will trigger WPS in the btn_press() function.
      /** Security parameters for 64 bit WEP Encryption @ref m2m_wifi_connect */
      tstrM2mWifiWepParams wep64_parameters = { MAIN_WLAN_WEP_KEY_INDEX, 
                                              sizeof(MAIN_WLAN_WEP_KEY_40),
                                              MAIN_WLAN_WEP_KEY_40};
      /** Security parameters for 128 bit WEP Encryption @ref m2m_wifi_connect */
      tstrM2mWifiWepParams wep128_parameters = { MAIN_WLAN_WEP_KEY_INDEX,
                                                sizeof(MAIN_WLAN_WEP_KEY_104),
                                                MAIN_WLAN_WEP_KEY_104};
      /* Case 1. Connect to AP with security type WEP. */
      m2m_wifi_connect((char *)MAIN_WLAN_DEVICE_NAME, strlen((char *)MAIN_WLAN_DEVICE_NAME),
           M2M_WIFI_SEC_WEP, &wep64_parameters, M2M_WIFI_CH_ALL);
    Case 2: WPA-PSK Security Method
    • To test WPA security, use case 2 in the main() function and modify MAIN_WLAN_PSK in main.h.
      #define MAIN_WLAN_PSK     "12345678" /**< Password for Destination SSID */
    • Connect to the AP with the given information.
      /* Case 2. Connect to AP with security type WPA. */
      m2m_wifi_connect((char *)MAIN_WLAN_DEVICE_NAME, strlen((char *)MAIN_WLAN_DEVICE_NAME),
           M2M_WIFI_SEC_WPA_PSK, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL);
  2. Prepare an AP that supports WEP and WPA/WPA2 Security and configure its Wi-Fi Security. For more information, refer to the AP manufacturer's manual.
  3. Run the application. If the device connected successfully, the IP address assigned by DHCP will be displayed on the terminal program.