| 201 | } |
| 202 | |
| 203 | void setup() { |
| 204 | Serial.begin(115200); |
| 205 | Serial.println("\nHTTP Client Validation Suite (Loopback Mode)"); |
| 206 | Serial.println("Starting self-contained server + client test\n"); |
| 207 | |
| 208 | FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS); |
| 209 | FastLED.setBrightness(64); |
| 210 | |
| 211 | // Register HTTP server routes that mimic httpbin.org |
| 212 | |
| 213 | // ROUTE 1: GET /json - Sample JSON slideshow data |
| 214 | server.get("/json", [](const fl::http_request& req) { |
| 215 | // Return JSON as raw string with proper Content-Type header |
| 216 | const char* json_response = R"({ |
| 217 | "slideshow": { |
| 218 | "author": "FastLED Community", |
| 219 | "title": "FastLED Tutorial", |
| 220 | "slides": [ |
| 221 | {"title": "Introduction to FastLED", "type": "tutorial"}, |
| 222 | {"title": "LED Basics", "type": "lesson"}, |
| 223 | {"title": "HTTP Fetch API", "type": "demo"} |
| 224 | ] |
| 225 | } |
| 226 | })"; |
| 227 | fl::http_response response; |
| 228 | response.status(200) |
| 229 | .header("Content-Type", "application/json") |
| 230 | .body(json_response); |
| 231 | return response; |
| 232 | }); |
| 233 | |
| 234 | // ROUTE 2: GET /get - Echo request information |
| 235 | server.get("/get", [](const fl::http_request& req) { |
| 236 | const char* json_response = R"({ |
| 237 | "origin": "127.0.0.1", |
| 238 | "url": "http://localhost:8081/get" |
| 239 | })"; |
| 240 | fl::http_response response; |
| 241 | response.status(200) |
| 242 | .header("Content-Type", "application/json") |
| 243 | .body(json_response); |
| 244 | return response; |
| 245 | }); |
| 246 | |
| 247 | // ROUTE 3: GET /ping - Health check |
| 248 | server.get("/ping", [](const fl::http_request& req) { |
| 249 | return fl::http_response::ok("pong\n"); |
| 250 | }); |
| 251 | |
| 252 | // Start server (automatically integrates with FastLED async system) |
| 253 | if (server.start(SERVER_PORT)) { |
| 254 | Serial.print("Server started on http://localhost:"); |
| 255 | Serial.println(SERVER_PORT); |
| 256 | state = SERVER_STARTING; |
| 257 | } else { |
| 258 | Serial.println("ERROR: Failed to start server"); |
| 259 | Serial.print("Error: "); |
| 260 | Serial.println(server.last_error().c_str()); |
nothing calls this directly
no test coverage detected