Hi,
We are using the CC3135MOD module with STM32 with FreeRTOS. The module is interfaced through SPI. My application runs as an HTTPS Client and transmits data frequently, say every 10 seconds. I would like to know the ideal way to handle errors.
My pseudo code:
httpTask() { static int16_t retClientConnectStatus{-1}; static int16_t retClientSetHeaderStatus{-1}; static int16_t retClientSendStatus{-1}; static int16_t retClientCreateStatus{-1}; static int16_t retClientDestroyStatus{-1}; HTTPClient_extSecParams esParams; char hostIpAddr[NO_23U_NUMERIC]; std::array<char, NO_62U_NUMERIC> requestURI; requestURI.fill('\0'); if(retClientCreateStatus != 0) { HttpClient::httpClientHandle = HttpClient::CreateHttpClient(0, &retClientCreateStatus); } if(retClientCreateStatus >= 0) { if((retClientConnectStatus < 0)) { esParams.clientCert = nullptr; esParams.privateKey = nullptr; esParams.rootCa = ROOT_CA_CERT; retClientSetHeaderStatus = HttpClient::SetHeaderHttpClient( HttpClient::httpClientHandle, HTTPClient_HFIELD_REQ_USER_AGENT, USER_AGENT, strlen(USER_AGENT) + 1U, HTTPClient_HFIELD_PERSISTENT); retClientSetHeaderStatus = HttpClient::SetHeaderHttpClient( HttpClient::httpClientHandle, HTTPClient_HFIELD_REQ_CONNECTION, CONNECTION_KEEP_ALIVE, strlen(CONNECTION_KEEP_ALIVE) + 1U, HTTPClient_HFIELD_PERSISTENT); retClientSetHeaderStatus = HttpClient::SetHeaderHttpClient( HttpClient::httpClientHandle, HTTPClient_HFIELD_REQ_CONTENT_TYPE, CONTENT_TYPE, strlen(CONTENT_TYPE) + 1U, HTTPClient_HFIELD_PERSISTENT); static_cast<void>(memset(hostIpAddr, '\0', sizeof(hostIpAddr))); static_cast<void>(strcpy(hostIpAddr, HOSTNAME)); retClientConnectStatus = HttpClient::ConnectHttpClient(HttpClient::httpClientHandle, (hostIpAddr), &esParams, 0); static_cast<void>(memset(hostIpAddr, '\0', sizeof(hostIpAddr))); } if(retClientConnectStatus == 0) { switch(msgType) { case wifiDataType::Msg_1: std::copy_n(REQUEST_URI_Msg_1, strlenRequestURIMsg1, requestURI.begin()); break; case wifiDataType::Msg_2: std::copy_n(REQUEST_URI_Msg_2, strlenRequestURIMsg2, requestURI.begin()); break; case wifiDataType::Msg_3 std::copy_n(REQUEST_URI_Msg_3, strlenRequestURIMsg3, requestURI.begin()); break; default: break; } std::copy_n(devName, FindMessageSize(devName), requestURI.begin() + FindMessageSize(&requestURI[0])); retClientSendStatus = HttpClient::SendHttpRequest( HttpClient::httpClientHandle, HTTP_METHOD_POST, &requestURI[0], reinterpret_cast<const char*>(msgToSend), (strlen(msgToSend) + 1U), 0); } if((retClientSendStatus < 0) && ((retClientSendStatus != SL_RET_CODE_INVALID_INPUT) && (retClientSendStatus != SLNETERR_ESEC_HAND_SHAKE_TIMED_OUT)) && (retClientSendStatus != HTTPClient_ERESPONSEINVALID) ) { retClientDestroyStatus = HttpClient::DestroyHttpClient(HttpClient::httpClientHandle); static_cast<void>(memset(hostIpAddr, '\0', sizeof(hostIpAddr))); retClientCreateStatus = -1; retClientConnectStatus = -1; } }
httpTask gets called every 10 seconds.
My questions are:
1. Is the pseudo code correct?
2. What errors in HTTPClient_sendRequest or HTTPClient_connect should lead to HTTPClient_destroy and subsequent HTTPClient_create ?
I saw the HTTPSGET example in the SDK, where the client is destroyed after every send operation. I would not want to do that unless there is an error since I do not want the latency of the HTTP handshake every time I send.
Please advise.
Thanks,
SN