extern crate clap; #[macro_use] extern crate lazy_static; extern crate regex; #[macro_use] extern crate serde_derive; mod lifx; mod light; mod mqtt; mod mqtt_commands; mod mqtt_updates; use clap::App; use clap::Arg; use crossbeam_channel::unbounded; use std::thread; pub const MQTT_ID: &str = "lifx-mqtt-bridge"; fn main() { let matches = App::new(MQTT_ID) .version("0.1") .about("Lifx Mqtt Bridge") .author("BuntpfotenkÃĪtzchen") .arg( Arg::with_name("host") .short("h") .long("host") .required(true) .takes_value(true), ) .arg( Arg::with_name("port") .short("p") .long("port") .takes_value(true) .default_value("1883"), ) .arg( Arg::with_name("lifx-secret") .short("s") .long("lifx-secret") .required(true) .takes_value(true), ) .get_matches(); let host = matches.value_of("host").unwrap(); let port: u16 = matches.value_of("port").unwrap().parse().unwrap(); let lifx_secret = matches.value_of("lifx-secret").unwrap(); println!("Connecting to {}:{}", host, port); let (s_commands, r_commands) = unbounded(); let (s_updates, r_updates) = unbounded(); let (mqtt_commands, mut mqtt_updates) = match mqtt::mqtt_connect(host, port, s_commands, r_updates) { Ok(mqtt) => mqtt, Err(err) => panic!("Error connecting: {}", err), }; let mut lifx_client = lifx::Lifx::new(lifx_secret, s_updates, r_commands); thread::spawn(move || mqtt_commands.listen()); thread::spawn(move || mqtt_updates.listen()); lifx_client.listen(); }