+TCP HTTP CGI / REST

miclam wrote on Thursday, March 23, 2017:

Like Michael here https://sourceforge.net/p/freertos/discussion/382005/thread/72bd7781/ I also need a way to deliver data as dynamically created JSON objects and to embed placeholders in HTML files. uIP had CGI routines for that.

Basically what happend there was, that if a requested file had a specific ending (.shtml), instead of just serving the file as-is, it was scanned for placeholders like %! foo. Content up to the placeholder was send, then the script associated with the placeholder was executed and the return was send, then the rest of the file was processed.

I am planning to implement a similar logic, since it should be easy to call FreeRTOS_send() multiple times.

I am aware of the ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK, which will be usefull to analyse GET parameters to answer requests like /user.json?id=12.

As soon as I have some code I will append it here, but I’m already up for comments and feedback.

heinbali01 wrote on Saturday, April 22, 2017:

Hi Michael, sorry for thinking so long about a proper answer to your post.

When I hear “CGI”, I’ve always thought that you need an OS which can at least run a script or a program. It doesn’t sound like FreeRTOS, which is running tasks, not programs. And ‘scripts’, yes, you can interpret scripts.

I understand the need for flexible HTML code. What we decided, well not “we” but the JS (JQuery) programmers that I work with, is to make extensive use of the statement:

    $('#id').html( <html code> );

That is a different way of creating flexible HTML code.

The actual <html code> is often the result of a JSON request to an HTML server. And this request is indeed handled by the application hook ( with ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK enabled ).

Only requests with a certain characters (usually a '?') will be forwarded to the application. All other requests are about retrieving files.

In some project I’m showing the properties of a sound-limiter, gain, bass, treble, and also the actual (measured) sound pressure. There is a constant polling of these properties and they’re shown in a browser with e.g.:

    $('#id_volume').html(settings.volume);
    $('#id_bass').html(settings.bass);
    $('#id_sound_pressure').html(settings.spl);

The advantage of this approach is more simplicity at the embedded side. It just has to answer simple questions about settings and measurements. And also it gets commands of course, to change the settings.

Browsers are normally running on powerful CPU’s with lots of memory. Let them do more work to unload our small cheap MCU’s :slight_smile:

As soon as I have some code I will append it here,
but I’m already up for comments and feedback.

Please do, post it. Many people are looking for workable solutions. It is not original to say, but there are many ways to Rome.
Regards.

glenenglish wrote on Sunday, April 23, 2017:

Hi Michael
I have a simple web functionality for serving JSON files
the original HTTP server was built from bits I found from Lwip HTTP and Freertos http, and file system
, it also hamdles POST.

\FreeRTOS-Plus\protocols\HTTP
I build the FS for the http server with a linux script into fsdata.c.

It builds and decodes the JSON files on the fly.

jsonproc.c

and also serves a .dat file for other purposes. it serves files from the flash fs (include file) , and if the extension is .json, it goes and builds the json files on the fly from hot data,

I also have libs for programming flash for NVs , and also for configuraing a xilinx fpga

in /web/fs you will find my web page sources . have a look at ipsetup.htm
etc

feel free to contact me direct
-glen

michaelzimmers wrote on Thursday, October 17, 2019:

Hi - I know this thread is fairly old, but it’s newer than anything else I could find regarding REST.

We have a customer who wants a RESTful API on our (FreeRTOS-based) product. Has there been any movement on this in the past couple years?

Thanks…

michaelzimmers wrote on Thursday, October 17, 2019:

Hi - I know this thread is fairly old, but it’s newer than anything else I could find regarding REST.

We have a customer who wants a RESTful API on our (FreeRTOS-based) product. Has there been any movement on this in the past couple years?

Thanks…

michaelzimmers wrote on Thursday, October 17, 2019:

Hi - I know this thread is fairly old, but it’s newer than anything else I could find regarding REST.

We have a customer who wants a RESTful API on our (FreeRTOS-based) product. Has there been any movement on this in the past couple years?

Thanks…