FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [December 2016 Threads]
I would like to build service that would managed and responding by simple JSON object. I've created project based on FreeRTOS, FreeRTOS-Plus-TCP and FreeRTOS-plus-FAT sources. I was able to set up network connection between browser and MCU. But i am wondering how to implement such behaviour, because according to FreeRTOS-Plus-TCP : FreeRTOS_HTTP-Server.c responds with file (web page) on every request. But maybe there is a built-in mechanism to catch every Http request and handle it without modification of FreeRTOS-Plus-TCP sources.
Do you need your new service and the main HTTP server running at the
same time? Perhaps just don't create the HTTP server and have your new
service respond to all requests.
Actually, i need both of them. In some cases it is good to respond by pages, in other (i.e. to make chain of data processing, to handle data from mobile devices it is neccessary to use it like REST (i.e. having some widgets on the screen). in addition there is one more thing: i am configuring useHTTP by config in FreeRTOSIP.config so in this case a ma switching onbuilt in htttp processing. So to exclude i shoul proccess raw TCP or modify existing HTTP Server.
Michael,
Have you had a look at ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK
already?
A user-hook will be called for every GET received:
~~~~
/*
* A GET request is received containing a special character,
* usually a question mark.
* const char *pcURLData; // A request, e.g. "/request?temperature=?"
* char *pcBuffer; // Here the answer can be written
* sizet uxBufferLength; // Size of the buffer
*
*/
int xGetTemperature()
{
static int temp = 23;
return temp++;
}
sizet uxApplicationHTTPHandleRequestHook( const char *pcURLData, char *pcBuffer, sizet uxBufferLength )
{
sizet xResult;
const char pcMyRequest[] = "temperature=?";
pcURLData = strchr( pcURLData, '?' );
if( ( pcURLData != NULL ) && ( strncmp( pcMyRequest, pcURLData + 1, sizeof( pcMyRequest ) - 1 ) == 0 ) )
{
xResult = snprintf( pcBuffer, uxBufferLength, "/request?temperature=%d", xGetTemperature() );
}
else
{
xResult = 0;
}
return xResult;
}
~~~~
In the same way, it is also possible to respond to complex JSON expressions.
As long as the hook returns zero, the url after GET is treated as a filename like here:
~~~~
GET /css/images/ui-iconsffffff256x240.png HTTP/1.1
~~~~
Here is a more complex JSON example:
~~~~
GET /audioset?sample={"startdate":20161128,"enddate":20161128,"starttime":100,"end_time":240000}&records=?
~~~~
The question-mark itself may never be used in an url that indicates a file name. So the hook will first test on the occurrence of a ?
. If present, the request needs special treatment.
I hope this makes sense?
Ping ping, does that answer your question? Will that work for you?
Sorry, that have not answered you, I understood the idea but, unfortunately i was unable to catch the hook. I'll keep my researches and when i receive result i write about it. However according to sniffer i started to receive 404, but i had to sufficiently decrease ipconfigTCPWINSEG_COUNT up to 12 . What do you think is this decreasing could influence on parallel working with web server or on performance.
Hi Michael,
Normally when people develop a new +TCP driver, I get in touch with them directly. If you want, write me at "h point tibosch on freertos point org". Then we'll probably get through this a lot quicker.
The feature ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK
is fairly new, and only available in the latest 160919 release. It is more a sketch rather than a real solution. I would like to get feedback about what solution fits best for most users.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.