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.

CC3200-LAUNCHXL: sl_connect took time when there is no network

Part Number: CC3200-LAUNCHXL
Other Parts Discussed in Thread: ENERGIA, CC3200

Hi

Referring to this thread:-

I was also working on that, everything is working fine. But now i want to reduce the time taken by sl_connect when there is no network. I tried the solution what you suggested in the above thread. I am using non-blocking option for sl_setsockopt(). But still there is no luck.

Here is my piece of changes i made in the code:-

#Define MAX_TIMEOUT 50
   
long nonBlockingValue = 1;   
int timeout = 0;
     
 if (setsockopt(skt, SOL_SOCKET, SL_SO_NONBLOCKING, &nonBlockingValue, sizeof(nonBlockingValue)) < 0) {
                HTTPCli_disconnect(cli);
               return (HTTPCli_ESOCKETFAIL);           
}


    while(1){
        ret = connect(skt, sa, slen);
        if(ret >= 0){
            setCliState(cli, INPROGRESS_FLAG, 0);
            return 0;       //connection established
        }
        if(ret == SL_EALREADY){
            UtilsDelay(10000000);
            if(timeout++ > MAX_TIMEOUT){
                setCliState(cli, INPROGRESS_FLAG, 0);
                return -2;  //connection timeout
            }
        }
        else if(ret < 0){
            setCliState(cli, INPROGRESS_FLAG, 0);
            return -1;      //connection error
        }
    }

  • Hi,

    Can you be more specific what is not working? Are you using CCS or Energia? At the first sight is seems to be that code should be functional. Only one thing I don't like. Usage of delay by the UtilsDelay(). In case RTOS is used, this function should not be used for a longer delays, because It does not switch RTOS context. In CC3200 is here function osi_Sleep().

    Jan

  • Hi Jan,

    Ya, when i use this piece of code my device is not able to connect with server even internet is available.

    I am using CCS with NON-OS configuration, so i have to use utils delay for delay.

  • Hi,

    Please try add calling of _SlNonOsMainLoopTask(); in waiting loop.

    Jan

  • Hi Jan,

    I added that line into the waiting loop, then the connection to the server was successful but it is giving me error while receiving the response from the server.

    Error is : -104 which HTTPCli Receive failed error.

    While if run the firmware in debugging mode with a setting breakpoint, it is getting a proper response.

  • Hi,

    I am sorry, I haven't experience with httpcli library. I am not sure what can cause error HTTPCli_ERECVFAIL.

    Please wait for answer from TI.

    Jan
  • Hi Jan,

    Okay no problem, but there is one more thing i noticed While if run the firmware in debugging mode with a setting breakpoint, it is getting a proper response.
  • Hi,

    It seems to be some kind of "timing" related issue. But I am not sure. Wait for a TI answer.

    Jan
  • Hello,

    This is probably related to how fast the server has data for your recv().

    Looking at the http library code, I can see that if recveive inside bufferedRecv() is blocking and get Ssock_TIMEOUT (-11) -> it is translated to HTTPCli_ERECVFAIL. Actually, in non-blocking mode, getting -11 which is EAGAIN means you need to call the API again since there is no data waiting for you.

    Regards,

    Shlomi

  • Hi Shlomi,

    Yes exactly. 

    But if i see receive inside bufferedRecv() function, there is no option of blocking or non-blocking, how may i know that it is blocking? Also i am not sure how i can implement the calling of API again and how many times i have to call it, because it is giving Ssock_TIMEOUT(-11) and it is not mentioned anywhere that (-11) is related to EAGAIN. 

    Regards

    Shubham

  • Hi Shmoli,

    You are right, i checked in the library and i found EAGAIN is related to (-11) which means try again. But still i am not sure how many times i have to call the API or for which condition i have to call the API again as.. HTTPCli_getResponseStatus gives me -104 error while Ssock_recv() API gives me (-11) error in the httpcli library.
  • Hello,

    Specifically to your question, if you set a socket to non-blocking, there are two options. One is to poll for it and whenever you get EAGAIN, you need to call again. The other is to use select() and test for the incoming flag indicating your request.

    The library itself "converts" the Ssock_TIMEOUT which marks the EAGAIN into HTTPCli_EINPROGRESS in case of a non-blocking socket. Ssock_TIMEOUT converts into HTTPCli_ERECVFAIL in blocking mode with recv timeout.

    Do you have a recv timeout on your socket?

    Regards,

    Shlomi

  • Hi Shlomi,

    Okay , that i can try.

    I can see there is no recv timeout in HTTPCi library. Earlier i was using Blocking option there may be timeout. But as now i am using non-blockking option so there is no timeout related to recv

    Regards
    Shubham
  • Hello,

    I looked a little bit more on the code and accidently I referred to the implementation under __SLP__.

    Since we work with __SL__, we need to refer to the "else" part.

    So what happens with the non-blocking is that the first call to Ssock_recv() would return with Ssock_TIMEOUT. If the 2nd call also returns with Ssock_TIMEOUT, it is converted to HTTPCli_ERECVFAIL.

    The good news is that this is the only place a HTTPCli_ERECVFAIL is returned so you can be sure that getting this event under non-blocking mode means a Ssock_TIMEOUT, i.e. need to refer it as EAGAIN.

    Regards,

    Shlomi

  • Hi Shlomi

    Oh okay.

    Yes that it is confirm that i am getting yhe error related to Ssock_TIMEOUT which means EAGAIN. I put the recv() api in the polling

    While(numRead == EAGAIN){

    numRead = recv();

    }

    This is working when there is network.

    Now i have to test it when there is no network..it should not be block for more than 5 secs.

    Regards

    Shubham