This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Changing IP properties in NDK during run-time (in httpServer Example)

MCU: TM4C1294NCPDT

TI-RTOS: v2.01.00.03

NDK: v2.23.01.01

CCS: v6.0.1.0040

Hello,

    In the httpServer example (processors.wiki.ti.com/.../TI-RTOS_HTTP_Example), the IP address of the board is set in the .cfg configuration file as indicated in the below lines:

Ip.autoIp = false;
Ip.address = "192.168.1.2";
Ip.mask = "255.255.255.0";
Ip.gatewayIpAddr = "192.168.1.2";

    But how can I change these properties during run time? In my application, I have to give control to the user who can set these parameters as he wants.

Thanks

Regards

Soumyajit

  • Does this thread help you?

    http://e2e.ti.com/support/embedded/tirtos/f/355/p/221215/778867.aspx#778867

    There are many threads concerning NDK and changing IP address.  Can you do a search and see if any of them help you.  Here's another one:

    http://e2e.ti.com/support/embedded/tirtos/f/355/t/340967.aspx

    Judah

  • Hello Judah,

        Thanks for pointing out the solution, it worked. But I still wonder how to enable & disable DHCP during runtime. Also how to set the IP gateway apart from setting IP Address & Subnet Mask.

        Can you please help me in these issues too?

        

    Thanks

    Regards

    Soumyajit

  • Please see if this post helps you:

    http://e2e.ti.com/support/embedded/tirtos/f/355/t/294840.aspx

    Judah

  • Hi   Soumyajit

            I am now using the TI-RTOS and I encountered the same problem. Will you be able to let me see your the solution of example ?

             

    I'm looking forward to your reply!

    Thanks

  • Hello,

        I have added a function named "functionNetworkOpenHook" to my project; this function is called by the network stack when the network opens/starts.

        Then I have added "Global.networkOpenHook = "&functionNetworkOpenHook";" to my configuration file.

    The details are provided below. I would suggest that you open your config file (.cfg), then add "Global.networkOpenHook = "&functionNetworkOpenHook";" to it. Then you can put the whole function in a .c file as I have provided below. This should ideally work.

    ----------------------------------------------------------------------------------------------------------------------------

    // the following is the content of a .c file

    Void functionNetworkOpenHook(Void)

    {
    CI_IPNET NA;

    HANDLE hCfgIpAddr;

    /* Setup manual IP address */
    bzero(&NA, sizeof(NA));
    NA.IPAddr = inet_addr("192.168.1.2");
    NA.IPMask = inet_addr("255.255.255.0");
    strcpy(NA.Domain, "demo.net");
    NA.NetType = 0;

    /* get the current static IP entry */
    CfgGetEntry(0, CFGTAG_IPNET, 1, 1, &hCfgIpAddr);

    /* remove the current static IP entry */
    CfgRemoveEntry(0, hCfgIpAddr);

    /* add a new static IP entry */
    CfgAddEntry(0, CFGTAG_IPNET, 1, 0,
    sizeof(CI_IPNET), (UINT8 *)&NA, 0);
    }

    ----------------------------------------------------------------------------------------------------------------------------

    // the following is the contents of the .cfg file

    /* ================ Driver configuration ================ */

    var TIRTOS = xdc.useModule('ti.tirtos.TIRTOS');
    var GPIO = xdc.useModule('ti.drivers.GPIO');
    var SDSPI = xdc.useModule('ti.drivers.SDSPI');
    var USBMSCHFatFs = xdc.useModule('ti.drivers.USBMSCHFatFs');
    GPIO.libType = GPIO.LibType_NonInstrumented;
    SDSPI.libType = SDSPI.LibType_NonInstrumented;
    USBMSCHFatFs.libType = USBMSCHFatFs.LibType_NonInstrumented;
    var I2C = xdc.useModule('ti.drivers.I2C');
    I2C.libType = I2C.LibType_NonInstrumented;
    Global.IPv6 = false;
    Ip.autoIp = false;
    Ip.address = "192.168.1.0";
    Ip.mask = "255.255.255.0";
    Ip.gatewayIpAddr = "192.168.1.2";
    var http0Params = new Http.Params();
    var http0 = Http.create(http0Params);
    EMAC.libType = EMAC.LibType_NonInstrumented;
    Global.stackInitHook = "&AddWebFiles";
    Global.stackDeleteHook = "&RemoveWebFiles";
    Global.networkIPAddrHook = null;
    Global.networkOpenHook = "&functionNetworkOpenHook";
    Global.stackBeginHook = null;
    Global.ndkThreadStackSize = 2048;
    Global.pktSizeFrameBuf = 1536;

    ----------------------------------------------------------------------------------------------------------------------------

    ALSO note that these following two files are included in a header file which is included in the c file where the function "functionNetworkOpenHook" is residing.

    #include <ti/ndk/inc/netmain.h>
    #include <ti/ndk/inc/_stack.h>

        Do post whether the solution worked or NOT!!!

    Regards

    Soumyajit

  • Hi  Soumyajit

            I am very pleased to receive your reply.My board suddenly broken. After I fix it, I will immediately verify your answer.I wonder if "Void functionNetworkOpenHook (Void)" In addition to the above functions outside can also create a task or two task? As shown below:

    // the following is the content of a .c file

    Void functionNetworkOpenHook(Void)

    {
    CI_IPNET NA;

    HANDLE hCfgIpAddr;

    /* Setup manual IP address */
    bzero(&NA, sizeof(NA));
    NA.IPAddr = inet_addr("192.168.1.2");
    NA.IPMask = inet_addr("255.255.255.0");
    strcpy(NA.Domain, "demo.net");
    NA.NetType = 0;

    /* get the current static IP entry */
    CfgGetEntry(0, CFGTAG_IPNET, 1, 1, &hCfgIpAddr);

    /* remove the current static IP entry */
    CfgRemoveEntry(0, hCfgIpAddr);

    /* add a new static IP entry */
    CfgAddEntry(0, CFGTAG_IPNET, 1, 0,
    sizeof(CI_IPNET), (UINT8 *)&NA, 0);

    Task_Handle taskHandle;
    Task_Params taskParams;
    Error_Block eb;

    /* Make sure Error_Block is initialized */
    Error_init(&eb);

    /*
    * Create the Task that handles UDP "connections."
    * arg0 will be the port that this task listens to.
    */
    Task_Params_init(&taskParams);
    taskParams.stackSize = 1024;
    taskParams.priority = 1;
    taskParams.arg0 = UDPPORT;
    taskHandle = Task_create((Task_FuncPtr)udpHandler, &taskParams, &eb);
    if (taskHandle == NULL) {
    System_printf("main: Failed to create udpHandler Task\n");
    }


    }

    I look forward to your reply!

    Thanks!

  • Ideally, the task creation inside the said function should work. If it doesn't, you may make use of a flag (or binary semaphore) that will trigger some other function (that is already running) or task to create the new task.

    Regards

    Soumyajit

    If my replies help you in solving your issues, then do mark these posts as answered....

  • After I fix my development board, I have a try.

    If you do not mind whether to leave your contact information? I'm working on and your work is very similar, and hope to have more communication.

  • You can reach me at mail567@yahoo.co.in

    But still I prefer that for technical issues you post in E2E forum so that any other member can benefit out of our discussion(s)...

    You may please provide your contact information too

    Regards

    Soumyajit

  • Ok, I agree with your point of view. You are great.

                                                             Nice to meet you!

  • Hi Soumyajit
    You said“ In my application, I have to give control to the user who can set these parameters as he wants.”I now need to do, but I do not know how to put those arguments to the user? May I ask you give me your routine did do it?

    Regards
    Lewis
  • Hi Soumyajit
    You said " In my application, I have to give control to the user who can set these parameters as he wants."I now need to put those arguments to the user, but I do not know. May I ask you give me your routine done it?

    Regards
    Lewis
  • Hi  Soumyajit

         

            You said " In your  application, You have to give control to the user who can set these parameters as he wants."

            I do not know the manner in which you put the relevant parameters to the user, and allow users to control it. Can you tell me? If you can put your example of success, it would be very nice.

    Regards

    Lewis

     

  • 3326.DL_Tiva_v1_for_ToddM.zipHello Lewis,

       Firstly, sorry for the late reply. I have not completed the entire project as of now & am also not working on the ethernet part currently. The HMI (human machine interface) is also not started yet. So, the user changing the parameters directly is NOT yet implemented but will be done shortly. But to help you out, I have attached the version of my code that contains the ethernet codes.

       To answer your query, the user should be able to enter the ethernet parameters in a string buffer, say, str_IpAddress & str_SubNetMask. You must have some codes written based on some keypad & LCD interfacing (the keypad & LCD applies in my case) which will take input from the user & store the same in some form of non-volatile storage (EEPROM memory of Tiva C MCU in my project). Now, in the attached zip file, open the file ethernet.c file. There you will find the function named functionNetworkOpenHook (code chunk also presented below). Just modify the two lines (back coloured as yellow) by the newly shown code lines (back coloured in orange). Since, I am NOT over with my project, I can't guarantee things would work for sure, but I just shared how I have planned to do things once I start working on the ethernet module. The changes shown below should ideally work. Let me know if any issue pops up.

    -

    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//

    Void functionNetworkOpenHook(Void)
    {
    CI_IPNET NA;

    HANDLE hCfgIpAddr;

    /* Setup manual IP address */
    bzero(&NA, sizeof(NA));
    NA.IPAddr = inet_addr("192.168.1.2");
    NA.IPMask = inet_addr("255.255.255.0");
    strcpy(NA.Domain, "demo.net");
    NA.NetType = 0;

    /* get the current static IP entry */
    CfgGetEntry(0, CFGTAG_IPNET, 1, 1, &hCfgIpAddr);

    /* remove the current static IP entry */
    CfgRemoveEntry(0, hCfgIpAddr);

    /* add a new static IP entry */
    CfgAddEntry(0, CFGTAG_IPNET, 1, 0,
    sizeof(CI_IPNET), (UINT8 *)&NA, 0);
    }

    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//

    ___________________________________________________________________________________

    NA.IPAddr = inet_addr(str_IpAddress);
    NA.IPMask = inet_addr(str_SubNetMask);

    ___________________________________________________________________________________

    -

    Thanks & Regards

    Soumyajit

  • Hi Soumyajit
    I am very happy to receive your reply! Also very grateful to you for helping me, I am willing to try your method. In your project file, I see you use the file system module TI-RTOS system, I have seen the relevant documents, it seems that only when the file system is mounted USB or SD card when you can use it? If I did not mount USB and SD card I can use TI-RTOS directly inside the file system?
    I look forward to your reply!
    Thanks
    Lewis
  • Hi Lewis,
    Its true that the file system FatFs is used in conjunction with SD card & USB Thumb drive but even the ethernet module uses a RAM based embedded file system. Refer this link for your reference http://processors.wiki.ti.com/index.php/TI-RTOS_HTTP_Example. In this link you will find a .ppt file (inside the downloadable zip file). Go through it & you will see that the EFS (Embedded File System) is used even without enabling the FatFs of the TI-RTOS.
    May I know what project you are working on or what you are trying to accomplish, may be then I can help you more or help you specifically for your project.
    -
    Thanks
    Regards
    Soumyajit