wled-json-api-library
easy way to control WLED with their JSON API.
This library has a pretty sizable amount of documentation for what each feild means, so even if you are making your own library or can't use Rust, this is the best spot I can find to figure out what various feilds mean. Most are not on the JSON API page, and most of the rest isn't even commented in the WLED source code.
Compatibility
I made and tested this with WLED 14.0, but it's meant to support as many builds and past versions as possible. Future versions may or may not be added, but the feilds already present should still work.
Streaming colors
while there is a way to stream colors with the JSON API, it sucks and it slow. If this is something you want to do, use the DDP protocol. rust ddp protocol library
Example
use std::time::Duration;
use reqwest::Url;
use wled_json_api_library::wled::Wled;
use wled_json_api_library::structures::{state::State, cfg::Cfg, cfg::cfg_def::Def};
fn main() {
let url: Url = Url::try_from("http://192.168.1.40/").unwrap();
let mut wled: Wled = Wled::try_from_url(&url).unwrap();
println!("new wled: {wled:?}");
{
wled.state = Some(State {
on: Some(true),
bri: None,
transition: None,
tt: None,
ps: None,
psave: None,
pl: None,
nl: None,
udpn: None,
v: None,
rb: None,
live: None,
lor: None,
time: None,
mainseg: None,
playlist: None,
seg: None,
});
let response = wled.flush_state().unwrap();
println!("turning the thing off {:?}", response.text());
}
wled.get_cfg_from_wled().unwrap();
let turn_on_after_boot = wled.cfg.unwrap().def.unwrap().on.unwrap();
println!("received cfg, turn on after boot: {:?}", turn_on_after_boot);
wled.cfg = Some(Cfg{
rev: None,
vid: None,
id: None,
nw: None,
eth: None,
ap: None,
wifi: None,
hw: None,
light: None,
def: Some(Def{
ps: None,
on: Some(!turn_on_after_boot),
bri: None,
}),
if_field: None,
remote: None,
ol: None,
timers: None,
ota: None,
dmx: None,
um: None,
});
let response = wled.flush_config().unwrap();
println!("toggling: {:?}", response.text());
std::thread::sleep(Duration::from_millis(80));
wled.get_cfg_from_wled().unwrap();
let turn_on_after_boot = wled.cfg.unwrap().def.unwrap().on.unwrap();
println!("received cfg, turn on after boot: {:?}", turn_on_after_boot);
}