add battery level & load setting by device.env

This commit is contained in:
Romulus21
2021-06-05 10:42:40 +02:00
parent 44ba86a985
commit 6c7d3f834a
7 changed files with 72 additions and 19 deletions

View File

@@ -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('/');