User Manual
Converting Static Content (HTTPResources)
It's easy to convert a set of static files to resources that AdafruitHTTPServer can use and embed in the sketch itself. For
details see the dedicated pyresource (https://adafru.it/qoD) tool page.
Implementing Dynamic Page Handlers
Two of the HTTPPage entries in the example above ('/info.html' and '/404.html') show how dynamic pages can be
added to the HTTP server.
The dynamic page function prototypes are declared at the top of the code above, and the functions can then be
implemented following the example below, which is called when a 404 error occurs:
void info_html_generator (const char* url, const char* query, httppage_request_t* http_request);
void file_not_found_generator (const char* url, const char* query, httppage_request_t* http_request);
const char hello_html[] = "<html><body> <h1>Hello World!</h1> </body></html>";
HTTPPage pages[] =
{
HTTPPageRedirect("/", "/hello.html"), // redirect root to hello page
HTTPPage("/hello.html", HTTP_MIME_TEXT_HTML, hello_html),
HTTPPage("/info.html" , HTTP_MIME_TEXT_HTML, info_html_generator),
HTTPPage("/404.html" , HTTP_MIME_TEXT_HTML, file_not_found_generator),
};
# Note that we need to indicate the page count in the constructor!
// Declare HTTPServer with max number of pages
uint8_t pagecount = sizeof(pages)/sizeof(HTTPPage);
AdafruitHTTPServer httpserver(pagecount);
The HTTP Server will always redirect to ´/404.html´ when a 404 error occurs (meaning a user requested a
URL that is not available in the HTTPPage list included at compile time). As such, it is a good idea to always
include this page in your project.
© Adafruit Industries https://learn.adafruit.com/introducing-the-adafruit-wiced-feather-wifi Page 102 of 202










