Basic HTTP Server example

HTTP Server with custom URLs and actions

API Features Demonstrated


This app works on:

Requirements and Prerequisites

Requires a Gecko OS evaluation board, such as a WGM160P_eval.


The initialization file settings.ini is packaged into the app file downloaded to the device.


The http_server app demonstrates how to create custom URLs.

Usage Instructions

Open a Gecko OS serial terminal to the device. See Getting Started, Opening a Gecko OS Terminal.

This app assumes your Gecko OS device is set up with the credentials to join your local network. If you have not already set up network credentials, on the Gecko OS terminal, run the commands:

network_up -s

See the Wi-Fi Command API documentation for network_up and save.

After creating and running the app, connect a PC or mobile device to the same network as the Gecko OS device and open a browser to the device IPv4 address.

When the HTTP server receives a request for one of the registered custom URLs, the associated callback function executes. Note that HTTP callbacks execute in the HTTP server context, not in the Gecko OS app thread context.

When the app runs, the Gecko OS terminal output is:

> Success
HTTP Server example starting...
HTTP Server running...
Available custom URLs:
 0: http://http_server.local/toggle_light
 1: http://http_server.local/set_light/%s
 2: http://http_server.local/get_params
 3: http://http_server.local/json_parser
 4: http://http_server.local/json_generator
Network down
Network up

If you are viewing this documentation with a browser connected to the same network as the Gecko OS device, you can click on the links below to verify the behavior of the app:

Link RequestBehaviour
http://http_server.local/toggle_light GET Toggle User LED 1
http://http_server.local/set_light/1 GET Turn User LED 1 on
http://http_server.local/set_light/0 GET Turn User LED 1 off
http://http_server.local/get_params?msg=Hello&light=on&retval=returnToSender GET Logs msg on terminal
Sets User LED 1 to value specified
Displays retval and LED val in return HTML
Try using the '' script to send a sample POST request.
POST Logs msg parameter to Gecko OS terminal.
Returns HTML formatted LED value and Retval
http://http_server.local/json_generator GET Display response with json formatted with GPIO values


The macros:

set up a table of custom URLs assigned to callback functions. Each of the callback functions is defined in a separate .c file. The custom URL function declarations are shared in the file common.h.

See Gecko OS API documentation, HTTP Server Macros.



get_params_request_processor (see get_params.c)

This handles a standard GET request with URL parameters



See also: