//! # MQTT
// Use http://www.hivemq.com/demos/websocket-client/
// Topics to subscribe:
//    - <uuid>/hello
//    - <uuid>/color_topic
//    - <uuid>/sensor_data/temperature
//    - <uuid>/sensor_data/temperature
// tests
use bsc::{
    led::{RGB8, WS2812RMT},
    wifi::wifi,
};
use embedded_svc::mqtt::client::{
    Client,
    Details::{Complete, InitialChunk, SubsequentChunk},
    Event::{self, Received},
    Message, Publish, QoS,
};
use esp32_s3_dkc02_bsc as bsc;
use esp_idf_svc::{
    log::EspLogger,
    mqtt::client::{EspMqttClient, EspMqttMessage, MqttClientConfiguration},
};
use shtcx::{self, PowerMode};
use std::{borrow::Cow, convert::TryFrom, thread::sleep, time::Duration};
// If using the `binstart` feature of `esp-idf-sys`, always keep this module imported
use esp_idf_hal::{
    delay::FreeRtos,
    i2c::{config::MasterConfig, Master, MasterPins, I2C0},
    peripherals::Peripherals,
    prelude::*,
};
use esp_idf_sys as _;
use log::{error, info};

// imported message topics
use mqtt_messages::{cmd_topic_fragment, hello_topic, Command, RawCommandData};

const UUID: &'static str = get_uuid::uuid();

#[toml_cfg::toml_config]
pub struct Config {
    #[default("broker.mqttdashboard.com")]
    mqtt_host: &'static str,
    #[default("")]
    mqtt_user: &'static str,
    #[default("")]
    mqtt_pass: &'static str,
    #[default("Wokwi-GUEST")]
    wifi_ssid: &'static str,
    #[default("")]
    wifi_psk: &'static str,
}

fn main() -> anyhow::Result<()> {
    // Setup
    esp_idf_sys::link_patches();

    EspLogger::initialize_default();

    let app_config = CONFIG;
    println!("Hollo");
    let mut led = bsc::led::WS2812RMT::new()?;
    led.set_pixel(RGB8::new(50, 50, 0))?;
    // let _wifi = wifi(app_config.wifi_ssid, app_config.wifi_psk)?;

   
    loop {
        println!("Test");
        sleep(Duration::from_secs(1));
    }
}