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.

Ethernet link down and HTTP Get

Hi,


I am having problem handling an ethernet link down event. I saw this post (https://e2e.ti.com/support/embedded/tirtos/f/355/p/271637/1705132#1705132) but the NC_stop function didn't solve my issue. I


When I disconnect the ethernet link everything is fine, when I plug it back when I try to excute HTTPCli_connect it just fail because of the socket (httpcli.c :  if (isValidSocket(skt)) )


How can I reset the socket ? Note that everytime I make an http get the socket is closed after it's done.

Thank you in advance,


Best Regards,

  • Hi Yannick,
    What version of TI-RTOS are you using, and what platform are you running on?
    Thanks,
    Janet
  • Hi Janet,

    Sorry the lack of informations. I am using TM4C1294XL Connected Launchpad with TI-RTOS 2.14.00.10

    Please feel free to ask if I am missing some informations...

    Best Regards,

  • Hi Yannick,

    I took the TM4C1294XL HTTP Client GET TI-RTOS Network example, and modified the httpTask function to disconnect and reconnect in a loop.  That seemed to work fine.  My modified httpTask looks like the following:

    Void httpTask(UArg arg0, UArg arg1)
    {
        bool moreFlag = false;
        char data[64];        /* buffers response data */
        int ret;
        struct sockaddr_in addr;
        int i;

        HTTPCli_Struct cli;
        HTTPCli_Field fields[3] = {
            { HTTPStd_FIELD_NAME_HOST, HOSTNAME },
            { HTTPStd_FIELD_NAME_USER_AGENT, USER_AGENT },
            { NULL, NULL }
        };

        for (i = 0; i < NLOOPS; i++) {
            addr.sin_family = AF_INET;
            addr.sin_port = htons(PORT);
            inet_pton(AF_INET, IP, &addr.sin_addr);

            HTTPCli_construct(&cli);

            HTTPCli_setRequestFields(&cli, fields);

            ret = HTTPCli_connect(&cli, (struct sockaddr *)&addr, 0, NULL);
            if (ret < 0) {
                printError("httpTask: connect failed", ret);
            }

            ret = HTTPCli_sendRequest(&cli, HTTPStd_GET, REQUEST_URI, false);
            if (ret < 0) {
                printError("httpTask: send failed", ret);
            }

            ret = HTTPCli_getResponseStatus(&cli);
            if (ret != HTTPStd_OK) {
                printError("httpTask: cannot get status", ret);
            }

            ret = HTTPCli_getResponseField(&cli, data, sizeof(data), &moreFlag);
            if (ret != HTTPCli_FIELD_ID_END) {
                printError("httpTask: response field processing failed", ret);
            }

            ret = HTTPCli_readResponseBody(&cli, data, sizeof(data), &moreFlag);
            if (ret < 0) {
                printError("httpTask: response body processing failed", ret);
            }
            else if (moreFlag) {
                printError("httpTask: response body is too big for the buffer", -1);
            }
            data[ret] = '\0';

            System_printf("\nThe current date-time is: %s\n", data);
            System_flush();

            HTTPCli_disconnect(&cli);
            HTTPCli_destruct(&cli);
            Task_sleep(1000);
        }
    }

    Is that the sort of thing you are trying to do?

    Best regards,

        Janet

  • Hello Janet, first of all Happy new year !

    I am trying to use the http get after the physical ethernet link socket has been plugged out and plugged in.

    When I try to make an http get after done this, I have a lot of http connect error (-101) and them the board disconnect itself from the network because of the DHCP, maybe because it is seeing too much errors.

    I thought I managed to get rid of the problem but now it's here again.

    The error 101 refer to "switching protocols" which is what happen when the ethernet link (physical) is disconnected and reconnected. But how can I resolve this to use the http get request again ?


    Thanks for your help,


    Best regards,

    Yannick

  • Hi Yannick,

    Yannick Riou said:
    I am trying to use the http get after the physical ethernet link socket has been plugged out and plugged in.

    Can you please provide some more info on this?  How long are you unplugging the Ethernet cable for?  Are you unplugging it, and then quickly replugging it back in?  Or, leaving it unplugged for a while?

    Yannick Riou said:
    the board disconnect itself from the network because of the DHCP, maybe because it is seeing too much errors.

    What is the output you are seeing here?  Are you seeing a "DHCP fault" message of sorts?

    Steve