FastLED 3.9.15
Loading...
Searching...
No Matches
fl::WLED Class Reference

Detailed Description

WLED-specific Remote RPC extension.

Extends the base Remote RPC system with WLED state management for controlling on/off state, brightness, segments, and effects.

Provides methods to:

  • Set WLED state from JSON objects (on/bri/segments/effects/playlists)
  • Get current WLED state as JSON
  • Query individual state fields (on/off, brightness, segments, etc.)

WLED JSON API REFERENCE (https://kno.wled.ge/interfaces/json-api/)

ABOUT WLED:

WLED is a popular ESP8266/ESP32 firmware for controlling addressable LEDs over WiFi. It provides a comprehensive JSON API via HTTP endpoints like /json, /json/state, /json/info, /json/eff, /json/pal, etc.

FastLED does NOT implement a network server or HTTP endpoints. This reference documents WLED's JSON data structures and control properties that could be used for interoperability or implementing WLED-compatible control interfaces in FastLED-based projects

STATE OBJECT PROPERTIES:

Property Range Description
on bool or "t" Power toggle (true=on, false=off, "t"=toggle)
bri 0-255 Master brightness level
transition 0-65535 Crossfade duration (×100ms, e.g., 7 = 700ms)
ps -1 to 250 Active preset ID (-1=none)
pl -1 to 250 Active playlist ID (-1=none)
nl object Nightlight configuration (see below)
udpn object UDP sync settings
lor 0-2 Live data override (0=off, 1=override, 2=until reboot)
mainseg 0-maxseg-1 Main segment for global controls
seg array Segment configurations (see below)
playlist object Playlist configuration (see below)

SEGMENT CONTROL (seg array):

Property Range Description
id 0-maxseg-1 Segment identifier (required for updates)
start LED index Starting LED position (inclusive)
stop LED index Ending LED position (exclusive)
len count Segment length (alternative to stop)
grp count LED grouping factor
spc count Spacing between groups
of offset Group offset
on bool or "t" Segment power state
bri 0-255 Segment brightness
cct 0-255 or K Color temperature (Kelvin 1900-10091 or 0-255)
col array Color slots [[R,G,B(,W)], ...] or ["RRGGBB", ...]

| | - Index 0: Primary color | | - Index 1: Secondary color | | - Index 2: Tertiary color fx | 0-fxcount-1 | Effect ID sx | 0-255 | Effect speed ix | 0-255 | Effect intensity pal | 0-palcount-1 | Palette ID c1, c2, c3 | 0-255 | Effect custom parameters sel | bool | Segment selected for API control rev | bool | Reverse segment direction mi | bool | Mirror effect within segment o1, o2, o3 | bool | Effect option flags si | 0-3 | Sound simulation mode m12 | 0-3 | Segment mapping mode i | array | Individual LED control: ["RRGGBB", "RRGGBB", ...] | | - Use LED index or range: "i":["FF0000|10","00FF00|20-30"] n | string | Segment name rpt | bool | Repeat segment pattern

COLOR CONTROL:

Colors: RGB(W) arrays [[R,G,B(,W)], ...] or hex strings ["RRGGBB", ...] Example: {"seg":[{"col":[[255,170,0],[0,0,0],[64,64,64]]}]} or {"seg":[{"col":["FFAA00","000000","404040"]}]}

Individual LEDs: {"seg":{"i":["FF0000","00FF00","0000FF"]}}

  • Sets first 3 LEDs to red, green, blue
  • Range syntax: "i":["FF0000|10-20"] sets LEDs 10-20 to red

INFO OBJECT (read-only):

Property Description
ver WLED version string
vid Version ID (integer)
leds.count Total LED count
leds.rgbw True if 4-channel (RGBW) support
leds.wv True if WLED version supports white channel
leds.cct True if CCT control available
leds.pwr Current power consumption (mW)
leds.maxpwr Configured max power limit (mW)
leds.seglock True if segments locked
str Info string
name Device name
udpport UDP port number
live True if in live/realtime mode
lm Live mode data source
lip Live data source IP
ws WebSocket client count
fxcount Number of available effects
palcount Number of available palettes
cpalcount Number of custom palettes
maps LED mapping count
wifi.bssid Connected AP BSSID
wifi.signal WiFi signal strength (0-100)
wifi.channel WiFi channel
fs.u Used filesystem space (KB)
fs.t Total filesystem space (KB)
fs.pmt Last modification time
ndc Node discovery count
arch Architecture (esp8266/esp32/etc.)
core Core/SDK version
lwip LwIP version
freeheap Free heap memory (bytes)
uptime Uptime in seconds
opt Build options/features bitfield
brand Brand identifier
product Product identifier
mac MAC address
ip IP address

NIGHTLIGHT (nl object):

Property Range Description
on bool Nightlight active
dur 1-255 Duration in minutes
mode 0-3 Transition mode:

| | 0=Instant off, 1=Fade to off, 2=Color fade, | | 3=Sunrise (warmth increase) tbri | 0-255 | Target brightness for nightlight end rem | -1 to 255 | Remaining nightlight duration (read-only)

Example: {"nl":{"on":true,"dur":10,"mode":1}}

PLAYLIST (playlist object):

Property Description
ps Array of preset IDs to cycle through
dur Array of durations (seconds) for each preset
transition Array of transition times (×100ms) for each preset
repeat Number of cycles (0=infinite)
end End preset ID (after playlist completes)
r True for randomized playback order

Example: {"playlist":{"ps":[26,20,18],"dur":[30,20,10],"repeat":10}}

EFFECT METADATA (/json/fxdata):

Format: "<parameters>;<colors>;<palette>;<flags>;<defaults>"

  • Parameters: Control sliders/inputs for the effect
  • Colors: Number of color slots used (0-3)
  • Palette: True if effect uses palette
  • Flags: Effect characteristics:
    • '1' = Optimized for 1D strips
    • '2' = Requires 2D matrix
    • 'v' = Volume reactive (audio)
    • 'f' = Frequency reactive (audio)
  • Defaults: Default values for parameters

CCT (COLOR TEMPERATURE):

  • Accepts relative values (0-255) or Kelvin (1900-10091)
  • Only affects output when:
    • White balance correction enabled, OR
    • CCT-capable bus configured (dual white LEDs)
  • Example: {"seg":[{"cct":127}]} or {"seg":[{"cct":3000}]}

WLED JSON CONTROL EXAMPLES (for reference):

  1. Turn on at full brightness: {"on":true,"bri":255}
  2. Set segment 0 to teal color: {"seg":[{"id":0,"col":[[0,255,200]]}]}
  3. Toggle segment 2: {"seg":[{"id":2,"on":"t"}]}
  4. Apply effect 5 to segment 0 at speed 128, intensity 200: {"seg":[{"id":0,"fx":5,"sx":128,"ix":200}]}
  5. Set custom LED pattern (first 3 LEDs): {"seg":{"i":["FF0000","00FF00","0000FF"]}}
  6. Enable nightlight (fade to off in 30 minutes): {"nl":{"on":true,"dur":30,"mode":1}}
  7. Load preset 5: {"ps":5}
  8. Start playlist cycling through presets: {"playlist":{"ps":[1,2,3],"dur":[20,20,20],"repeat":0}}

WLED INTEGRATION NOTES:

  • WLED uses JSON for state management (not HTTP API for new integrations)
  • Partial updates supported: only changed properties need to be sent
  • Segments allow independent control of different LED strip regions
  • Effects and palettes are device-specific in WLED
  • WLED supports UDP sync for multi-device synchronization
  • Presets store complete state snapshots for quick recall
  • Playlists automate preset sequences with timing control

FASTLED IMPLEMENTATION:

This class currently implements basic WLED state management (on/bri). Future enhancements could include:

  • Segment control (multiple independent LED regions)
  • Effect parameter mapping (fx, sx, ix, pal)
  • Nightlight timer functionality
  • Preset/playlist support
  • Color temperature (CCT) control
  • Individual LED control syntax parsing

Definition at line 246 of file wled.h.

#include <wled.h>

+ Inheritance diagram for fl::WLED:
+ Collaboration diagram for fl::WLED:

Public Member Functions

 WLED () FL_NOEXCEPT
 Construct WLED with default stub I/O callbacks.
 
 WLED (RequestSource source, ResponseSink sink)
 Construct WLED with custom I/O callbacks.
 
const WLEDSegmentfindSegmentById (u8 id) const
 Find segment by ID.
 
u8 getBrightness () const
 Get WLED brightness.
 
u8 getLiveOverride () const
 Get live data override setting.
 
u8 getMainSegment () const
 Get main segment index.
 
u8 getNightlightDuration () const
 Get nightlight duration.
 
u8 getNightlightMode () const
 Get nightlight mode.
 
bool getNightlightOn () const
 Get nightlight active state.
 
u8 getNightlightTargetBrightness () const
 Get nightlight target brightness.
 
bool getOn () const
 Get WLED on/off state.
 
i16 getPlaylist () const
 Get active playlist ID.
 
fl::json getPlaylistConfig () const
 Get playlist configuration.
 
i16 getPreset () const
 Get active preset ID.
 
const WLEDSegmentgetSegment (size_t index) const
 Get segment by index.
 
size_t getSegmentCount () const
 Get segment count.
 
const fl::vector< WLEDSegment > & getSegments () const
 Get all segments.
 
fl::json getState () const
 Get current WLED state as JSON object.
 
u16 getTransition () const
 Get transition duration.
 
bool getUdpReceive () const
 Get UDP sync receive setting.
 
bool getUdpSend () const
 Get UDP sync send setting.
 
bool hasPlaylistConfig () const
 Check if playlist is active.
 
void setState (const fl::json &wledState)
 Set WLED state from JSON object.
 
- Public Member Functions inherited from fl::Remote
 Remote (const Remote &) FL_NOEXCEPT=delete
 
 Remote (Remote &&) FL_NOEXCEPT=delete
 
 Remote (RequestSource source, ResponseSink sink)
 Construct with I/O callbacks.
 
template<typename Callable>
void bind (const char *name, Callable fn, fl::RpcMode mode=fl::RpcMode::SYNC)
 Register method by name, function, and optional mode (default SYNC)
 
template<typename Callable>
void bind (const Config< Callable > &config)
 Register method with config (name, function, optional metadata)
 
void bindAsync (const char *name, fl::function< void(fl::ResponseSend &, const fl::json &)> fn, fl::RpcMode mode=fl::RpcMode::ASYNC)
 Register async method with ResponseSend& parameter (for ASYNC/ASYNC_STREAM modes) Signature: void(ResponseSend&, const json&) The ResponseSend& parameter provides send(), sendUpdate(), sendFinal() methods.
 
void clear (ClearFlags flags)
 Clear state (bitwise OR of ClearFlags)
 
fl::size count () const
 Get number of registered methods.
 
template<class Sig>
fl::BindResult< Sig > get (const char *name) const
 Get bound method by name for direct C++ invocation.
 
bool has (const fl::string &name) const
 Check if method is registered.
 
fl::vector< MethodInfomethods () const
 Get method information for all registered methods.
 
Remoteoperator= (const Remote &) FL_NOEXCEPT=delete
 
Remoteoperator= (Remote &&) FL_NOEXCEPT=delete
 
size_t pendingCount () const
 Get number of pending scheduled calls.
 
fl::json processRpc (const fl::json &request)
 Process JSON-RPC request (with optional "timestamp" field for scheduling) Returns JSON-RPC response: {"result": ...} or {"error": {...}}.
 
void reportError (const fl::json &data)
 Send an error notification with structured data Format: {"jsonrpc":"2.0","method":"__error","params":<data>}.
 
void reportError (const fl::string &message)
 Send an error notification to the remote peer.
 
fl::json schema () const
 Returns flat schema document Format: {"schema": [["methodName", "returnType", [["param1", "type1"], ...]], ...]}.
 
void sendAsyncResponse (const char *method, const fl::json &result)
 Send async response for a previously-called async method The request ID is automatically retrieved from internal storage.
 
void sendStreamFinal (const char *method, const fl::json &result)
 Send final stream response for a streaming async method (ASYNC_STREAM mode) The request ID is automatically retrieved from internal storage and method is removed.
 
void sendStreamUpdate (const char *method, const fl::json &update)
 Send stream update for a streaming async method (ASYNC_STREAM mode) The request ID is automatically retrieved from internal storage.
 
size_t tick (u32 currentTimeMs)
 Process scheduled calls (call regularly)
 
bool unbind (const fl::string &name)
 Unregister method by name.
 
size_t update (u32 currentTimeMs)
 Main update: pull + tick + push (overrides Server::update)
 
- Public Member Functions inherited from fl::Server
 Server () FL_NOEXCEPT
 Default constructor.
 
 Server (const Server &) FL_NOEXCEPT=delete
 
 Server (RequestSource source, ResponseSink sink)
 Construct with I/O callbacks.
 
 Server (Server &&) FL_NOEXCEPT=default
 
virtual ~Server () FL_NOEXCEPT=default
 
Serveroperator= (const Server &) FL_NOEXCEPT=delete
 
Serveroperator= (Server &&) FL_NOEXCEPT=default
 
size_t pull ()
 Pull requests from source, process, queue responses.
 
size_t push ()
 Push queued responses to sink.
 
void setRequestHandler (RequestHandler handler)
 Set request handler.
 
void setRequestSource (RequestSource source)
 Set request source callback.
 
void setResponseSink (ResponseSink sink)
 Set response sink callback.
 
size_t update ()
 Main update: pull + push.
 

Private Member Functions

fl::optional< fl::jsonstubRequestSource ()
 Stub request source callback.
 
void stubResponseSink (const fl::json &response)
 Stub response sink callback.
 

Private Attributes

u8 mLiveOverride = 0
 
u8 mMainSegment = 0
 
u8 mNightlightDuration = 60
 
u8 mNightlightMode = 1
 
bool mNightlightOn = false
 
u8 mNightlightTargetBrightness = 0
 
i16 mPlaylist = -1
 
fl::vector< u16 > mPlaylistDurations
 
i16 mPlaylistEnd = -1
 
fl::vector< i16 > mPlaylistPresets
 
bool mPlaylistRandomize = false
 
u16 mPlaylistRepeat = 0
 
fl::vector< u16 > mPlaylistTransitions
 
i16 mPreset = -1
 
fl::vector< WLEDSegmentmSegments
 
u16 mTransition = 7
 
bool mUdpReceive = true
 
bool mUdpSend = false
 
u8 mWledBri = 255
 
bool mWledOn = false
 

Additional Inherited Members

- Public Types inherited from fl::Remote
using ClearFlags = fl::RemoteClearFlags
 
template<typename Callable>
using Config = typename fl::Rpc::Config<Callable>
 Configuration for method registration (forwards to Rpc::Config)
 
using MethodInfo = fl::MethodInfo
 
using ParamInfo = fl::ParamInfo
 
using RpcResult = fl::RpcResult
 
- Public Types inherited from fl::Server
using RequestHandler = fl::function<fl::json(const fl::json&)>
 
using RequestSource = fl::function<fl::optional<fl::json>()>
 
using ResponseSink = fl::function<void(const fl::json&)>
 
- Protected Member Functions inherited from fl::Remote
void recordResult (const fl::string &funcName, const fl::json &result, u32 scheduledAt, u32 receivedAt, u32 executedAt, bool wasScheduled)
 
void scheduleFunction (u32 timestamp, u32 receivedAt, const fl::json &jsonRpcRequest)
 
- Protected Attributes inherited from fl::Remote
fl::unordered_map< fl::string, AsyncRequestmAsyncRequests
 
fl::vector< RpcResultmResults
 
fl::Rpc mRpc
 
fl::net::RpcScheduler mScheduler
 
- Protected Attributes inherited from fl::Server
fl::vector< fl::jsonmOutgoingQueue
 
RequestHandler mRequestHandler
 
RequestSource mRequestSource
 
ResponseSink mResponseSink
 

The documentation for this class was generated from the following files: