.env
This commit is contained in:
Generated
+7
@@ -239,6 +239,12 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dotenv"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
|
||||
|
||||
[[package]]
|
||||
name = "dtoa"
|
||||
version = "1.0.11"
|
||||
@@ -2065,6 +2071,7 @@ name = "weather"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"dotenv",
|
||||
"reqwest 0.13.4",
|
||||
"rumqttc",
|
||||
"scraper 0.27.0",
|
||||
|
||||
@@ -13,6 +13,7 @@ serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_derive = "1.0.228"
|
||||
serde_json = "1.0.149"
|
||||
chrono = "0.4.45"
|
||||
dotenv = "0.15.0"
|
||||
|
||||
# Raspberrypi
|
||||
# cross build --release --target aarch64-unknown-linux-gnu
|
||||
|
||||
+13
-2
@@ -5,6 +5,8 @@ use rumqttc::{AsyncClient, EventLoop, MqttOptions, QoS};
|
||||
use scraper::{Html as HtmlScraper, Selector};
|
||||
use std::time::Duration;
|
||||
use tokio::{task, time};
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
|
||||
const METEO_MUNICH_API_URL: &str =
|
||||
"https://www.meteorologie.lmu.de/~quicklooks/aktuelle_messwerte/messwerte_stadt.html";
|
||||
@@ -15,6 +17,9 @@ const LONGITUDE_MUC: f64 = 11.542922;
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() {
|
||||
|
||||
dotenv().ok();
|
||||
|
||||
let (client, mut eventloop) = create_conn();
|
||||
|
||||
match meteo_weather().await {
|
||||
@@ -157,11 +162,17 @@ async fn publish_topic(client: AsyncClient, topic: &str, value: String) {
|
||||
}
|
||||
|
||||
fn create_conn() -> (AsyncClient, EventLoop) {
|
||||
let mut mqttoptions = MqttOptions::new("rust-mqqt", "192.168.1.37", 1883);
|
||||
let mqtt_client = env::var("MQTT_CLIENT");
|
||||
let mqtt_broker = env::var("MQTT_BROKER");
|
||||
let mqtt_user = env::var("MQTT_USER");
|
||||
let mqtt_password = env::var("MQTT_PASSWORD");
|
||||
|
||||
let mut mqttoptions = MqttOptions::new(mqtt_client.unwrap(), mqtt_broker.unwrap(), 1883);
|
||||
mqttoptions
|
||||
.set_keep_alive(Duration::from_secs(5))
|
||||
.set_manual_acks(false)
|
||||
.set_credentials("mqtt", "delta32#")
|
||||
.set_credentials(mqtt_user.unwrap(), mqtt_password.unwrap())
|
||||
.set_clean_session(false);
|
||||
AsyncClient::new(mqttoptions, 10)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user