Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
/ tinywot-http-simple Public archive

A simple HTTP protocol binding implementation for TinyWoT.

License

Notifications You must be signed in to change notification settings

jyhi/tinywot-http-simple

Repository files navigation

TinyWoT Protocol Binding - Simple HTTP

This is a simple protocol binding implementation for TinyWoT to transform HTTP requests into TinyWoT requests and TinyWoT responses into HTTP responses. Features include:

Installation

Dependencies

  • TinyWoT (build-time)
  • A standard C library (libc)

Use

  1. 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
  1. Upon a network request, invoke tinywot_http_simple_recv with the configuration object and a pointer to TinyWoTRequest. The function will fill the TinyWoTRequest while consuming the HTTP request.
  2. After tinywot_process, invoke tinywot_http_simple_send with the configuration object and a pointer to the TinyWoTResponse returned. The function will emit HTTP response texts according to the TinyWoTResponse.
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.

Configuration

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.

Limitations

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 set linebuf_size to a value larger than 64 (bytes).
    • The same for pathbuf storing the incoming path.

License

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.

About

A simple HTTP protocol binding implementation for TinyWoT.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published