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,
}
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
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)
6fn main() {
7
8 // create the URL
9 let url: Url = Url::try_from("http://192.168.1.40/").unwrap();
10
11 // create the WLED connection
12 let mut wled: Wled = Wled::try_from_url(&url).unwrap();
13 println!("new wled: {wled:?}");
14
15 // turn off the WLED
16 {
17 // put the desired change in the internal state data member
18 wled.state = Some(State {
19 on: Some(true),
20 bri: None,
21 transition: None,
22 tt: None,
23 ps: None,
24 psave: None,
25 pl: None,
26 nl: None,
27 udpn: None,
28 v: None,
29 rb: None,
30 live: None,
31 lor: None,
32 time: None,
33 mainseg: None,
34 playlist: None,
35 seg: None,
36 });
37
38 // flush and print the server response
39 let response = wled.flush_state().unwrap();
40 println!("turning the thing off {:?}", response.text());
41 }
42
43
44 // fill internal cfg with result from WLED
45 wled.get_cfg_from_wled().unwrap();
46
47 // get the field defining the power on boot default behaviour
48 let turn_on_after_boot = wled.cfg.unwrap().def.unwrap().on.unwrap();
49 // print it
50 println!("received cfg, turn on after boot: {:?}", turn_on_after_boot);
51
52
53 // put the desired change into the config data member
54 wled.cfg = Some(Cfg{
55 rev: None,
56 vid: None,
57 id: None,
58 nw: None,
59 eth: None,
60 ap: None,
61 wifi: None,
62 hw: None,
63 light: None,
64 def: Some(Def{
65 ps: None,
66 on: Some(!turn_on_after_boot),
67 bri: None,
68 }),
69 if_field: None,
70 remote: None,
71 ol: None,
72 timers: None,
73 ota: None,
74 dmx: None,
75 um: None,
76 });
77
78 // print the response.
79 let response = wled.flush_config().unwrap();
80 println!("toggling: {:?}", response.text());
81
82 // wait for WLED to finish making this change.
83 // Around 100 milliseconds should be enough on good hardware,
84 // but this is especially slow because it has to read and write from the internal filesystem
85 // where the config file is stored
86 std::thread::sleep(Duration::from_millis(80));
87
88
89 // get and print the new state from the server
90 wled.get_cfg_from_wled().unwrap();
91 let turn_on_after_boot = wled.cfg.unwrap().def.unwrap().on.unwrap();
92
93 println!("received cfg, turn on after boot: {:?}", turn_on_after_boot);
94
95}
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)
6fn main() {
7
8 // create the URL
9 let url: Url = Url::try_from("http://192.168.1.40/").unwrap();
10
11 // create the WLED connection
12 let mut wled: Wled = Wled::try_from_url(&url).unwrap();
13 println!("new wled: {wled:?}");
14
15 // turn off the WLED
16 {
17 // put the desired change in the internal state data member
18 wled.state = Some(State {
19 on: Some(true),
20 bri: None,
21 transition: None,
22 tt: None,
23 ps: None,
24 psave: None,
25 pl: None,
26 nl: None,
27 udpn: None,
28 v: None,
29 rb: None,
30 live: None,
31 lor: None,
32 time: None,
33 mainseg: None,
34 playlist: None,
35 seg: None,
36 });
37
38 // flush and print the server response
39 let response = wled.flush_state().unwrap();
40 println!("turning the thing off {:?}", response.text());
41 }
42
43
44 // fill internal cfg with result from WLED
45 wled.get_cfg_from_wled().unwrap();
46
47 // get the field defining the power on boot default behaviour
48 let turn_on_after_boot = wled.cfg.unwrap().def.unwrap().on.unwrap();
49 // print it
50 println!("received cfg, turn on after boot: {:?}", turn_on_after_boot);
51
52
53 // put the desired change into the config data member
54 wled.cfg = Some(Cfg{
55 rev: None,
56 vid: None,
57 id: None,
58 nw: None,
59 eth: None,
60 ap: None,
61 wifi: None,
62 hw: None,
63 light: None,
64 def: Some(Def{
65 ps: None,
66 on: Some(!turn_on_after_boot),
67 bri: None,
68 }),
69 if_field: None,
70 remote: None,
71 ol: None,
72 timers: None,
73 ota: None,
74 dmx: None,
75 um: None,
76 });
77
78 // print the response.
79 let response = wled.flush_config().unwrap();
80 println!("toggling: {:?}", response.text());
81
82 // wait for WLED to finish making this change.
83 // Around 100 milliseconds should be enough on good hardware,
84 // but this is especially slow because it has to read and write from the internal filesystem
85 // where the config file is stored
86 std::thread::sleep(Duration::from_millis(80));
87
88
89 // get and print the new state from the server
90 wled.get_cfg_from_wled().unwrap();
91 let turn_on_after_boot = wled.cfg.unwrap().def.unwrap().on.unwrap();
92
93 println!("received cfg, turn on after boot: {:?}", turn_on_after_boot);
94
95}
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)
6fn main() {
7
8 // create the URL
9 let url: Url = Url::try_from("http://192.168.1.40/").unwrap();
10
11 // create the WLED connection
12 let mut wled: Wled = Wled::try_from_url(&url).unwrap();
13 println!("new wled: {wled:?}");
14
15 // turn off the WLED
16 {
17 // put the desired change in the internal state data member
18 wled.state = Some(State {
19 on: Some(true),
20 bri: None,
21 transition: None,
22 tt: None,
23 ps: None,
24 psave: None,
25 pl: None,
26 nl: None,
27 udpn: None,
28 v: None,
29 rb: None,
30 live: None,
31 lor: None,
32 time: None,
33 mainseg: None,
34 playlist: None,
35 seg: None,
36 });
37
38 // flush and print the server response
39 let response = wled.flush_state().unwrap();
40 println!("turning the thing off {:?}", response.text());
41 }
42
43
44 // fill internal cfg with result from WLED
45 wled.get_cfg_from_wled().unwrap();
46
47 // get the field defining the power on boot default behaviour
48 let turn_on_after_boot = wled.cfg.unwrap().def.unwrap().on.unwrap();
49 // print it
50 println!("received cfg, turn on after boot: {:?}", turn_on_after_boot);
51
52
53 // put the desired change into the config data member
54 wled.cfg = Some(Cfg{
55 rev: None,
56 vid: None,
57 id: None,
58 nw: None,
59 eth: None,
60 ap: None,
61 wifi: None,
62 hw: None,
63 light: None,
64 def: Some(Def{
65 ps: None,
66 on: Some(!turn_on_after_boot),
67 bri: None,
68 }),
69 if_field: None,
70 remote: None,
71 ol: None,
72 timers: None,
73 ota: None,
74 dmx: None,
75 um: None,
76 });
77
78 // print the response.
79 let response = wled.flush_config().unwrap();
80 println!("toggling: {:?}", response.text());
81
82 // wait for WLED to finish making this change.
83 // Around 100 milliseconds should be enough on good hardware,
84 // but this is especially slow because it has to read and write from the internal filesystem
85 // where the config file is stored
86 std::thread::sleep(Duration::from_millis(80));
87
88
89 // get and print the new state from the server
90 wled.get_cfg_from_wled().unwrap();
91 let turn_on_after_boot = wled.cfg.unwrap().def.unwrap().on.unwrap();
92
93 println!("received cfg, turn on after boot: {:?}", turn_on_after_boot);
94
95}
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)
6fn main() {
7
8 // create the URL
9 let url: Url = Url::try_from("http://192.168.1.40/").unwrap();
10
11 // create the WLED connection
12 let mut wled: Wled = Wled::try_from_url(&url).unwrap();
13 println!("new wled: {wled:?}");
14
15 // turn off the WLED
16 {
17 // put the desired change in the internal state data member
18 wled.state = Some(State {
19 on: Some(true),
20 bri: None,
21 transition: None,
22 tt: None,
23 ps: None,
24 psave: None,
25 pl: None,
26 nl: None,
27 udpn: None,
28 v: None,
29 rb: None,
30 live: None,
31 lor: None,
32 time: None,
33 mainseg: None,
34 playlist: None,
35 seg: None,
36 });
37
38 // flush and print the server response
39 let response = wled.flush_state().unwrap();
40 println!("turning the thing off {:?}", response.text());
41 }
42
43
44 // fill internal cfg with result from WLED
45 wled.get_cfg_from_wled().unwrap();
46
47 // get the field defining the power on boot default behaviour
48 let turn_on_after_boot = wled.cfg.unwrap().def.unwrap().on.unwrap();
49 // print it
50 println!("received cfg, turn on after boot: {:?}", turn_on_after_boot);
51
52
53 // put the desired change into the config data member
54 wled.cfg = Some(Cfg{
55 rev: None,
56 vid: None,
57 id: None,
58 nw: None,
59 eth: None,
60 ap: None,
61 wifi: None,
62 hw: None,
63 light: None,
64 def: Some(Def{
65 ps: None,
66 on: Some(!turn_on_after_boot),
67 bri: None,
68 }),
69 if_field: None,
70 remote: None,
71 ol: None,
72 timers: None,
73 ota: None,
74 dmx: None,
75 um: None,
76 });
77
78 // print the response.
79 let response = wled.flush_config().unwrap();
80 println!("toggling: {:?}", response.text());
81
82 // wait for WLED to finish making this change.
83 // Around 100 milliseconds should be enough on good hardware,
84 // but this is especially slow because it has to read and write from the internal filesystem
85 // where the config file is stored
86 std::thread::sleep(Duration::from_millis(80));
87
88
89 // get and print the new state from the server
90 wled.get_cfg_from_wled().unwrap();
91 let turn_on_after_boot = wled.cfg.unwrap().def.unwrap().on.unwrap();
92
93 println!("received cfg, turn on after boot: {:?}", turn_on_after_boot);
94
95}
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 Freeze for Wled
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