Struct 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,
}

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

Source

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}
Source

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}
Source

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}
Source

pub fn get_effects_from_wled(&mut self) -> Result<(), WledJsonApiError>

Source

pub fn get_info_from_wled(&mut self) -> Result<(), WledJsonApiError>

Source

pub fn get_state_from_wled(&mut self) -> Result<(), WledJsonApiError>

Source

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}
Source

pub fn get_net_from_wled(&mut self) -> Result<(), WledJsonApiError>

Source

pub fn get_nodes_from_wled(&mut self) -> Result<(), WledJsonApiError>

Source

pub fn get_palettes_from_wled(&mut self) -> Result<(), WledJsonApiError>

Source

pub fn get_live_from_wled(&mut self) -> Result<(), WledJsonApiError>

Trait Implementations§

Source§

impl Debug for Wled

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,