99 FL_WARN(
"FastLED Networking Tutorial started - 10 LEDs set to dark red");
100 FL_WARN(
"Learning HTTP fetch API with TWO different async patterns:");
101 FL_WARN(
" APPROACH 1: Promise-based (.then/.catch_) with explicit types");
102 FL_WARN(
" APPROACH 2: fl::task::await_top_level pattern with explicit types");
103 FL_WARN(
"Toggles between approaches every 10 seconds for comparison...");
104 FL_WARN(
"LED colors indicate status: Red=Error, Green=Promise Success, Blue=Await Success");
110 FL_WARN(
"APPROACH 1: Promise-based pattern with explicit types");
120 FL_WARN(
"SUCCESS [Promise] HTTP fetch successful! Status: "
121 << response.status() <<
" " << response.status_text());
127 FL_WARN(
"CONTENT [Promise] Content-Type: " << *content_type);
131 const fl::string& response_body = response.text();
132 if (response_body.
length() >= 100) {
133 FL_WARN(
"RESPONSE [Promise] First 100 characters: " << response_body.
substr(0, 100));
135 FL_WARN(
"RESPONSE [Promise] Full response (" << response_body.
length()
136 <<
" chars): " << response_body);
143 FL_WARN(
"ERROR [Promise] HTTP Error! Status: "
144 << response.status() <<
" " << response.status_text());
145 FL_WARN(
"CONTENT [Promise] Error content: " << response.text());
155 FL_WARN(
"ERROR [Promise] Network Error: " << network_error.
message);
165 FL_WARN(
"APPROACH 2: await_top_level pattern with explicit types");
171 .
header(
"User-Agent",
"FastLED/Client-Tutorial");
188 FL_WARN(
"SUCCESS [Await] HTTP fetch successful! Status: "
189 << http_response.
status() <<
" " << http_response.status_text());
195 FL_WARN(
"CONTENT [Await] Content-Type: " << *content_type);
199 const fl::string& response_body = http_response.text();
200 if (response_body.
length() >= 100) {
201 FL_WARN(
"RESPONSE [Await] First 100 characters: " << response_body.
substr(0, 100));
203 FL_WARN(
"RESPONSE [Await] Full response (" << response_body.
length()
204 <<
" chars): " << response_body);
212 FL_WARN(
"ERROR [Await] Request failed: " << result.error_message());
222 FL_WARN(
"APPROACH 3: JSON Response handling with fl::json integration");
228 FL_WARN(
"SUCCESS [JSON Promise] HTTP fetch successful! Status: "
229 << response.status() <<
" " << response.status_text());
233 if (response.is_json()) {
234 FL_WARN(
"DETECTED [JSON Promise] Response contains JSON data");
244 int slide_count = data[
"slideshow"][
"slides"].
size();
246 FL_WARN(
"JSON [Promise] Slideshow Author: " << slideshow_url);
247 FL_WARN(
"JSON [Promise] Slideshow Title: " << slideshow_title);
248 FL_WARN(
"JSON [Promise] Slide Count: " << slide_count);
252 fl::json slides = data[
"slideshow"][
"slides"];
257 FL_WARN(
"JSON [Promise] First slide: " << first_slide_title <<
" (" << first_slide_type <<
")");
265 FL_WARN(
"INFO [JSON Promise] Response is not JSON format");
270 FL_WARN(
"ERROR [JSON Promise] HTTP error: " << response.status()
271 <<
" " << response.status_text());
287 FL_WARN(
"APPROACH 4: JSON Response with await pattern");
301 FL_WARN(
"SUCCESS [JSON Await] HTTP fetch successful! Status: "
302 << http_response.
status() <<
" " << http_response.status_text());
305 if (http_response.is_json()) {
306 FL_WARN(
"DETECTED [JSON Await] Response contains JSON data");
316 FL_WARN(
"JSON [Await] Request Origin IP: " << origin_ip);
317 FL_WARN(
"JSON [Await] Request URL: " << request_url);
325 FL_WARN(
"JSON [Await] User-Agent: " << user_agent);
326 FL_WARN(
"JSON [Await] Accept: " << accept);
332 if (
args.size() > 0) {
333 FL_WARN(
"JSON [Await] Query parameters found: " <<
args.size());
335 FL_WARN(
"JSON [Await] No query parameters in request");
343 FL_WARN(
"INFO [JSON Await] Response is not JSON format");
350 FL_WARN(
"ERROR [JSON Await] Request failed: " << result.error_message());
373 FL_WARN(
"CYCLE: Demonstrated Promise-based pattern (Green LEDs on success)");
376 FL_WARN(
"CYCLE: Demonstrated Await-based pattern (Blue LEDs on success)");
379 FL_WARN(
"CYCLE: Demonstrated JSON Promise pattern (Blue LEDs on success)");
382 FL_WARN(
"CYCLE: Demonstrated JSON Await pattern (Cyan LEDs on success)");
387 FL_WARN(
"NEXT: Will switch to next approach in 10 seconds...");
static fl::u32 last_request_time
void test_promise_approach()
void test_json_await()
APPROACH 4: JSON Response with await pattern Same JSON handling but using await_top_level for synch...
void test_await_approach()
void test_json_response()
APPROACH 3: JSON Response Handling with FastLED's ideal JSON API This demonstrates fetch responses wi...
static int approach_counter
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
bool has_value() const FL_NOEXCEPT
Response & json(const class json &data)
Set JSON response body with automatic Content-Type header.
Response & status(int code)
Set HTTP status code.
fl::size length() const FL_NOEXCEPT
bool is_array() const FL_NOEXCEPT
size_t size() const FL_NOEXCEPT
bool contains(size_t idx) const FL_NOEXCEPT
FetchOptions & header(const fl::string &name, const fl::string &value)
Add header.
FetchOptions & timeout(int timeout_ms)
Set timeout in milliseconds.
Fetch options builder (fluent interface)
HTTP response class (unified interface)
string substr(fl::size start, fl::size length) const FL_NOEXCEPT
Promise class that provides fluent .then() and .catch_() semantics This is a lightweight wrapper arou...
Result type for promise operations.
void fill_solid(CRGB *targetArray, int numToFill, const CRGB &color) FL_NOEXCEPT
Fill a range of LEDs with a solid color.
Task executor — runs registered task runners and manages the run loop.
Unified HTTP fetch API for FastLED (cross-platform)
Centralized logging categories for FastLED hardware interfaces and subsystems.
fl::task::Promise< Response > fetch_get(const fl::string &url, const FetchOptions &request)
HTTP GET request.
PromiseResult< T > await_top_level(Promise< T > p)
Synchronously wait for a promise to complete (ONLY safe in top-level contexts)
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
Representation of an 8-bit RGB pixel (Red, Green, Blue)