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

Function runNetLoopback

examples/AutoResearch/AutoResearchNet.cpp:339–416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337}
338
339fl::json runNetLoopback() {
340 fl::json response = fl::json::object();
341 int tests_passed = 0;
342 int tests_failed = 0;
343 fl::json results = fl::json::array();
344
345 // Initialize TCP/IP stack for loopback (no WiFi needed)
346 if (!initNetifForLoopback()) {
347 response.set("success", false);
348 response.set("error", "Failed to initialize network stack for loopback");
349 return response;
350 }
351
352 // Start the HTTP server on localhost
353 if (!startHttpServer()) {
354 response.set("success", false);
355 response.set("error", "Failed to start HTTP server for loopback test");
356 return response;
357 }
358
359 FL_WARN("[NET] Loopback test: server running on port " << s_net_state.server_port);
360
361 // Small delay to let server settle
362 delay(100);
363
364 // Build loopback URLs using 127.0.0.1
365 char url_ping[128];
366 char url_status[128];
367 char url_leds[128];
368 snprintf(url_ping, sizeof(url_ping), "http://127.0.0.1:%u/ping",
369 s_net_state.server_port);
370 snprintf(url_status, sizeof(url_status), "http://127.0.0.1:%u/status",
371 s_net_state.server_port);
372 snprintf(url_leds, sizeof(url_leds), "http://127.0.0.1:%u/leds",
373 s_net_state.server_port);
374
375 // Test 1: GET /ping
376 {
377 fl::json r = runHttpGetTest(url_ping, "GET /ping (loopback)");
378 auto passed = r[fl::string("passed")].as_bool();
379 if (passed.has_value() && passed.value()) {
380 tests_passed++;
381 } else {
382 tests_failed++;
383 }
384 results.push_back(r);
385 }
386
387 // Test 2: GET /status
388 {
389 fl::json r = runHttpGetTest(url_status, "GET /status (loopback)");
390 auto passed = r[fl::string("passed")].as_bool();
391 if (passed.has_value() && passed.value()) {
392 tests_passed++;
393 } else {
394 tests_failed++;
395 }
396 results.push_back(r);

Callers 1

registerFunctionsMethod · 0.85

Calls 12

initNetifForLoopbackFunction · 0.85
snprintfFunction · 0.85
runHttpGetTestFunction · 0.85
startHttpServerFunction · 0.70
arrayClass · 0.50
delayFunction · 0.50
stringClass · 0.50
setMethod · 0.45
as_boolMethod · 0.45
has_valueMethod · 0.45
valueMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected