Struct wled_json_api_library::wled::Wled
source · pub struct Wled {
pub effects: Option<Effects>,
pub palettes: Option<Palettes>,
pub state: Option<State>,
pub info: Option<Info>,
pub cfg: Option<Cfg>,
pub live: Option<Live>,
pub nodes: Option<Nodes>,
pub net: Option<Net>,
pub client: Client,
pub url: Url,
pub ddp_url: Url,
}
Fields§
§effects: Option<Effects>
§palettes: Option<Palettes>
§state: Option<State>
§info: Option<Info>
§cfg: Option<Cfg>
§live: Option<Live>
§nodes: Option<Nodes>
§net: Option<Net>
§client: Client
§url: Url
§ddp_url: Url
Implementations§
source§impl Wled
impl Wled
sourcepub fn try_from_url(url: &Url) -> Result<Wled, WledJsonApiError>
pub fn try_from_url(url: &Url) -> Result<Wled, WledJsonApiError>
Examples found in repository?
examples/basic_example.rs (line 12)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
fn main() {
// create the URL
let url: Url = Url::try_from("http://192.168.1.40/").unwrap();
// create the WLED connection
let mut wled: Wled = Wled::try_from_url(&url).unwrap();
println!("new wled: {wled:?}");
// turn off the WLED
{
// put the desired change in the internal state data member
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,
});
// flush and print the server response
let response = wled.flush_state().unwrap();
println!("turning the thing off {:?}", response.text());
}
// fill internal cfg with result from WLED
wled.get_cfg_from_wled().unwrap();
// get the field defining the power on boot default behaviour
let turn_on_after_boot = wled.cfg.unwrap().def.unwrap().on.unwrap();
// print it
println!("received cfg, turn on after boot: {:?}", turn_on_after_boot);
// put the desired change into the config data member
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,
});
// print the response.
let response = wled.flush_config().unwrap();
println!("toggling: {:?}", response.text());
// wait for WLED to finish making this change.
// Around 100 milliseconds should be enough on good hardware,
// but this is especially slow because it has to read and write from the internal filesystem
// where the config file is stored
std::thread::sleep(Duration::from_millis(80));
// get and print the new state from the server
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);
}
sourcepub fn flush_state(&self) -> Result<Response, WledJsonApiError>
pub fn flush_state(&self) -> Result<Response, WledJsonApiError>
Examples found in repository?
examples/basic_example.rs (line 39)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
fn main() {
// create the URL
let url: Url = Url::try_from("http://192.168.1.40/").unwrap();
// create the WLED connection
let mut wled: Wled = Wled::try_from_url(&url).unwrap();
println!("new wled: {wled:?}");
// turn off the WLED
{
// put the desired change in the internal state data member
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,
});
// flush and print the server response
let response = wled.flush_state().unwrap();
println!("turning the thing off {:?}", response.text());
}
// fill internal cfg with result from WLED
wled.get_cfg_from_wled().unwrap();
// get the field defining the power on boot default behaviour
let turn_on_after_boot = wled.cfg.unwrap().def.unwrap().on.unwrap();
// print it
println!("received cfg, turn on after boot: {:?}", turn_on_after_boot);
// put the desired change into the config data member
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,
});
// print the response.
let response = wled.flush_config().unwrap();
println!("toggling: {:?}", response.text());
// wait for WLED to finish making this change.
// Around 100 milliseconds should be enough on good hardware,
// but this is especially slow because it has to read and write from the internal filesystem
// where the config file is stored
std::thread::sleep(Duration::from_millis(80));
// get and print the new state from the server
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);
}
sourcepub fn flush_config(&self) -> Result<Response, WledJsonApiError>
pub fn flush_config(&self) -> Result<Response, WledJsonApiError>
be careful with this, this library does not stop you from sending invalid and crazy configs. as long as the feilds make sense it should work, but
Examples found in repository?
examples/basic_example.rs (line 79)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
fn main() {
// create the URL
let url: Url = Url::try_from("http://192.168.1.40/").unwrap();
// create the WLED connection
let mut wled: Wled = Wled::try_from_url(&url).unwrap();
println!("new wled: {wled:?}");
// turn off the WLED
{
// put the desired change in the internal state data member
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,
});
// flush and print the server response
let response = wled.flush_state().unwrap();
println!("turning the thing off {:?}", response.text());
}
// fill internal cfg with result from WLED
wled.get_cfg_from_wled().unwrap();
// get the field defining the power on boot default behaviour
let turn_on_after_boot = wled.cfg.unwrap().def.unwrap().on.unwrap();
// print it
println!("received cfg, turn on after boot: {:?}", turn_on_after_boot);
// put the desired change into the config data member
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,
});
// print the response.
let response = wled.flush_config().unwrap();
println!("toggling: {:?}", response.text());
// wait for WLED to finish making this change.
// Around 100 milliseconds should be enough on good hardware,
// but this is especially slow because it has to read and write from the internal filesystem
// where the config file is stored
std::thread::sleep(Duration::from_millis(80));
// get and print the new state from the server
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);
}
pub fn get_effects_from_wled(&mut self) -> Result<(), WledJsonApiError>
pub fn get_info_from_wled(&mut self) -> Result<(), WledJsonApiError>
pub fn get_state_from_wled(&mut self) -> Result<(), WledJsonApiError>
sourcepub fn get_cfg_from_wled(&mut self) -> Result<(), WledJsonApiError>
pub fn get_cfg_from_wled(&mut self) -> Result<(), WledJsonApiError>
Examples found in repository?
examples/basic_example.rs (line 45)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
fn main() {
// create the URL
let url: Url = Url::try_from("http://192.168.1.40/").unwrap();
// create the WLED connection
let mut wled: Wled = Wled::try_from_url(&url).unwrap();
println!("new wled: {wled:?}");
// turn off the WLED
{
// put the desired change in the internal state data member
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,
});
// flush and print the server response
let response = wled.flush_state().unwrap();
println!("turning the thing off {:?}", response.text());
}
// fill internal cfg with result from WLED
wled.get_cfg_from_wled().unwrap();
// get the field defining the power on boot default behaviour
let turn_on_after_boot = wled.cfg.unwrap().def.unwrap().on.unwrap();
// print it
println!("received cfg, turn on after boot: {:?}", turn_on_after_boot);
// put the desired change into the config data member
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,
});
// print the response.
let response = wled.flush_config().unwrap();
println!("toggling: {:?}", response.text());
// wait for WLED to finish making this change.
// Around 100 milliseconds should be enough on good hardware,
// but this is especially slow because it has to read and write from the internal filesystem
// where the config file is stored
std::thread::sleep(Duration::from_millis(80));
// get and print the new state from the server
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);
}
pub fn get_net_from_wled(&mut self) -> Result<(), WledJsonApiError>
pub fn get_nodes_from_wled(&mut self) -> Result<(), WledJsonApiError>
pub fn get_palettes_from_wled(&mut self) -> Result<(), WledJsonApiError>
pub fn get_live_from_wled(&mut self) -> Result<(), WledJsonApiError>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Wled
impl Send for Wled
impl Sync for Wled
impl Unpin for Wled
impl !UnwindSafe for Wled
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more