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.

RTOS/CC3220MODA: Http Client Task

Part Number: CC3220MODA

Tool/software: TI-RTOS

Hi,

I imported the httpget demo's httpTask code for my project and post/get data to my server, and i can post/get http requests successfully. But sometimes, the httpTask blocks the code and wdt reset occurs. I had many tests and debugs about that and the problem seems like when the code started to have a new connection with the server on socket layer, wifi connection can be disconnected so the system gets reset. Maybe checking rssi value can be an answer but i don't want to make my live connection area smaller.

Is there anybody have a solution of a problem like that? And, my sdk release is 2_20_00_10, i checked these libraries for a while in the newer versions and seem any change.

I have a connection control parameter before starting the http connection with the server, I do not try to send anything to the server when the device is not connected.

I use TI-TROS.

Thanks,

Taylan.

  • Hi Taylan,

    If I understand correctly, your device is disconnecting from AP when the HTTP service tries to connect a socket?

    If so, do you know why you lose connection to the AP? Have you checked disconnect code from wlan event handler?

    Jesu
  • Hi Jesu,
    Sorry I could not explain the case correctly. Disconnection is normal, the device is moving and sometimes can go out of the wifi network. I have automatically reconnection alghoritm in the eventhandler, there is no problem about this, too.
    Actually the problem is reset. I don't want to reset the device. If it is connected to the internet(in fact server) it should send the data, if not, get a negative error code(as listed in httpclient.h) but not reset. This process works when the device was disconnected before trying to send http data, and also works when the device was connected. But when the http send process start but disconnect before finishing, it reset, not get an error code and continue.

  • Hello,

    Have you tried to debug where the device is resetting? What function call causes it? Also, when you reconnect you have to wait for the device to get assigned an IP address.

    Jesu
  • Hi Jesu,
    I have tried but couldn't have the same case at all. Because it's a very phisical thing, the wifi connection should be in a very special case. Reconnection and getting a new ip is not a big problem, it can wait but reset is a big problem for me.
  • Hello,

    How do you know it's a physical thing? Are you able to re-produce the reset consistently?

    Also include the httpget.c and platform.c in your next response so I can check your code.

    Jesu
  • Hi Jesu, 

    I mean this is not aall about my device and my code, the case needs a special wifi signal value so i can not have the same easily when i say it is phisical. I will share the codes in a while.

    Thank you.

  • Hi Jesu,

    My codes are attached. 

    Thank you!

    static int16_t http_send(void){
    
        int16_t status;
        int16_t ret = 0;
        int16_t len = 0;
        bool moreDataFlag = false;
        int16_t statusCode;
        uint8_t returnData[1024];
    
    
        HTTPClient_Handle httpClientHandle;
    
        if((http_state==0) || (keepAlive== false) ){
    
    
            status = pthread_mutex_lock(&handle_kill_mutex);
            httpClientHandle = HTTPClient_create(&statusCode,0);
            checkError(statusCode,0, "httpTask: creation of http client handle failed");
            status = pthread_mutex_unlock(&handle_kill_mutex);
    
    
            if(statusCode < 0)
            {
                printError("httpTask: creation of http client handle failed",
                           statusCode);
                return statusCode;
            }
    
    
            status = pthread_mutex_lock(&handle_kill_mutex);
            ret = HTTPClient_connect(httpClientHandle,SERVERADDRESS,0,0);
            resetHttpSendParams(REQUESTURI,"");
            setHeaders(httpClientHandle);
            status = pthread_mutex_unlock(&handle_kill_mutex);
    
    
            if(ret < 0)
            {
                printError("httpTask: connect failed", ret);
                HTTPClient_destroy(httpClientHandle);
                return ret;
            }
        }
    
    
            status = pthread_mutex_lock(&handle_kill_mutex);
            if(setCookieHeader(httpClientHandle) == 1) { 
                setCookieFlag = 1;
            }
            status = pthread_mutex_unlock(&handle_kill_mutex);
    
        UART_PRINT("Sending a request to Server: '%s' Uri: '%s' data:'%s' and type is %s \n",
                   SERVERADDRESS,(const char*)reqUri,(const char*)sendData, sMethod);
    
    
        status = pthread_mutex_lock(&handle_kill_mutex);
        ret = HTTPClient_sendRequest(httpClientHandle,(const char*)sMethod,
                                     (const char*)reqUri,
                                     (const char*)sendData,strlen((char*)sendData), 0);
        status = pthread_mutex_unlock(&handle_kill_mutex);
    
    
        if(ret < 0)
        {
            printError("httpTask: send failed", ret);
            httpClientHandleKill(httpClientHandle);
            return ret;
        }
    
        if(ret < 0)
        {
            printError("httpTask: send failed %d", ret);
            httpClientHandleKill(httpClientHandle);
            return ret;
        }
    
        if(ret >= 403)
        {
            printError("httpTask: cannot get status %d", ret);
            httpClientHandleKill(httpClientHandle);
            return ret;
        }
    
        UART_PRINT("HTTP Response Status Code: %d\n", ret);
    
        len = 0;
    
        status = pthread_mutex_lock(&handle_kill_mutex);
        do
        {
            memset(returnData,0,sizeof(returnData));
    
            ret = HTTPClient_readResponseBody(httpClientHandle, (char*)returnData, 1024,
                                              &moreDataFlag);
            if(ret < 0)
            {
                printError("httpTask: response body processing failed", ret);
            }
    
    
            if(ret > 0) {
                //UART_PRINT( "\n//size inside: %d and ret: %d \n", len,ret);
                memcpy((char*)recvBuffer + len,(char*)returnData,ret);
            }
            len += ret;
    
        }
        while(moreDataFlag);
        status = pthread_mutex_unlock(&handle_kill_mutex);
    
        /* if(moreDataFlag == true) {
            UART_PRINT("could not get all response body! \n");
            return (-1);//TODO SET return Code
        }*/
    
        *recvBufferSize = len;
    
        status = pthread_mutex_lock(&handle_kill_mutex);
        getHeaders(httpClientHandle);
        status = pthread_mutex_unlock(&handle_kill_mutex);
    
    
        UART_PRINT("Received %d bytes of payload\n", len);
    
    
        if(keepAlive == false ){
            UART_PRINT("task Handle closed \n");
            httpClientHandleKill(httpClientHandle);
            return ret;
        }
    
        stopTimer();
        http_state = 1;
        return 0;
    }
    void setStationMode(void)
    {
        int           mode;
        int           response;
    
        mode = sl_Start(0, 0, 0);
        if (mode < 0) {
            /* sl_Start error: Could not initialize SimpleLink Wi-Fi */
            UART_PRINT("sl error for first try \n");
        }
    
        /*
        _u8 *device_name = "threadinmotion-";
        strcat((char*)device_name, (char*)deviceID);
        sl_NetAppSet (SL_NETAPP_DEVICE_ID,SL_NETAPP_DEVICE_URN, strlen(device_name), (_u8 *)
        device_name);*/
    
    
        /* Change network processor to station mode */
        if (mode != ROLE_STA) {
            sl_WlanSetMode(ROLE_STA);
    
            /* Restart network processor */
            sl_Stop(200);
            mode = sl_Start(0, 0, 0);
            if (mode < 0) {
                /* Error: Failed to set SimpleLink Wi-Fi to Station mode */
                UART_PRINT("sl error for STA MODE \n");
            }
        }
    
        sl_WlanDisconnect();
        /* Set auto connect policy */
        response = sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION,
                                    SL_WLAN_CONNECTION_POLICY(1, 1, 0, 1), NULL, 0);
    
        UART_PRINT("wlan policy response: %d \n",response);
        if (response < 0) {
            /* Error: Failed to set connection policy to auto connect */
            UART_PRINT("wlan policy set error \n");
        }
    	intervalInSeconds=10;
    
        response = sl_WlanPolicySet(SL_WLAN_POLICY_SCAN, SL_WLAN_SCAN_POLICY(1,0),
                                    (_u8 *)&intervalInSeconds,sizeof(intervalInSeconds));
        UART_PRINT("Scan policy response: %d \n",response);
    
    
    
        /* Enable DHCP client */
        response = sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE, SL_NETCFG_ADDR_DHCP,
                                0, 0);
    
        if (response < 0) {
            /* Error: Could not enable DHCP client */
            UART_PRINT("net config set error  \n");
        }
    
        sl_Stop(200);
    
        /* Set connection variables to initial values */
        /*    deviceConnected = false;
        ipAcquired = false;*/
    }
    
    
    int32_t wlanConnect(void) {
    
        SlWlanSecParams_t          secParams = {0};
        SlWlanSecParams_t          getSecParams = {0};
        static char         getSsidName[64];
        static _i16                getNameLen = 0;
        static _i16                profileGetStatus = 0;
        static int32_t             status = 0;
        static uint8_t             wlanProfileFlag = 0; //wlan profile deleting check
        static uint8_t              index = 0;
        
    
            ifWifiConnected = 'N';
            secParams.Key = (signed char*)pass;
            secParams.KeyLen = strlen(pass);
            secParams.Type = SL_WLAN_SEC_TYPE_WPA_WPA2;
    
            //status = sl_WlanConnect((signed char*)ssid, strlen(ssid), 0, &secParams, 0);
    
            UART_PRINT("will check profile get info \n ",status,index);
            for(index = 0;index<7;index++) {
    
                profileGetStatus = sl_WlanProfileGet(index,&getSsidName , &getNameLen,
                                           0, &getSecParams, 0, 0);
    
                UART_PRINT("status is %d when index is %d.. \n ",status,index);
    
                if(memcmp(getSsidName,
                          ssid,strlen(ssid)) == 0)//TODO yalnizca ssid kontrolu dogru degil, sifre oku!
                {
    
                    UART_PRINT("SSID INFO IS SAME WITH OLDER, NOTHING DONE.. \n ");
                    UART_PRINT("ssid: %s , nameLen: %d \n",getSsidName,getNameLen);
    
                    if(sl_WlanConnect((signed char*)ssid,
                            strlen(ssid), 0, &secParams, 0) == 0) {
    
                        UART_PRINT("Trying to connect to AP : %s and profileGetStatus: %d \n ",
                                   ssid, profileGetStatus);
    
                    }
                    wlanProfileFlag = 1;
                    break;
                }
    
            }
    
            if(wlanProfileFlag == 0) {
    
                status = sl_WlanProfileDel(SL_WLAN_DEL_ALL_PROFILES);
    
                UART_PRINT("deleting process: %d \n",status);
    
                status= sl_WlanProfileAdd((signed char*)ssid, strlen(ssid),
                                          0,  &secParams, 0, 6, 0);
                UART_PRINT("Saving Process: %d \n",status);
    
                UART_PRINT("Trying to connect to AP : %s and status: %d \n ",
                           ssid, status);
    
            }
    
    
    
        return status;
    
    }
    
    /*
     *  ======== initWiFi =======
     *  Start the NWP and connect to AP
     */
    
    void initWifi() {
    
        int16_t ret = 0;
        setStationMode();
    
        /* Host driver starts the network processor */
        if (sl_Start(NULL, NULL, NULL) < 0) {
            /* Error: Could not initialize WiFi */
            UART_PRINT("sl general start error \n");
        }
    
        if (wlanConnect() < 0) {
            /* Error: Could not connect to WiFi AP */
            UART_PRINT("wlanconnect cant done \n");
        }
    
        /* Start SmartConfig using unsecured method. */
        //ret = sl_WlanProvisioning(SL_WLAN_PROVISIONING_CMD_START_MODE_SC, ROLE_STA, 10,
        //                         NULL, 0);
        //UART_PRINT("return from provisioning: %d \n",ret);
    }
    

  • Hello,

    Do you still get reset if you do not move the device so that it shouldn't disconnect? If you still reset without disconnecting perhaps it's something related to HTTP. I'm trying to help you isolate the problem. All I know is you have a device moving around sending HTTP request that disconnect/reconnects sometimes.

    Jesu
  • Hi Jesu,
    There is no problem in wifi is connected area, and also wifi is disconnected area. In these 2 places, device works without reset. The problem occurs when the device is moving from connection area to disconnection area. The sentence you wrote is true. Its moving around and sending HTTP Requests and disconnect/reconnect sometimes.
  • Hello,

    If you comment out the HTTP functionality do you still get reset?

    Jesu
  • Hi,
    No, The system works when it is not sending http requests.
    Regards.
  • Hi Taylan,

    How are you resetting the WDT interval to prevent system reset? Is the task it's in higher priority than HTTP?

    Jesu
  • Hi Jesu,
    HTTP is in higher priority but this question remind me something! My sl task pritority and http task priority are SAME! I think this can be a big problem because sl_task starts when there is a reconnection and can block http task.
    I will try this firstly.