You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.2 KiB

extern crate clap;
extern crate lazy_static;
extern crate regex;
extern crate serde_derive;
extern crate log;
extern crate env_logger;
mod lifx;
mod light;
mod mqtt;
mod mqtt_commands;
mod mqtt_updates;
use clap::App;
use clap::Arg;
use crossbeam_channel::unbounded;
use env_logger::Builder;
use log::info;
use log::LevelFilter;
use std::thread;
pub const MQTT_ID: &str = "lifx-mqtt-bridge";
fn main() {
let matches = App::new(MQTT_ID)
.about("Lifx Mqtt Bridge")
let host = matches.value_of("host").expect("Invalid host");
let port: u16 = matches
.expect("Invalid port")
.expect("Invalid port");
let lifx_secret = matches
.expect("Invalid lifx-secret");
info!("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());