I am launching a new embedded system design using FreeRTOS. My last one used eCos, which has a built-in HTTP server, which is really lightweight, especially since I did not have a file system. In short, it was that every page was a CC-like C function, which was invoked when necessary by the HTTP daemon. In particular, you should write a form function:
int MyWebPage(FILE* resp, const char* page, const char* params, void* uData);
where page was the page part of the URL, params were any form parameters (only GET, not POST is supported, which prevented files from loading and thus caused the flash to crash), uData is the marker that was set when you registered the function, therefore you can use the same function for multiple URLs or ranges with different data, and resp is the file descriptor to which you write the HTTP response (headers and that's it).
Then you registered the function with:
CYG_HTTPD_TABLE_ENTRY(www_myPage, "/", MyWebPage, 0);
where CYG_HTTPD_TABLE_ENTRY is a macro where the first parameter was the name of the variable, the second is the URL of the page (a wildcard character * allowed, so page gets the value MyWebPage() ), thirdly, it is a pointer function, and the last is the value uData .
So a simple example:
int HelloWorldPage(FILE* resp, const char*, const char* params, void*) { fprintf("Content-Type: text/html;\n\n"); fprintf("<html><head><title>Hello World!</title></head>\n"); fprintf("<body>\n"); fprintf("<h1>Hello, World!</h1>\n"); fprintf("<p>You passed in: %s</p>\n", params); fprintf("</body></html>\n"); } CYG_HTTPD_TABLE_ENTRY(www_hello, "/", HelloWorldPage, 0);
(In fact, params will be passed through a function to avoid HTML magic characters, and I would use other pair functions to separate the parameters and make it <ul> , but I left this for clarity.)
The server itself simply started as a task (i.e. a thread) and did not interfere while it had a lower priority than critical tasks.
Needless to say, this turned out to be invaluable for testing and debugging. (One problem with the built-in work is that you cannot throw XTerm at all for use as a log.) Therefore, when the High Programmer reflexively accused me of not working (the path of least resistance, I think), I could pull up web pages and show that he sent me bad parameters. Saved a lot of debugging time in integration.
So, anyway ... I wonder if there is something like that as an independent library? What can I link, register my callbacks, create a thread and allow magic? Or do I need to crank my own? I would prefer C ++, but maybe also can use the C library.
EDIT: Since I put generosity into it, I need to clarify that the library must be under an open source license.