3.1.11.1 Execution

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

  1. Code summary:
    Case 1: Push Button Method
    • To test the WPS button method, configure the WPS push button feature in main.h as below and use case 1 in the main() function.
      /** WPS Push Button Feature */
      #define MAIN_WPS_PUSH_BUTTON_FEATURE     true
      /* Device name must be set before enabling WPS mode. */
      m2m_wifi_set_device_name((uint8 *)devName, strlen(devName));
      if (MAIN_WPS_PUSH_BUTTON_FEATURE) {
      /* case 1 WPS Push Button method. */
          if (!gbPressButton){
              btn_init();
          }
      }
    • When pressing the SW0 button on the SAMD21, it will trigger WPS in the btn_press() function.
      /* Connect to defined AP. */
      m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), 
                      MAIN_WLAN_AUTH, (void *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL);
    • The wifi_cb() will receive the M2M_WIFI_REQ_WPS message and it can connect to the AP with the given information.
      static void wifi_cb(uint8_t u8MsgType, void *pvMsg)
      {
          case M2M_WIFI_REQ_WPS:
          {
      	tstrM2MWPSInfo *pstrWPS = (tstrM2MWPSInfo *)pvMsg;
      	printf("Wi-Fi request WPS\r\n");
      	printf("SSID : %s, authtyp : %d pw : %s\n", pstrWPS->au8SSID, pstrWPS->u8AuthType, pstrWPS->au8PSK);
      	if (pstrWPS->u8AuthType == 0) {
      	    printf("WPS is not enabled OR Timedout\r\n");
      	    m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
      	    /* WPS is not enabled by firmware OR WPS monitor timeout.*/
      	} else{
      	    printf("Request Wi-Fi connect\r\n");
      	    m2m_wifi_connect((char *)pstrWPS->au8SSID, (uint8)m2m_strlen(pstrWPS->au8SSID),
      					pstrWPS->u8AuthType, pstrWPS->au8PSK, pstrWPS->u8Ch);
      	}
    Case 2: PIN Method
    • To test the WPS PIN method, configure the WPS PIN number and WPS push button feature in main.h as below and use case 2 in the main() function.
      /** WPS PIN number */
      #define MAIN_WPS_PIN_NUMBER              "12345670"
      /** WPS Push Button Feature */
      #define MAIN_WPS_PUSH_BUTTON_FEATURE     false
      /* Device name must be set before enabling WPS mode. */
      m2m_wifi_set_device_name((uint8 *)devName, strlen(devName));
      if (!MAIN_WPS_PUSH_BUTTON_FEATURE) {
          /* case 2 WPS PIN method */
          m2m_wifi_wps(WPS_PIN_TRIGGER, (const char *)MAIN_WPS_PIN_NUMBER);
      }
    • When pressing the SW0 button on the SAMD21, it will trigger WPS in the btn_press() function.
      /* Connect to defined AP. */
      m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), 
                      MAIN_WLAN_AUTH, (void *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL);
    • The wifi_cb() will receive the M2M_WIFI_REQ_WPS message and it can connect to the AP with the given information.
      static void wifi_cb(uint8_t u8MsgType, void *pvMsg)
      {
          case M2M_WIFI_REQ_WPS:
          {
      	tstrM2MWPSInfo *pstrWPS = (tstrM2MWPSInfo *)pvMsg;
      	printf("Wi-Fi request WPS\r\n");
      	printf("SSID : %s, authtyp : %d pw : %s\n", pstrWPS->au8SSID, pstrWPS->u8AuthType, pstrWPS->au8PSK);
      	if (pstrWPS->u8AuthType == 0) {
      	    printf("WPS is not enabled OR Timedout\r\n");
      	    m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
      	    /* WPS is not enabled by firmware OR WPS monitor timeout.*/
      	} else{
      	    printf("Request Wi-Fi connect\r\n");
      	    m2m_wifi_connect((char *)pstrWPS->au8SSID, (uint8)m2m_strlen(pstrWPS->au8SSID),
      					pstrWPS->u8AuthType, pstrWPS->au8PSK, pstrWPS->u8Ch);
      	}
  2. Prepare an AP that supports Wi-Fi Protected Setup (WPS).
  3. Press the WPS button on the AP when using the WPS button method or enter the WPS PIN number in the AP setup menu and start the AP. (For more information, refer to the AP product documentation.)
  4. Run the application. Press the SW0 button on the SAM D21 when using the WPS button method. The ATWINC15x0 will be connected to the AP automatically without security information.
  5. Build the program and download it into the board.
  6. Start the application.