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.
Have you had a look at
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
static int temp = 23;
sizet uxApplicationHTTPHandleRequestHook( const char *pcURLData, char *pcBuffer, sizet uxBufferLength )
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() );
xResult = 0;
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:
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.
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.
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.