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.

CC3220: Non-blocking http client using noRTOS

Part Number: CC3220

Hi,

I use the code below, using httpclient library. There are semhapore parts inside but i need to toggle it because i do not use rtos in my code. My algorthm is collecting several datas and sending them to server using httpclient, as a post request but at the time of sending data using http, i can not collect data because it blocks my process: for example button cant get trig or led doesn't blink..

I need this code non-blocking version and could not find where i can change it. 

Do i need to use rtos or do i have another way to do it? 

Thanks!

int16_t httpSend(uint8_t* data , uint8_t dataSize) {  

    sendDataRCounter=0;
    memset(sendDataR,0,512);
    memset(sendData,0,255);
    memcpy(sendData,reqUri,reqUriSize);
    //memcpy((sendData+reqUriSize),data,dataSize);
    int16_t cnt;
    for(cnt=0;cnt<255;cnt++){
      if(sendData[cnt]==' '){
          sendDataR[sendDataRCounter++]=0x25;
          sendDataR[sendDataRCounter++]='2';
          sendDataR[sendDataRCounter++]='0';
      }else{
          sendDataR[sendDataRCounter++]=sendData[cnt];
      }
    
    }
   //reqUri = reqUri + *getRssiValue();
   bool moreDataFlag = false;
    int16_t ret = 0;
    int16_t len = 0;
    SlDateTime_t dateTimeSet = {0};
    uint16_t configLen = sizeof(SlDateTime_t);
    uint8_t configOpt = SL_DEVICE_GENERAL_DATE_TIME;
    //sem_wait(&ipEventSyncObj);
   // UART_PRINT("Sending a HTTP GET request to '%s'\n",
     //       HOSTNAME);

    HTTPClient_Handle httpClientHandle;
    HTTPClient_extSecParams httpClientSecParams;
    int16_t statusCode;
    httpClientHandle = HTTPClient_create(&statusCode,0);
    if (statusCode < 0)
    {
        return ret;// UART_PRINT("httpTask: creation of http client handle failed", ret);
    }

    httpClientSecParams.rootCa = "ca.der";
    httpClientSecParams.clientCert = NULL;
    httpClientSecParams.privateKey = NULL;
/*
    dateTimeSet.tm_day = 13;
    dateTimeSet.tm_hour = 1;
    dateTimeSet.tm_min = 17;
    dateTimeSet.tm_mon = 3;
    dateTimeSet.tm_sec = 0;
    dateTimeSet.tm_year = 2018;
*/
    if(pingResult == 1) {
        ret = sl_DeviceSet(SL_DEVICE_GENERAL, configOpt, configLen, (uint8_t *)(&dateTimeSet));
        if(ret < 0)
        {
           return ret; // UART_PRINT("httpTask: failed to set device time", ret);
        }
        
        ret = HTTPClient_connect(httpClientHandle,(char*)serv,&httpClientSecParams,0);
        if (ret < 0) {
           return ret; // UART_PRINT("httpTask: connect failed", ret);
        }
     
        ret = HTTPClient_sendRequest(httpClientHandle,HTTP_METHOD_POST, (const char*)reqUri
                                                              ,"TESTDATA",8,0);
        
        if (ret < 0) {
            return ret;// UART_PRINT("httpTask: send failed", ret);
        }

        if (ret == HTTP_SC_OK) {
          ret=0;
           // UART_PRINT("httpTask: cannot get status", ret);
        }else
          ret=-1;

       

        HTTPClient_disconnect(httpClientHandle);
        if (ret < 0)
        {

        }

        HTTPClient_destroy(httpClientHandle);
    }
    else 
      ret = 0xFF;
    return ret;
}

  • Taylan,

    Currently the library only works in a RTOS enviroment. You would need to port this to no-rtos if you wish to use it as such.

    My suggestion is to use RTOS though, which will speed up your development. Any reason you are trying to not use a RTOS?

    VR
  • Hi Vincent,
    All my other parts of my alghoritm works fine with noRTOS so i think porting all the project to RTOS would be hard.
    On the other hand, i nearly finished the porting job of this library, except non blocking working.
    In this situation we can not assume this library works or this library doesn't work. If i change my question and ask you, for a ported http client library can i use http_sendrequest function non blocking?

  • Hi Taylan,

    You can make the socket that you're sending on non-blocking through the use of the SlNetSock_setOpt() API:

    SlNetSock_Nonblocking_t enableOption;
               enableOption.nonBlockingEnabled = 1;
               SlNetSock_setOpt(SockID, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_NON_BLOCKING, (uint8_t *)&enableOption, sizeof(enableOption));

    You'll probably have to do some more work other than just enabling that socket option though. For one, the way non-blocking sockets work is that if the socket is busy when you attempt to do some non-blocking operation is that you get an EAGAIN-type error instead of blocking and waiting for the socket to become ready. This means you'll have to catch that case and try the socket operation again later on. 

    Give that a try and let me know if you have any other questions or need more help.

    Regards,
    Michael

  • Hi,

    I have ported my project into TIRTOS for this issue and it works, but i will try this in a couple of days to share code example in this post, maybe somebody else needs. 

    Thanks!