This library provides a single interface that can be used to handle HTTP requests made directly to the controller or forwarded to the controller via a websocket.
- https://github.com/Links2004/arduinoWebSockets (With PlatformIO it will automatically install this).
The easiest way to use the library is to place it in your Arduino libraries directory, which is automatically included by the Arduino IDE and can manually be included by any other project that doesn't use the IDE.
First use the Arduino IDE to install the WebSockets library v2.7.2 or later by Markus Sattler.
Then, copy this library into the libraries directory of your sketchbook location (which can be viewed from the Arduino IDE preferences).
Local HTTP request bodies require a valid Content-Length and must arrive completely within the request timeout. The default maximum body size is 8192 bytes. Resource-constrained applications can override it at compile time, for example with -DOTF_MAX_BODY_SIZE=2048.
- Local requests retain complete
If-None-Matchheaders, allowing applications to implement conditional GET responses on the LAN as well as through OTC. - Local headers are read as physical lines. Overlong headers are discarded in full, so their remaining bytes cannot be interpreted as another header. Incomplete or slow request headers receive HTTP 408 under one request deadline, including when input keeps arriving. Overlong request lines receive HTTP 414 after the headers have been consumed. The request-line limit follows the constructor's supplied buffer size, not a fixed 1 KiB limit: for a buffer of N bytes it accepts N-11 bytes before the newline, including the carriage return (10 reserved bytes and one NUL terminator). The default 1024-byte buffer therefore accepts 1013 bytes; 2/4/8 KiB buffers accept 2037/4085/8181. This is the whole request line, not just the URL. Kept headers must also fit the shared request buffer. The strict total header deadline is 1.5 seconds with the default timeout; handling remains synchronous and can delay the application loop while waiting. It is not a nonblocking-server change.
OTF_RESPONSE_BUFFER_SIZEsets the response staging buffer at build time. The default remains 4096 bytes; values below 256 are rejected. Raw body writes stream across buffer boundaries. Applications reducing the buffer must ensure each individual formatted write (including a header) fits.
These changes do not change cloud authentication, TLS, or the proxy server.
Run the focused native parser tests with:
make -C test test-
Add support for OTA firmware updates.
-
Cleanup debug logging.
An opt-in OTF_SECURE_CLOUD integration enables the existing Arduino secure
constructor path and exposes intentional transport pause for resource sharing.
Pause increments the cloud generation and discards pending forwarded work;
requests are never replayed after reconnect. The pause preserves reconnect
failure history. Trust, buffer ownership and secure-client policy are supplied
by the application's reviewed WebSockets/core integration. Ordinary users and
builds without this flag retain their existing transport implementation.
This opt-in supports only Arduino ESP8266 and requires the paired transport's
OTF_VERIFIED_WSS_TRANSPORT=1 capability marker. Unsupported platforms or an
unpatched dependency fail compilation; defining the flag is not a way to enable
generic upstream TLS. Ordinary ESP8266, ESP32 and Linux users need no new flags.
Without the opt-in, the existing useSsl=true constructor remains inactive as
in0.2.7; this candidate does not silently enable it for other applications.
Call pauseCloud() only from the application's main loop, after OTF's loop()
has returned. Never call it from request handlers, WebSocket callbacks or ISRs:
it synchronously destroys the transport. It returns false without discarding
work when cloud dispatch or transport polling is active; callers must not assume
resources were released after a refusal. These guards do not make other calling
contexts supported, nor do they automatically detect interrupts/local handlers.
An accepted pause blocks reentrant polling throughout disconnect/cleanup. Its five-second reconnect delay begins after cleanup and preserves outage backoff. There are no additional per-client state fields. Host tests cover callback and cloud-handler refusal, pending work preserved on refusal, accepted pause cleanup, slow cleanup, half-open sockets, retry history and rollover. Existing dispatcher tests also cover payload lifetime when a network disconnect occurs in a handler; that is not permission to invoke pause from the handler.