This is a simple protocol binding implementation for TinyWoT to transform HTTP requests into TinyWoT requests and TinyWoT responses into HTTP responses. Features include:
- PlatformIO:
pio lib install tinywot-http-simple
- TinyWoT (build-time)
- A standard C library (libc)
- Prepare a configuration object (
TinyWoTHTTPSimpleConfig
). This include:
- a read line handler (
readln
) - a write handler (
write
) - a buffer "scratchpad" (
linebuf
) and its size (linebuf_size
) - a buffer storing the path (
pathbuf
) and its size (pathbuf_size
) - an optional context pointer (
ctx
) for the use of read / write handlers; for example, a socket
- Upon a network request, invoke
tinywot_http_simple_recv
with the configuration object and a pointer toTinyWoTRequest
. The function will fill theTinyWoTRequest
while consuming the HTTP request. - After
tinywot_process
, invoketinywot_http_simple_send
with the configuration object and a pointer to theTinyWoTResponse
returned. The function will emit HTTP response texts according to theTinyWoTResponse
.
if (!tinywot_http_simple_recv(&cfg, &req)) {
// error handling
}
resp = tinywot_process(&thing, &req);
if (!tinywot_http_simple_send(&cfg, &resp)) {
// error handling
}
A sample Thing implemented using this library based on Arduino with Ethernet connectivity can be found in example/arduino-led.
A few macros can be defined in the build system to tweak this library:
TINYWOT_HTTP_SIMPLE_USE_PROGMEM
: use AVR program space (flash memory) to store the HTTP strings. Toggling this helps saving around 40% of RAM that is purely used to store static HTTP strings.TINYWOT_HTTP_SIMPLE_USE_REASON_PHRASE
: append optional HTTP reason phrases in the response line of responses.
For example, in PlatformIO, insert build_flags
in [env]
blocks:
build_flags =
-DTINYWOT_HTTP_SIMPLE_USE_PROGMEM
-DTINYWOT_HTTP_SIMPLE_USE_REASON_PHRASE
For TinyWoT configuration options, see its documentation.
As a "simple" implementation, it just works and doesn't cover too many use cases.
- This library parses HTTP line-by-line, so the size of buffer (
linebuf
, as the name suggests) essentially limits the maximum possible length of a HTTP request. If a HTTP request has a line longer than the size of buffer, the receiving or the sending process will fail. It's recommended to setlinebuf_size
to a value larger than 64 (bytes).- The same for
pathbuf
storing the incoming path.
- The same for
This project is REUSE 3.0 compliant: every file is carried with its own copyright and licensing information in the comment headers or the corresponding .license
files. In general:
- Source files are licensed under the MIT license.
- Various data files are (un)licensed under the CC0 license.
See the LICENSES directory for copies of licenses used across this project. The LICENSE file also contains a MIT license for non-REUSE practices.