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

◆ setup()

void setup ( )

Definition at line 64 of file RpcClient.ino.

64 {
65 Serial.begin(115200);
66 while (!Serial && millis() < 3000) {
67 // Wait for serial or timeout
68 }
69
70 Serial.println("\n=== HTTP RPC Client Example ===\n");
71 Serial.println("This example connects to an HTTP RPC server");
72 Serial.println("and calls remote methods using all three RPC modes:");
73 Serial.println(" - SYNC: Immediate response");
74 Serial.println(" - ASYNC: ACK + later result");
75 Serial.println(" - ASYNC_STREAM: ACK + updates + final");
76 Serial.println();
77 fl::printf("Connecting to server at %s:%d...\n", SERVER_HOST, SERVER_PORT);
78
79 // Initialize LEDs
80 FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
81 FastLED.setBrightness(50);
83 FastLED.show();
84
85 // Create HTTP streaming client transport
87
88 // Configure heartbeat and timeout
89 transport->setHeartbeatInterval(30000); // 30 seconds
90 transport->setTimeout(60000); // 60 seconds
91
92 // Set connection state callbacks
93 transport->setOnConnect([]() {
94 Serial.println("[CALLBACK] Connected to server!");
95 // Visual feedback: turn first LED green
96 leds[0] = CRGB::Green;
97 FastLED.show();
98 });
99
100 transport->setOnDisconnect([]() {
101 Serial.println("[CALLBACK] Disconnected from server!");
102 // Visual feedback: turn first LED red
103 leds[0] = CRGB::Red;
104 FastLED.show();
105 waitingForResponse = false;
106 });
107
108 // Create Remote with transport callbacks
110 []() { return transport->readRequest(); },
111 [](const fl::json& response) { transport->writeResponse(response); }
112 );
113
114 // Connect to server
115 if (!transport->connect()) {
116 Serial.println("ERROR: Failed to connect to server!");
117 Serial.println("Make sure RpcServer example is running.");
118 leds[0] = CRGB::Red;
119 FastLED.show();
120 return;
121 }
122
123 Serial.println("Connected successfully!");
124 Serial.println();
125}
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
#define DATA_PIN
Definition ClientReal.h:82
#define SERVER_PORT
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
bool waitingForResponse
fl::unique_ptr< fl::Remote > remote
Definition RpcClient.ino:43
fl::unique_ptr< fl::net::http::HttpStreamClient > transport
Definition RpcClient.ino:42
#define SERVER_HOST
Definition RpcClient.ino:33
void fill_solid(CRGB *targetArray, int numToFill, const CRGB &color) FL_NOEXCEPT
Fill a range of LEDs with a solid color.
Definition fill.cpp.hpp:9
constexpr EOrder GRB
Definition eorder.h:19
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
void printf(const char *format, const Args &... args) FL_NOEXCEPT
Printf-like formatting function that prints directly to the platform output.
Definition stdio.h:635
fl::enable_if<!fl::is_array< T >::value, unique_ptr< T > >::type make_unique(Args &&... args) FL_NOEXCEPT
Definition unique_ptr.h:261
@ Green
<div style='background:#008000;width:4em;height:4em;'></div>
Definition crgb.h:558
@ Red
<div style='background:#FF0000;width:4em;height:4em;'></div>
Definition crgb.h:622
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:510
#define Serial
Definition serial.h:304

References fl::CRGB::Black, DATA_PIN, FastLED, fill_solid(), GRB, fl::CRGB::Green, leds, fl::make_unique(), NUM_LEDS, fl::printf(), fl::CRGB::Red, remote, Serial, SERVER_HOST, SERVER_PORT, transport, and waitingForResponse.

+ Here is the call graph for this function: