Other Parts Discussed in Thread: , CC3200
Hi All,
I am trying to change the IP address from static to dynamic and vice versa in runtime. All the drivers and wifi has been initialized previously and is working fine. Later at some time, I need to switch from dynamic IP to static IP and again from static to dynamic. This is my function which is performing this-
sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO, &dhcpIsOn, &len, (unsigned char *) &ipV4);
///////////////// getting reset here
I am getting reset here. WHy is it so?
Thanks
bool reconnectWifi(char* ipAddr, char* ipMask) //
{
if (strlen(ipAddr) < 7 || strlen(ipMask) < 7)
{
return false;
}
g_lastWiFiSwitchSecs = Seconds_get();
sl_WlanDisconnect();
sl_Stop(800);
g_lastWiFiSwitchSecs = 0;
SlNetCfgIpV4Args_t ipV4;
uint8_t len = sizeof(ipV4);
uint8_t dhcpIsOn;
int result, mode, param, response;
result = sl_Start(NULL, NULL, NULL);
if (strcmp(ipAddr, "dynamic") == 0) // already in station mode amde previosuly in normal wifi usage
{
/* Set auto connect policy */
response = sl_WlanPolicySet(SL_POLICY_CONNECTION,
SL_CONNECTION_POLICY(1, 0, 0, 0, 0), NULL,
0);
if (response < 0)
{
System_abort("Failed to set connection policy to auto");
}
/* Enable DHCP client */
param = 1;
response = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE, 1, 1, ¶m);
if (response < 0)
{
System_abort("Could not enable DHCP client");
}
sl_Stop(1000); //BIOS_WAIT_FOREVER);
// sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO, &dhcpIsOn, &len, (unsigned char *) &ipV4);
}
else
{
//Set static ip adress
char lAddr[50] = { 0 };
strcpy(lAddr, ipAddr);
char* indxSt = lAddr;
char* indx = strchr(indxSt, '.');
indx[0] = 0;
int ip1 = strtol(indxSt, (char **) NULL, 10);
indxSt = indx + 1;
indx = strchr(indxSt, '.');
indx[0] = 0;
int ip2 = strtol(indxSt, (char **) NULL, 10);
indxSt = indx + 1;
indx = strchr(indxSt, '.');
indx[0] = 0;
int ip3 = strtol(indxSt, (char **) NULL, 10);
indxSt = indx + 1;
int ip4 = strtol(indxSt, (char **) NULL, 10);
//Mask
strcpy(lAddr, ipMask);
indxSt = lAddr;
indx = strchr(indxSt, '.');
indx[0] = 0;
int im1 = strtol(indxSt, (char **) NULL, 10);
indxSt = indx + 1;
indx = strchr(indxSt, '.');
indx[0] = 0;
int im2 = strtol(indxSt, (char **) NULL, 10);
indxSt = indx + 1;
indx = strchr(indxSt, '.');
indx[0] = 0;
int im3 = strtol(indxSt, (char **) NULL, 10);
indxSt = indx + 1;
int im4 = strtol(indxSt, (char **) NULL, 10);
ipV4.ipV4 = (_u32) SL_IPV4_VAL(ip1, ip2, ip3, ip4); // _u32 IP address
ipV4.ipV4Mask = (_u32) SL_IPV4_VAL(im1, im2, im3, im4); // _u32 Subnet mask for this STA/P2P
//ipV4.ipV4Gateway = (_u32)SL_IPV4_VAL(192,168,2,1); // _u32 Default gateway address
//ipV4.ipV4DnsServer = (_u32)SL_IPV4_VAL(192,168,2,1); // _u32 DNS server address
//sl_NetCfgGet(SL_IPV4_STA_P2P_CL_STATIC_ENABLE, &dhcpIsOn, &len, (unsigned char *)&ipV4);
long lRetVal = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_STATIC_ENABLE,
IPCONFIG_MODE_ENABLE_IPV4,
sizeof(SlNetCfgIpV4Args_t), (_u8 *) &ipV4);
sl_Stop(200);
sl_Start(NULL, NULL, NULL);
}
unsigned int TimeOutTime =
Clock_getTicks() + WIFI_SCAN_TIMEOUT * ClockTicks_per_ms;
/*
* Wait for SimpleLink to connect to an AP. If connecting to the AP for
* the first time, press Board_BUTTON0 to start SmartConfig.
*/
int count = 0;
while (((g_deviceConnected != true) || (g_ipAcquired != true))
&& g_wifiMaxScan)
{
/*
* This could be done with GPIO interrupts, but for simplicity polling
* is used to check the button.
*/
if (++count % 5000000 == 0)
{
logIntInt("Count(%d):deviceConnected %d", __FUNCTION__, count,
g_deviceConnected);
}
if (Clock_getTicks() > TimeOutTime)
{
break;
}
}
if (g_ipAcquired != true)
{
logg("***ERROR*** - unable to acquire wifi IP - timeout", __FUNCTION__);
buzzerSet(true, 2000, 0xf0f0, false);
return false;
}
sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO, &dhcpIsOn, &len, (unsigned char *) &ipV4); ///////////////// getting reset here
/* Print IP address */
char ipAddrStr[20] = { 0 };
sprintf(ipAddrStr, "%d.%d.%d.%d", SL_IPV4_BYTE(ipV4.ipV4, 3),
SL_IPV4_BYTE(ipV4.ipV4, 2), SL_IPV4_BYTE(ipV4.ipV4, 1),
SL_IPV4_BYTE(ipV4.ipV4, 0));
logStr("reconnect successful - IP address %s", "", ipAddrStr);
return true;
}