Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

How to setup service like REST with FreeRTOS Plus TCP

Posted by joporez on December 1, 2016

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.


How to setup service like REST with FreeRTOS Plus TCP

Posted by rtel on December 1, 2016

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.


How to setup service like REST with FreeRTOS Plus TCP

Posted by joporez on December 1, 2016

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.


How to setup service like REST with FreeRTOS Plus TCP

Posted by heinbali01 on December 2, 2016

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?


How to setup service like REST with FreeRTOS Plus TCP

Posted by heinbali01 on December 5, 2016

Ping ping, does that answer your question? Will that work for you?


How to setup service like REST with FreeRTOS Plus TCP

Posted by joporez on December 8, 2016

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.


How to setup service like REST with FreeRTOS Plus TCP

Posted by heinbali01 on December 8, 2016

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.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner