MCPcopy Create free account
hub / github.com/FastLED/FastLED / setup

Function setup

examples/Asio/ClientValidation/ClientValidationReal.h:203–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201}
202
203void 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());

Callers

nothing calls this directly

Calls 13

headerMethod · 0.80
statusMethod · 0.80
last_errorMethod · 0.80
updateLEDsFunction · 0.70
millisFunction · 0.50
beginMethod · 0.45
printlnMethod · 0.45
setBrightnessMethod · 0.45
getMethod · 0.45
startMethod · 0.45
printMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected