Hi All,
I am using BG96 for my application. I am trying to post data on the server by HTTP using ThreadX.
My problem is the HTTP post method works for some time (i.e. send 10-40 pings), After that, it’s not able to connect to HTTP client session to the HTTP server in blocking mode. Every time I am getting an IP address and DNS also active. Module facing problem exactly when I am calling qapi_Net_HTTPc_Connect(http_handle, www.xyz.com,80) function, getting response 3.
As not much documents are available its seems black box to me now.
Please help me put if I am missing anything or I have to clear any memory
int http_post_begin(uint8_t *binary_data, uint16_t bd_index)
{
/* Start HTTPc service */
int status = qapi_Net_HTTPc_Start();
int fail_count = 0;
if (status != QAPI_OK)
{
_log("UNABLE TO START HTTP CLIENT\n\r");
return 1;
}
// qapi_Net_HTTPc_Start();
http_handle = qapi_Net_HTTPc_New_sess(20000, 0, http_post_cb, NULL, 1024, 1024);
if (http_handle == NULL)
{
_log("qapi_Net_HTTPc_New_sess ERROR\n\r");
return -2;
}
// why?
qapi_Net_HTTPc_Pass_Pool_Ptr(http_handle, byte_pool_task);
// http_post_body(host, path);
_log("Trying to Connect\n\r");
while (!http_post_done)
{
_log("HTTP_POST_BEGIN\r\n");
status = qapi_Net_HTTPc_Connect(http_handle, host, HTTP_DEFAULT_PORT);
if (status != QAPI_OK)
{
fail_count = fail_count+1;
_log("qapi_Net_HTTPc_Connect ERROR :%d, Fail Count %d", status, fail_count);
if (fail_count > HTTP_MAX_POST_TRIES)
{
_log("POST Tries Exceeded");
http_session_release();
return 1;
}
// try again
}
else
{
_log("<== CONNECTED ==>\r\n");
while (!http_post_done)
{
qapi_Net_HTTPc_Clear_Header(http_handle);
qapi_Net_HTTPc_Add_Header_Field(http_handle, "Content-Type", "application/octet-stream");
qapi_Net_HTTPc_Set_Body(http_handle, (const char *)binary_data, bd_index);
_log("Path is: %s\n\r", path);
status = qapi_Net_HTTPc_Request(http_handle, QAPI_NET_HTTP_CLIENT_POST_E, path);
if (status == QAPI_OK)
{
_log("qapi_Net_HTTPc_Request to post success\n\r");
int wait_count = 0;
while (1)
{
if (http_post_done != true)
{
_log("waiting..%d\n\r", wait_count);
qapi_Timer_Sleep(1, QAPI_TIMER_UNIT_SEC, true);
wait_count++;
if (wait_count > 60)
{
_log("FAILED AS POSTING TOOK TOO LONG\n\r");
return 1;
}
}
else
{
_log("POST SUCCESS\n\r");
http_session_release();
return 0;
}
}
http_session_release();
return 0;
}
else
{
_log("qapi_Net_HTTPc_Request to post FAILED\n\r");
// fail_count++;
}
// if (fail_count > HTTP_MAX_POST_TRIES)
// {
// _log("POST Tries Failed");
// http_session_release();
// return 1;
// }
qapi_Timer_Sleep(300, QAPI_TIMER_UNIT_MSEC, true);
}
}
qapi_Timer_Sleep(100, QAPI_TIMER_UNIT_MSEC, true);
}
}