User Manual

Adding Pages
All pages served by the HTTP server must be declared at compile time in a specifically formatted list made up of the
following record types:
1. HTTPPageRedirect Records (Page Redirection Entries)
An HTTPPageRedirect entry redirects all requests for the specified resource to another location, and contains a string
with the page to redirect from and the page to redirect to.
2. HTTPPage Records (Standard Pages)
An HTTPPage is composed of the page path + name, the mime type string (so that the browser knows how to render
the resource), and the reference to the resource itself, which can be one of the following:
A Raw String : The text contained in the specified string will be served as the page contents
An HTTPResource (Static File) : The variable name for the binary contents of a file, converted using the
pyresource (https://adafru.it/qoD) tool. This tool takes binary or text files, and converts them to standard C
headers, with the file contents added as an HTTPResource that AdafruitHTTPServer understands. This allows you
to insert static pages, images or other file types, and the mime type will be used to indicate how the resource
should be rendered in the browser.
A Dynamic Callback Handler : The specified callback handler function will be called when this resource is
requested, and you can generate the page contents dynamically in the callback handler
An SPI Flash Filename : The path and filename to retrieve a file from on the on board SPI flash if enabled (files
can be added to SPI flash over USB mass storage when the SPI flash is enabled via the optional solder jumper on
the bottom of the board).
A sample list of a well formatted page list can be seen below, where raw string data ('hello_html'), and dynamic content
('info_html_generator' and 'file_not_found_generator') are both present, as well as a redirection of root ('/') to
'/hello.html':
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),
};
uint8_t pagecount = sizeof(pages)/sizeof(HTTPPage);
// Declare HTTPServer with max number of pages
AdafruitHTTPServer httpserver(pagecount);
© Adafruit Industries https://learn.adafruit.com/introducing-the-adafruit-wiced-feather-wifi Page 101 of 202