-
Enable the wireless LAN with SysSetWLANPower function and initialize the wireless LAN with SysWLANInit function.
Sample
SysSetWLANPower(SYS_WLAN_POWER_AUTO); SysWLANInit(NULL);
-
Initialize the HttpRequest library by calling the HTTP_InitHttpRequest function.
Sample
HTTP_InitHttpRequest();
-
Call SysGetWLANConnectStatus function and wait until the wireless LAN is connected.
In the meantime, you need to keep calling the Idle function.
Sample
unsigned int waitStartTick; ... waitStartTick = GetTickCount(); do{ SysGetWLANConnectStatus(&status); if (status == SYS_WLAN_STATUS_CONNECTED) break; Idle(); }while (GetTickCount() - waitStartTick < WLAN_CONNECTION_TIMEOUT); if (status != SYS_WLAN_STATUS_CONNECTED){ // WLAN timeout error ... }
-
Define the content of the HTTP request with the HTTP_CreateRequest function and get the HTTP request handle.
Sample
HTTP_REQUEST_HANDLE hRequest; ... hRequest = HTTP_CreateRequest(SERVER_URL, HTTP_REQ_GET, NULL,0,NULL,15000/20,0); if (!hRequest) { return xxxx_SERVER_CONNECTION_ERROR; }
-
Call the HTTP_GetResponse function to send the HTTP request and wait for the HTTP response to be received.
Sample
int result_code; char responsePhase; unsigned int responseStatus; char *content; unsigned int content_length; char *header; unsigned int headerLength; bool bExit = false; ... while (1) { //Wait for HTTP response if (!HTTP_GetResponse( hRequest, &responsePhase, &responseStatus, &content, &content_length, &header, &headerLength)) { result_code = xxxx_SYSTEM_ERROR; break; } switch(responsePhase) { case HTTP_REQUEST_CONNECTION_ERROR: case HTTP_REQUEST_SYSTEM_ERROR: case HTTP_REQUEST_TIMEOUT: result_code = xxxx_SERVER_CONNECTION_ERROR; bExit = true; break; case HTTP_REQUEST_FINISHED: if (responseStatus != 200) { bExit = true; result_code = xxxx_SERVER_RESPONSE_ERROR; break; } // Got response.... .... result_code = xxxx_SUCCESS; bExit = true; break; } if (bExit) break; Idle(); }
-
Release the HTTP request resources with the HTTP_CloseRequest function.
Sample
HTTP_CloseRequest(hRequest);
-
Release the resources of the HttpRequest library with the HTTP_DeinitHttpRequest function.
Sample
HTTP_DeinitHttpRequest();
-
Disable the wireless LAN with SysSetWLANPower function.
Sample
SysSetWLANPower(SYS_WLAN_POWER_OFF);
See also
Last updated: 2022/04/08