For some reasons I cannot use the Profiles (one of them is that I have multiple credentials with the same ssid, and this is not supported by your profiles).
Hence I created my own ones. It's simply an array of ssid and keys (WPA2 only). Then I try to connect with the first one, if it fails or timeouts I try with the next one and so on. Here my connect function:
static _i16 NetworkConnect(int idx) { s_AppContext * const pCtx = &gAppCtx; SlWlanSecParams_t SecParams; _i16 ret; UART_PRINT("[SYS] Connecting using credentials #%d...\r\n", idx); // Cancel an ongoing connection attempt ret = sl_WlanDisconnect(); if (ret < 0) { if (ret != SL_ERROR_WLAN_WIFI_ALREADY_DISCONNECTED) ASSERT_ON_ERROR(ret); }
// Try with the new credentials SecParams.Type = SL_WLAN_SEC_TYPE_WPA_WPA2; SecParams.Key = (_i8 *) _Settings.wifi.key[idx]; SecParams.KeyLen = strlen((char *) SecParams.Key); char *ssid = _Settings.wifi.ssid[idx]; ret = sl_WlanConnect((_i8 *) ssid, strlen(ssid), NULL, &SecParams, NULL); ASSERT_ON_ERROR(ret); pCtx->asyncEvtTimeout = ASYNC_EVT_TIMEOUT; StartAsyncEvtTimer(); return ret; }
There must be something wrong because if during the first call it tries to connect to a non-available AP it timeouts (ok) but also the next ones (which is toward an available AP) timeouts!
Instead if I call the right AP at first it connects correctly.
Is my approach wrong?