use std::env;

mod device_var;
mod mqtt_pub;
mod system_values;

fn main() {
    device_var::read_env_var();

    let mut count = 3;
    let (mut cli, connection) = mqtt_pub::init_cli();

    cli = mqtt_pub::publish_message(
        cli,
        "temperature",
        system_values::get_temperature().to_string(),
    );
    cli = mqtt_pub::publish_message(cli, "storage", system_values::get_storage().to_string());
    cli = mqtt_pub::publish_message(cli, "mem", system_values::get_mem().to_string());

    let battery = env::var("BATTERY").unwrap().to_string();
    if battery == "true" {
        count = 4;
        mqtt_pub::publish_message(cli, "battery", system_values::get_battery().to_string());
    }

    mqtt_pub::disconnect(connection, count);
}
