Changing the color of a Wiz lightbulb from Rust.
After setting up the device to accept local communication we can control the smart devices by sending a UDP packet. You can do it via NC or by making a program. There is a nice Python library for this as well.
I'm going to list quick examples here for NC, Bash and Rust.
NC:
echo -n '{"id":1,"method":"setPilot","params":{"r":85,"g":85,"b":85,"dimming":100}}' | nc -4u -w1 192.168.5.106 38899
Bash:
echo -n '{"id":1,"method":"setPilot","params":{"r":200,"g":12,"b":85,"dimming":100}}' > /dev/udp/192.168.5.106/38899
Rust:
fn main() {
// Create the UDP socket
let socket = UdpSocket::bind("0.0.0.0:0").unwrap(); // Bind to an available local port
let target = "192.168.5.106:38899";
let mut rng = rand::thread_rng();
let r: u8 = rng.gen_range(0..=255);
let g: u8 = rng.gen_range(0..=255);
let b: u8 = rng.gen_range(0..=255);
let message2 = format!(r#"{{"id":1,"method":"setPilot","params":{{"r":{},"g":{},"b":{},"dimming":100}}}}"#,r,g,b);
socket.send_to(message2.as_bytes(), target).unwrap();
}