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.

EK-TM4C1294XL: enet_io IP fixed IP address

Part Number: EK-TM4C1294XL

I am running this code example enet_io  on my dev board: EK-TM4C1294XL. I would like to change the code such that I can enter my own IP address on the web browser. Without having to wait for the IP address to be assigned to me. 

I mean, I want to access the web server with a unique IP address that I can use all the time.

Is that possible?

  • Hi,

      Yes it is possible. 

    1)  In 'lwipopts.h' change the two defines below to 0:

    #define LWIP_DHCP    0

    #define LWIP_AUTOIP  0

    2) In your call to LwIPInit, pass the static IP address. Below is an example. 

    lwIPInit(g_ui32SysClock, pui8MACArray,
    (10 << 24) | (219 << 16) | (15 << 8) | 19,
    (255 << 24) | (255 << 16) | (0 << 8) | 0,
    (255 << 24) | (255 << 16) | (0 << 8) | 0,
    IPADDR_USE_STATIC);

    Also see this below post with similar question.

  • Thank you charles for the help! I am ok now with static IP.

    I have another question of you don't mind. I need to parse data coming from UART onto my webpage. could please describe how this can be done. I see from the enet_io example that the webpage can read the status of an LED, but I am still lost on the steps used to make that happen.

    Thank you!

  • HI,

      As described in the example description, there are two methods being used to pass the state of the LED to the server. Below is a snippet of the description.

    “IO Control Demo 1” uses JavaScript running in the web browser to send HTTP requests for particular
    special URLs. These special URLs are intercepted in the file system support layer (io_fs.c)
    and used to control the LED and animation LED. Responses generated by the board are returned
    to the browser and inserted into the page HTML dynamically by more JavaScript code.


    “IO Control Demo 2” uses standard HTML forms to pass parameters to CGI (Common Gateway
    Interface) handlers running on the board. These handlers process the form data and control the
    animation and LED as requested before sending a response page (in this case, the original form)

    back to the browser. The application registers the names and handlers for each of its CGIs with the
    HTTPD server during initialization and the server calls these handlers after parsing URL parameters
    each time one of the CGI URLs is requested.
    Information on the state of the various controls in the second demo is inserted into the served HTML
    using SSI (Server Side Include) tags which are parsed by the HTTPD server in the application. As
    with the CGI handlers, the application registers its list of SSI tags and a handler function with the
    web server during initialization and this handler is called whenever any registered tag is found in a
    .shtml, .ssi, .shtm or .xml file being served to the browser.
    In addition to LED and animation speed control, the second example also allows a line of text to
    be sent to the board for output to the UART. This is included to illustrate the decoding of HTTP text
    strings.

    As an example, you will find the io_cgi.ssi file in the fs folder. Below shows a snippet of the io_cgi.ssi. Here you can see the <!--#LEDtxt--> tag. 

                                        <form method="get" action="iocontrol.cgi" name="iocontrol">
                                            <table align="center" border="0" cellpadding="2" cellspacing="2" width="100%">
                                                <tbody>
                                                    <tr>
                                                        <td align="left" valign="top">
                                                            <b>Control</b>
                                                        </td>
                                                        <td align="center" valign="top">
                                                            <b>Current</b>
                                                        </td>
                                                        <td align="center" valign="top">
                                                            <b>New</b>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="left" valign="top">LED State</td>
                                                        <td align="center" valign="top">
                                                            <!--#LEDtxt-->
                                                        </td>
                                                        <td align="center" valign="top">
                                                            <input name="LEDOn" value="1" type="checkbox">
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="left" valign="top">Animation Speed</td>
                                                        <td align="center" valign="top">
                                                            <!--#speed-->
                                                        </td>
                                                        <td align="center" valign="top">
                                                            <input value="10" maxlength="3" size="4" name="speed_percent">
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td colspan="3" rowspan="1" align="center" valign="middle">
                                                            <input name="Update" value="Update Settings" type="submit">
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </form>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <ul></ul>
                        <br>
                        <table align="center" border="1" cellpadding="2" cellspacing="2" width="80%">
                            <tbody>
                                <tr>
                                    <td align="left" valign="top">
                                        <form method="get" action="settxt.cgi" name="settxt">
                                            <table border="0" cellpadding="2" cellspacing="2" width="100%">
                                                <tbody>
                                                    <tr align="center">
                                                        <td valign="top">
                                                            <b>Display this text over the UART:<br></b>
                                                            <input maxlength="40" size="40" name="DispText">
                                                            <input name="Display" value="Send Text" type="submit">
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </form>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <br>
                    </td>
                </tr>
            </tbody>
        </table>
        </div>
        <div id="footing">
          <hr><hr>
          Copyright &copy; 2013-2016 Texas Instruments Incorporated.  All rights reserved.
        </div>
    </body>
    </html>

    Now if you go to the enet_io.c file you will see how the server program is searching for these tags and handles them. As far as how to create SSI or CGI, it is beyond the scope of this MCU forum. I think you can do some Google searches and there should be a lot for you to get ideas on how they work.  

    //*****************************************************************************
    //
    // This array holds all the strings that are to be recognized as SSI tag
    // names by the HTTPD server. The server will call SSIHandler to request a
    // replacement string whenever the pattern <!--#tagname--> (where tagname
    // appears in the following array) is found in ".ssi", ".shtml" or ".shtm"
    // files that it serves.
    //
    //*****************************************************************************
    static const char *g_pcConfigSSITags[] =
    {
    "LEDtxt", // SSI_INDEX_LEDSTATE
    "FormVars", // SSI_INDEX_FORMVARS
    "speed" // SSI_INDEX_SPEED
    };

    //*****************************************************************************
    //
    // This function is called by the HTTP server whenever it encounters an SSI
    // tag in a web page.  The iIndex parameter provides the index of the tag in
    // the g_pcConfigSSITags array. This function writes the substitution text
    // into the pcInsert array, writing no more than iInsertLen characters.
    //
    //*****************************************************************************
    static int32_t
    SSIHandler(int32_t iIndex, char *pcInsert, int32_t iInsertLen)
    {
        //
        // Which SSI tag have we been passed?
        //
        switch(iIndex)
        {
            case SSI_INDEX_LEDSTATE:
                io_get_ledstate(pcInsert, iInsertLen);
                break;
    
            case SSI_INDEX_FORMVARS:
                usnprintf(pcInsert, iInsertLen,
                        "%sls=%d;\nsp=%d;\n%s",
                        JAVASCRIPT_HEADER,
                        io_is_led_on(),
                        io_get_animation_speed(),
                        JAVASCRIPT_FOOTER);
                break;

  • Thank you Charles for your help!

    I am more interested in using HTTP methods, though.

    I was trying to create another clickable button like the one you have in the demo example. I came across this line of code in the .js file:

    req.open("GET", "/cgi-bin/toggle_led?id" + Math.random(), true);

    I would like to know where is this file located: "/cgi-bin/toggle_led?id"

    In other words I want to know how are you guys naming this files that comes after "GET" in the req.open

    Thank you!

  • Hi,

      With some searches, you can find the reference to toggle_led. Check the io_http.htm file and also the io_fs.c file. I'm not the expert in the enet_io either as it was created long time ago for the TivaWare library. Let us know how it goes so you can share with the community.