FastLED 3.9.15
Loading...
Searching...
No Matches

◆ setup()

void setup ( )

Definition at line 203 of file ClientValidationReal.h.

203 {
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})";
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})";
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);
257 } else {
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
#define DATA_PIN
Definition ClientReal.h:82
fl::HttpServer server
@ SERVER_STARTING
#define SERVER_PORT
TestState state
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
static Response ok(const string &body="")
Factory method for 200 OK response.
constexpr EOrder GRB
Definition eorder.h:19
asio::http::Request http_request
Definition server.h:280
asio::http::Response http_response
Definition server.h:281
#define Serial
Definition serial.h:304

References DATA_PIN, FastLED, GRB, leds, NUM_LEDS, fl::asio::http::Response::ok(), Serial, server, SERVER_PORT, SERVER_STARTING, and state.

+ Here is the call graph for this function: