![]() |
Morse Micro IoT SDK
2.9.7
|
HTTP server example, with APIs for RESTful interfaces.
This file contains examples on how to use the lwIP http server. It supports static and dynamically generated pages.
Static pages are specified in the fs/ directory, and on compilation will be automatically converted to C arrays which will be embedded into the binary. Currently the file converter is compiled to run only on x86 linux systems. To support other systems, htmlgen can be recompiled on your development machine from the mainline lwIP sources.
Dynamic pages are specified through the custom file system, restfs, and are registered by specifying the URI and handler function in the rest_endpoints array.
Note that only GET requests are supported at this time.
To view the web-page, navigate to
on a computer with a route to the Morse Micro IoT device, over HaLow. Alternatively, you can run
from the AP that the device is connected to.
See Application helper routines for Wireless LAN interface for details of WLAN and IP stack configuration.
Definition in file http.c.
#include <string.h>#include "mmosal.h"#include "mmwlan.h"#include "mmipal.h"#include "lwip/apps/httpd.h"#include "lwip/def.h"#include "lwip/mem.h"#include "lwip/tcpip.h"#include "restfs.h"#include "mm_app_common.h"
Go to the source code of this file.
Functions | |
| static const char * | cgi_set_string (int index, int nparams, char *params[], char *values[]) |
| Example CGI handler to set a global variable based on query parameters. More... | |
| static void | rest_ep_getstring (struct restfs_file *fil) |
| Get the string previously set by set_string. More... | |
| static void | rest_ep_success (struct restfs_file *fil) |
| Example endpoint to return fixed html string. More... | |
| static void | rest_ep_failed (struct restfs_file *fil) |
| Example endpoint to return fixed html string. More... | |
| static void | rest_ep_hello (struct restfs_file *fil) |
| Hello world example endpoint. More... | |
| void | app_init (void) |
| Main entry point to the application. More... | |
Variables | |
| static char | cgi_string [32] = {0} |
| Buffer to store the string set by cgi_set_string() More... | |
| static const struct rest_endpoint | rest_endpoints [] |
| Vector table of rest endpoints. More... | |
| static const tCGI | cgi_endpoints [] |
| Vector table of LWIP CGI endpoints. More... | |
| void app_init | ( | void | ) |
|
static |
Example CGI handler to set a global variable based on query parameters.
Query string expected as value=<string to set>; e.g., /rest/set_string?value=test
| index | The index of the endpoint in the CGI handlers table. |
| nparams | Number of elements in params provided in the URI. |
| params | Parameter names provided in the URI. |
| values | Values corresponding to each parameter given in the URI. |
See lwIP httpd for more information
|
static |
|
static |
|
static |
|
static |
|
static |
Vector table of LWIP CGI endpoints.
Declare the URI and handlers for CGI endpoints here
Will pass query parameters to function call. For example, <ip_address>/rest/<endpoint>?queryname=queryval&queryname2=queryval2 ... etc.
|
static |
Buffer to store the string set by cgi_set_string()
|
static |
Vector table of rest endpoints.
Declare the URI and handlers for REST endpoints here.
For example, HTTP GET on <ip address>/rest/example_endpoint