use cli parser for agent

This commit is contained in:
csehviktor
2025-07-05 15:05:22 +02:00
parent 59865db66a
commit 3bcfc67bdb
6 changed files with 29 additions and 48 deletions
+4 -6
View File
@@ -3,17 +3,15 @@ use rumqttc::{AsyncClient, MqttOptions, QoS};
use std::time::Duration;
use tokio::task::JoinHandle;
use crate::config::MqttConfig;
pub struct MqttHandle {
pub agent: &'static str,
pub agent: String,
pub client: AsyncClient,
pub eventloop_handle: JoinHandle<()>,
}
impl MqttHandle {
pub async fn create(cfg: &'static MqttConfig) -> Self {
let mut mqttoptions = MqttOptions::new(&cfg.agent, &cfg.host, cfg.port);
pub async fn create(agent: String, host: String, port: u16) -> Self {
let mut mqttoptions = MqttOptions::new(&agent, &host, port);
mqttoptions.set_keep_alive(Duration::from_secs(5));
let (client, mut eventloop) = AsyncClient::new(mqttoptions, 10);
@@ -28,7 +26,7 @@ impl MqttHandle {
});
Self {
agent: &cfg.agent,
agent,
client,
eventloop_handle
}