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.

httpget example questions (TM4C1294 - TIRTOS)

Hello,

I'm trying to learn and I can't understand this one part of the HTTPGET example.

This is specific to the "httpget_EK_TM4C1294XL_TI_TivaTM4C1294NCPDT" example.

tirtos version: tirtos_tivac_2_14_04_31

Question:

  • Why doesn't the HTTPGET example restart when I unplug the ethernet connection and plug it into a new domain?
    • I expect the IP address should change and that should call the netIPAddrHook function?

Thanks for the help! I apologize if the answer is easy or already answered (I did due diligence of searching related questions and the docs).

  • Hello,

    The HTTP Client GET TI-RTOS example does not take care of checking for the availability of network. It assumes the network is available for HTTP communication. When the ethernet cable is unplugged, the connection to the HTTP server is lost and I believe a socket error occurs. It is the application's responsibility to handle socket errors and reconnect when network is available. But we wanted to just demonstrate the HTTP Client usage and keep the example simple. Hence we did not add any network error checking functionality.

    Hope this helps,
    Vikram
  • Thanks for the reply Vikram!

    I think that there are no socket errors because if the HTTP GET example completes, it will not run again. Of course if the HTTP GET was started but didn't complete and the ethernet was lost then, I assume a socket error would happen in that condition.

    After reading more documentation, I see that I can use "NC_setLinkHook", "NC_NetStop(1)" and the other NETCTRL functions to accomplish what I want. Is that the recommended way to ensure that the device restarts it's DHCP service so that a new IP address can be acquired?

    If that is the recommended method to re-acquire an IP address and detect link status changes, you can mark this as answered.

    Regards,

    Subhash 

  • The netIPAddrHook function will be called every time a IP address is added or removed. The argument "fAdd" will be 0 if IP is removed else IP is added. And yes, NETCTRL functions provides greater control of the underlying network layer. Please refer to the NDK User's Guide and Reference Guide for more details.

    If your questions are answered, please mark it as answered (I don't have the permission to mark this question answered).

    Vikram
  • Hi Vikram,

    I'm sorry but you still haven't answered my question. Or I am not understanding you.

    It really comes down to this:
    Should I expect netIPAddrHook to be called when I unplug and re-plug the physical Ethernet connection?
    Assuming the answer is no, is the recommended practice of Ethernet link detection to use the NETCTRL functions?

    I have read the NDK user guide and reference guide. I keep going back to them and the examples that I can find. I can't find the answers to these questions though.

    Thank you,
    Subhash
  • S D said:
    Should I expect netIPAddrHook to be called when I unplug and re-plug the physical Ethernet connection?

    No, the netIPAddrHook is not called when the link is up or down. This is called when an IP is added or removed. I was answering to your earlier question:

    S D said:
     expect the IP address should change and that should call the netIPAddrHook function?

    S D said:
    Assuming the answer is no, is the recommended practice of Ethernet link detection to use the NETCTRL functions?

    I have read the NDK user guide and reference guide. I keep going back to them and the examples that I can find. I can't find the answers to these questions though.

    Please refer to the NDK User Guide Section 4.2.4 - you can use LINKUP/LINKDOWN signalling. When configured, the NDK stack will call a user defined callback function and pass an argument informing the callback if the link went up or down. You can use this signalling to disable DHCP when link is down and re-enable when the link is up. This functionality for TivaC devices is supported in TI-RTOS 2.16.00.08 release.

    Here is an example for DHCP disable/enable (Note: this is an old code just for reference):

    //
    // DHCP_reset()
    //
    // Code to reset DHCP client by removing it from the active config,
    // and then reinstalling it.
    //
    // Called with:
    // IfIdx    set to the interface (1-n) that is using DHCP.
    // fOwnTask set when called on a new task thread (via TaskCreate()).
    //
    void DHCP_reset( uint IfIdx, uint fOwnTask )
    {
        CI_SERVICE_DHCPC dhcpc;
        HANDLE h;
        int    rc,tmp;
        uint   idx;
    
        // If we were called from a newly created task thread, allow
        // the entity that created us to complete
        if( fOwnTask )
            TaskSleep(500);
    
        // Find DHCP on the supplied interface
        for(idx=1; ; idx++)
        {
            // Find a DHCP entry
            rc = CfgGetEntry( 0, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT,
                              idx, &h );
            if( rc != 1 )
                goto RESET_EXIT;
    
            // Get DHCP entry data
            tmp = sizeof(dhcpc);
            rc = CfgEntryGetData( h, &tmp, (UINT8 *)&dhcpc );
    
            // If not the right entry, continue
            if( (rc<=0) || dhcpc.cisargs.IfIdx != IfIdx )
            {
                CfgEntryDeRef(h);
                h = 0;
                continue;
           }
    
            // This is the entry we want!
    
            // Remove the current DHCP service
            CfgRemoveEntry( 0, h );
    
            // Specify DHCP Service on specified IF
            bzero( &dhcpc, sizeof(dhcpc) );
            dhcpc.cisargs.Mode   = CIS_FLG_IFIDXVALID;
            dhcpc.cisargs.IfIdx  = IfIdx;
            dhcpc.cisargs.pCbSrv = &ServiceReport;
            CfgAddEntry( 0, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT, 0,
                         sizeof(dhcpc), (UINT8 *)&dhcpc, 0 );
            break;
        }
    
    RESET_EXIT:
        // If we are a function, return, otherwise, call TaskExit()
        if( fOwnTask )
            TaskExit();
    }
    

    Hope this answers your questions better.

    Vikram

  • Thank you very much for the help! I appreciate you taking the time to explain it and for providing an example.

    Regards,
    Subhash