WINC1500 - Proble with STATION Mode

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

 

I am working with WINC1500 (ver.19.4.4) and STMF1 as host MCU.

 

I'm trying to write my software according to Atmel example projects and using drivers from ASF, and I can work in AP mode perfectly and open a socket to communicate without problems.

 

The problem is that I can't connect in STATION mode with the router.
Using the function:

#define MAIN_WLAN_SSID "SABER_SL" /* < Destination SSID */
#define MAIN_WLAN_AUTH M2M_WIFI_SEC_WPA_PSK /* < Security manner */
#define MAIN_WLAN_PSK "Password" /* < Password for Destination SSID */ 

m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID),MAIN_WLAN_AUTH, (void *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL);

static void wifi_cb(uint8_t u8MsgType, void *pvMsg)
{
	switch (u8MsgType) {
	case M2M_WIFI_RESP_SCAN_DONE:
	{
		tstrM2mScanDone *pstrInfo = (tstrM2mScanDone *)pvMsg;
		scan_request_index = 0;
		if (pstrInfo->u8NumofCh >= 1) {
			m2m_wifi_req_scan_result(scan_request_index);
			scan_request_index++;
		} else {
			m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
		}

		break;
	}

	case M2M_WIFI_RESP_SCAN_RESULT:
	{
		tstrM2mWifiscanResult *pstrScanResult = (tstrM2mWifiscanResult *)pvMsg;
		uint16_t demo_ssid_len;
		uint16_t scan_ssid_len = strlen((const char *)pstrScanResult->au8SSID);

		// display founded AP. //
		my_printf("[%d] SSID:%s\r\n", scan_request_index, pstrScanResult->au8SSID);

		num_founded_ap = m2m_wifi_get_num_ap_found();
		if (scan_ssid_len) {
			// check same SSID. //
			demo_ssid_len = strlen((const char *)MAIN_WLAN_SSID);
			if((demo_ssid_len == scan_ssid_len) &&
				(!memcmp(pstrScanResult->au8SSID, (uint8_t *)MAIN_WLAN_SSID, demo_ssid_len)))
			{
				// A scan result matches an entry in the preferred AP List.
				 // Initiate a connection request.

				my_printf("Found %s \r\n", MAIN_WLAN_SSID);
				m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID),MAIN_WLAN_AUTH,
						(void *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL);
				break;
			}
		}

		if (scan_request_index < num_founded_ap) {
			m2m_wifi_req_scan_result(scan_request_index);
			scan_request_index++;
		} else {
			my_printf("can not find AP %s\r\n", MAIN_WLAN_SSID);
			m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
		}

		break;
	}

	case M2M_WIFI_RESP_CON_STATE_CHANGED:
	{
		tstrM2mWifiStateChanged *pstrWifiState = (tstrM2mWifiStateChanged *)pvMsg;
		if (pstrWifiState->u8CurrState == M2M_WIFI_CONNECTED) {
			HAL_GPIO_WritePin(GPIOA,GPIO_PIN_12,GPIO_PIN_RESET);
			m2m_wifi_request_dhcp_client();
		} else if (pstrWifiState->u8CurrState == M2M_WIFI_DISCONNECTED) {
			HAL_GPIO_WritePin(GPIOA,GPIO_PIN_12,GPIO_PIN_SET);
			my_printf("Wi-Fi disconnected\r\n");
			wifi_connected = 0;
			HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,GPIO_PIN_SET);
			/* Reconnect */
			//m2m_wifi_connect((char*)MAIN_WLAN_SSID,strlen((char*)MAIN_WLAN_SSID),MAIN_WLAN_AUTH, MAIN_WLAN_PSK,M2M_WIFI_CH_ALL);

			/* Request scan. */
			m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
			//m2m_wifi_p2p(0);
		}

		break;
	}

	case M2M_WIFI_REQ_DHCP_CONF:
	{
		uint8_t *pu8IPAddress = (uint8_t *)pvMsg;

		my_printf("Wi-Fi connected\r\n");
		my_printf("Wi-Fi IP is %u.%u.%u.%u\r\n",
				pu8IPAddress[0], pu8IPAddress[1], pu8IPAddress[2], pu8IPAddress[3]);
		/* Connected and gotten IP address*/
			wifi_connected = M2M_WIFI_CONNECTED;
		break;
	}
	case M2M_WIFI_RESP_PROVISION_INFO:
	{
		tstrM2MProvisionInfo *provInfo = (tstrM2MProvisionInfo*)pvMsg;
		if(provInfo->u8Status == M2M_SUCCESS)
		{
		// connect to the provisioned AP.
			m2m_wifi_connect((char*)provInfo->au8SSID, strlen(provInfo ->au8SSID),
			provInfo->u8SecType, provInfo->au8Password, M2M_WIFI_CH_ALL);
			my_printf("PROV SSID : %s\n", provInfo->au8SSID);
			my_printf("PROV PSK : %s\n", provInfo->au8Password);
			wifi_connected = false;
		}
		else
		{
			my_printf("(ERR) Provisioning Failed\n");
		}
		break;
	}

	default:
	{
		break;
	}
	}
}

 

and communicating by UART I receive the following messages:

 

 

The truth is that I do not know what may be happening, because all the examples I have seen follow these steps.

 

Thanks

 

Alejandro