Hi
my program cann't connect AP when I use profile and auto policy .but it can connect AP when try use ccs step by step debug. what's problem? code is as following, the problem is when i call WlanConnectAsPolicy(), program is trap in while loop, that means no wanlan event occur. but when i try debug it step by step, Wlan event occurred and program passed.
static long WlanConnectAsPolicy()
{
long lRetVal = -1;
// Set connection policy to Auto
// (Device's default connection policy)
lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,
SL_CONNECTION_POLICY(1, 0, 0, 0, 0), NULL, 0);
ASSERT_ON_ERROR(lRetVal);
// Wait for WLAN Event
while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
{
// Toggle LEDs to Indicate Connection Progress
GPIO_IF_LedOff(MCU_IP_ALLOC_IND);
MAP_UtilsDelay(800000);
GPIO_IF_LedOn(MCU_IP_ALLOC_IND);
MAP_UtilsDelay(800000);
}
return SUCCESS;
}
int main(void)
{
long lRetVal = -1;
//
// Initialize Board configurations
//
BoardInit();
//
// Configure the pinmux settings for the peripherals exercised
//
PinMuxConfig();
#ifndef NOTERM
InitTerm();
#endif
//
// Display banner
//
DisplayBanner(APPLICATION_NAME);
// Configure all 3 LEDs
//
GPIO_IF_LedConfigure(LED1|LED2|LED3);
// switch off all LEDs
GPIO_IF_LedOff(MCU_ALL_LED_IND);
// configure RED LED
//GPIO_IF_LedOff(MCU_RED_LED_GPIO);
InitializeAppVariables();
//
// Following function configure the device to default state by cleaning
// the persistent settings stored in NVMEM (viz. connection profiles &
// policies, power policy etc)
//
// Applications may choose to skip this step if the developer is sure
// that the device is in its default state at start of applicaton
//
// Note that all profiles and persistent settings that were done on the
// device will be lost
//
lRetVal = ConfigureSimpleLinkToDefaultState();
if(lRetVal < 0)
{
if (DEVICE_NOT_IN_STATION_MODE == lRetVal)
UART_PRINT("Failed to configure the device in its "
"default state \n\r");
LOOP_FOREVER();
}
UART_PRINT("Device is configured in default state \n\r");
CLR_STATUS_BIT_ALL(g_ulStatus);
//Start simplelink
lRetVal = sl_Start(0,0,0);
if (lRetVal < 0 || ROLE_STA != lRetVal)
{
UART_PRINT("Failed to start the device \n\r");
LOOP_FOREVER();
}
UART_PRINT("Device started as STATION \n\r");
// =========================================================
// Added
// Connecting to WLAN AP
_i8 ProfileSSID[33];
_i16 len;
_u8 ProfileMacAddr[7];
_u32 Priority;
SlSecParams_t secParams;
SlGetSecParamsExt_t SecExtParams;
lRetVal = sl_WlanProfileGet(0,ProfileSSID,&len,ProfileMacAddr,&secParams,&SecExtParams,&Priority);
if (lRetVal>0)
{
ProfileSSID[len]=0;
UART_PRINT("Use Profile connection %s \n\r",ProfileSSID);
lRetVal = WlanConnectAsPolicy();
if(lRetVal < 0)
{
UART_PRINT("Failed to establish connection w/ an AP \n\r");
LOOP_FOREVER();
}
UART_PRINT("Connection established w/ AP and IP is aquired \n\r");
UART_PRINT("Pinging...! \n\r");
//
// Checking the Lan connection by pinging to AP gateway
//
lRetVal = CheckLanConnection();
if(lRetVal < 0)
{
UART_PRINT("Device couldn't ping the gateway \n\r");
LOOP_FOREVER();
}
// Turn on GREEN LED when device gets PING response from AP
GPIO_IF_LedOn(MCU_EXECUTE_SUCCESS_IND);
// Checking the internet connection by pinging to external host
//
lRetVal = CheckInternetConnection();
if(lRetVal < 0)
{
UART_PRINT("Device couldn't ping the external host \n\r");
LOOP_FOREVER();
}
// Turn on ORAGE LED when device gets PING response from AP
GPIO_IF_LedOn(MCU_ORANGE_LED_GPIO);
UART_PRINT("Device pinged both the gateway and the external host \n\r");
UART_PRINT("WLAN STATION example executed successfully \n\r");
//================ End Add
// Connect to our AP using SmartConfig method
}
else
{
UART_PRINT("Profile empty,start provision \n\r");
lRetVal = startProvisioning();
if(lRetVal < 0)
{
ERR_PRINT(lRetVal);
}
else
{
UART_PRINT("Provisioning Succedded \n\r");
}
}
LOOP_FOREVER();
}