SWRU368C May 2018 – January 2021 CC3100 , CC3100MOD , CC3200 , CC3200MOD
When the HTTP server locates user tokens in the HTML files, the server generates get_token_value (for GET tokens) or post_token_value (for post tokens) events to the host for the user to correctly handle them.
When the host gets a get_token_value event with a specific token name, the server returns the token value for this token name by using the send_token_value command.
If the host does not have any token value to return, the server uses zero as the length of the token value.
When the user gets a post_token_value event with the token name and value, the user must save this new token value.
In the SimpleLink driver, when one of the preceeding events is generated the driver calls a predefined callback called SimpleLinkHttpServerCallback();
The callback is defined as follows:
void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpServerEvent, SlHttpServerResponse_t *pHttpServerResponse)
Where serverEvent and serverResponse are defined as follows:
typedef struct
{
unsigned long Event;
SlHttpServerEventData_u EventData;
}SlHttpServerEvent_t;
typedef struct
{
unsigned long Response;
SlHttpServerResponsedata_u ResponseData;
}SlHttpServerResponse_t;
typedef union
{
slHttpServerString_t httpTokenName; /* SL_NETAPP_HTTPGETTOKENVALUE */
slHttpServerPostData_t httpPostData; /* SL_NETAPP_HTTPPOSTTOKENVALUE */
} SlHttpServerEventData_u;
typedef union
{
slHttpServerString_t token_value; /* < 64 bytes*/
} SlHttpServerResponsedata_u;
typedef struct _slHttpServerString_t
{
UINT8 len;
UINT8 *data;
} slHttpServerString_t;
typedef struct _slHttpServerPostData_t
{
slHttpServerString_t action;
slHttpServerString_t token_name;
slHttpServerString_t token_value;
}slHttpServerPostData_t;
The following is user callback sample code:
/*HTTP Server Callback example */
void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpServerEvent,
SlHttpServerResponse_t *pHttpServerResponse)
{
switch (pHttpServerEvent->Event)
{
/* Handle Get token value */
case SL_NETAPP_HTTPGETTOKENVALUE:
{
char * tokenValue;
tokenValue = GetTokenValue (pHttpServerEvent >EventData.httpTokenName);
/* Response using driver memory - Copy the token value to the Event response
Important - Token value len should be < MAX_TOKEN_VALUE_LEN (64 bytes) */
strcpy (pHttpServerResponse->ResponseData.token_value.data, tokenValue);
pHttpServerResponse->ResponseData.token_value.len = strlen (tokenValue);
}
break;
/* Handle Post token */
case SL_NETAPP_HTTPPOSTTOKENVALUE:
{
HandleTokenPost (pHttpServerEvent->EventData.httpPostData.action,
pHttpServerEvent->EventData.httpPostData.token_name,
pHttpServerEvent->EventData.httpPostData.token_value);
}
break;
default:
break;
}
}
For the HTTP callback to work the following line should be uncommented in user.h:
#define sl_HttpServerCallback SimpleLinkHttpServerCallback