MQX How to change IP address, restart RTCS and/or HTTP

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MQX How to change IP address, restart RTCS and/or HTTP

1,798 Views
chinniwhites
Contributor II

I have a custom K60 board with Ethernet and I am running basically a custom version of httpserv example.  I have a webpage where I have my ip, subnet, and gw settings so user can change ip address - very standard stuff when talking Ethernet device.  In MQX, what is the process needed to get the ip address change to actually take affect.  My first attempt involved destroying the HTTP_TASK and then recreating the task but rtcs gave me an error 1300 probably because i tried to create an rtcs that was already running.

So to change IP address, do I stop HTTP, unbind, rebind, start HTTP server?

Is there a simple way to make an IP change take affect?

0 Kudos
Reply
3 Replies

707 Views
soledad
NXP Employee
NXP Employee

Hello,

Please check the below link and let me know if this helps!!!

How to change the IP address when Http server is running?


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

707 Views
chinniwhites
Contributor II

I am using ipcfg_unbind instead of RTCS_if_unbind since httpserv demo uses ipcfg functions in replacement of RTCS functions everywhere else in program.

After my unbind, I get error 10419 returning for ipcfg_init_device function.

What gives?

void rtcs_init()

{

   IPCFG_IP_ADDRESS_DATA ip_data;

   _enet_address           enet_address;

   uint32_t error;

   if (rtcs_started == 0){

       error = RTCS_create();

       if (error != RTCS_OK)

       {

          printf("\nRTCS failed to initialize, error = %X", error);

          _task_block();

       }

       _IP_forward = TRUE;

   }

   else{

       ipcfg_unbind(ENET_DEVICE);

       printf("Unbinded\n");

   }

#ifdef BSP_ENET_DEVICE_COUNT

#if  (BSP_ENET_DEVICE_COUNT > 0)

   /*Following section is relevant only in case there as some enet driver available in BSP (FEC, MACNET, WIFI or other enet driver)*/

  

   if (strlen(ethIpStr) >= 7){

       ip_data.ip = IPADDR(strtok(ethIpStr,"."),strtok(NULL,"."),strtok(NULL,"."),strtok(NULL,NULL));

       //ip_data.ip = IPADDR(10,1,100,4);

   }

   else{

       ip_data.ip = ENET_IPADDR;

   }

   if (strlen(ethSubnetStr) >= 7){

       ip_data.mask = IPADDR(strtok(ethSubnetStr,"."),strtok(NULL,"."),strtok(NULL,"."),strtok(NULL,NULL));

       //ip_data.mask = IPADDR(255,255,254,0);

   }

   else{

       ip_data.mask = ENET_IPMASK;

   }

   if (strlen(ethGwStr) >= 7){

       ip_data.gateway = IPADDR(strtok(ethGwStr,"."),strtok(NULL,"."),strtok(NULL,"."),strtok(NULL,NULL));

       //ip_data.gateway = IPADDR(10,1,100,1);

   }

   else{

       ip_data.gateway = ENET_GATEWAY;

   }

   //ip_data.ip = ENET_IPADDR;

   //ip_data.mask = ENET_IPMASK;

   //ip_data.gateway = ENET_GATEWAY; 

  

   /* calcualte unique mac address from IP ADDRES */

   ENET_get_mac_address(ENET_DEVICE, ip_data.ip, enet_address);

   error = ipcfg_init_device(ENET_DEVICE, enet_address);

   if (error != RTCS_OK)

   {

      printf("\nFailed to initialize ethernet device, error = %X", error);

      _task_block();

   }

  

#if DEMOCFG_USE_WIFI

    wifi_params_init();

    set_wifi_callback();

    wifi_param_connect(gp_WIFI_Params);

   

    if(!wifi_get_property(gp_WIFI_Params, WIFI_WIFI_CONNECTED))

        return; // Wi-Fi not connected, give up on rest of networking initialization

#endif  //DEMOCFG_USE_WIFI

#if RTCSCFG_ENABLE_LWDNS

   LWDNS_server_ipaddr = ip_data.gateway;  

   ipcfg_add_dns_ip(ENET_DEVICE,LWDNS_server_ipaddr);

#endif /* RTCSCFG_ENABLE_LWDNS */

   printf("\nWaiting for ethernet cable plug in ... ");

   while(!ipcfg_get_link_active(ENET_DEVICE)) {};

   printf("Cable connected\n");

#if RTCS_DHCP

   printf("Contacting DHCP server ... ");

   error = ipcfg_bind_dhcp_wait(ENET_DEVICE, FALSE, &ip_data);

#else

   printf("Setting static IP address ... ");

   error = ipcfg_bind_staticip (ENET_DEVICE, &ip_data);

#endif /* RTCS_DHCP */

   if (error != IPCFG_ERROR_OK)

   {

      printf("\nRTCS failed to bind interface with IPv4, error = %X", error);

      _task_block();

   }

   else

   {

      printf("OK\n");      

   }

   ipcfg_get_ip(ENET_DEVICE, &ip_data);

   printf("\nIP Address      : %d.%d.%d.%d\n",IPBYTES(ip_data.ip));

   printf("\nSubnet Address  : %d.%d.%d.%d\n",IPBYTES(ip_data.mask));

   printf("\nGateway Address : %d.%d.%d.%d\n",IPBYTES(ip_data.gateway));

   printf("\nDNS Address     : %d.%d.%d.%d\n",IPBYTES(ipcfg_get_dns_ip(ENET_DEVICE,0)));

#endif /* BSP_ENET_DEVICE_COUNT > 0 */

#endif /* BSP_ENET_DEVICE_COUNT */  

  

#if RTCS_PPP

    PPP_start();

#endif /* RTCS_PPP */

   /* TODO: start server(s) in separate tasks */

}

0 Kudos
Reply

707 Views
soledad
NXP Employee
NXP Employee

Hello,

Which MQX version are you using?

Could you please check the below threads??

DHCP client

ipcfg_get_link_active not working

Problem in Ethernet Communication


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply