add battery level & load setting by device.env
This commit is contained in:
@@ -3,13 +3,11 @@ use std::{
|
||||
process,
|
||||
time::Duration
|
||||
};
|
||||
use dotenv::dotenv;
|
||||
|
||||
// Define the qos.
|
||||
const QOS:i32 = 1;
|
||||
|
||||
pub fn init_cli() -> mqtt::Client {
|
||||
dotenv().ok();
|
||||
|
||||
let host = env::args().nth(1).unwrap_or_else(||
|
||||
env::var("BROKER_ADDRESS").unwrap().to_string()
|
||||
@@ -44,8 +42,8 @@ pub fn init_cli() -> mqtt::Client {
|
||||
}
|
||||
|
||||
pub fn publish_message(cli: mqtt::Client, topic: &str, message: &str) -> mqtt::Client {
|
||||
let topic = get_topic_name(topic);
|
||||
let msg = mqtt::Message::new(topic.clone(), message.clone(), QOS);
|
||||
// let topic = get_topic_name(topic);
|
||||
let msg = mqtt::Message::new(get_topic_name(topic), message, QOS);
|
||||
let tok = cli.publish(msg);
|
||||
|
||||
if let Err(e) = tok {
|
||||
@@ -65,7 +63,6 @@ pub fn disconnect(cli: mqtt::Client) {
|
||||
}
|
||||
|
||||
pub fn get_topic_name(types: &str) -> String {
|
||||
dotenv().ok();
|
||||
|
||||
let mut topic = env::var("SERVICE").unwrap().to_string();
|
||||
topic.push('/');
|
||||
|
||||
Reference in New Issue
Block a user