PUBLISH_COUNT
This commit is contained in:
+6
-4
@@ -1,4 +1,5 @@
|
||||
mod weather_data;
|
||||
|
||||
use chrono::{Local};
|
||||
use crate::weather_data::{DwdWeather, MucWeather};
|
||||
use rumqttc::{AsyncClient, EventLoop, MqttOptions, QoS};
|
||||
@@ -15,6 +16,8 @@ const LATITUDE_MUC: f64 = 48.163142;
|
||||
|
||||
const LONGITUDE_MUC: f64 = 11.542922;
|
||||
|
||||
const PUBLISH_COUNT: i32 = 5;
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() {
|
||||
|
||||
@@ -26,7 +29,6 @@ async fn main() {
|
||||
Ok(weather) => {
|
||||
task::spawn(async move {
|
||||
publish(client.clone(), &weather).await;
|
||||
time::sleep(Duration::from_secs(3)).await;
|
||||
});
|
||||
|
||||
let mut count = 0;
|
||||
@@ -34,7 +36,7 @@ async fn main() {
|
||||
let event = eventloop.poll().await;
|
||||
match &event {
|
||||
Ok(_) => {
|
||||
if count == 10 {
|
||||
if count == PUBLISH_COUNT * 2 {
|
||||
break;
|
||||
}
|
||||
count = count + 1;
|
||||
@@ -134,7 +136,7 @@ pub async fn meteo_weather() -> Result<MucWeather, reqwest::Error> {
|
||||
precipitation,
|
||||
date: cur_date_formatted
|
||||
};
|
||||
println!("Zeile: {:?}", weather);
|
||||
println!("{:?}", weather);
|
||||
Ok(weather)
|
||||
}
|
||||
|
||||
@@ -146,7 +148,7 @@ async fn publish(client: AsyncClient, muc: &MucWeather) {
|
||||
publish_topic(client.clone(), "munich/pressure", muc.pressure.to_string()).await;
|
||||
publish_topic(client.clone(), "munich/humidity", muc.humidity.to_string()).await;
|
||||
publish_topic(client.clone(), "munich/precipitation", muc.precipitation.to_string()).await;
|
||||
time::sleep(Duration::from_secs(2)).await;
|
||||
time::sleep(Duration::from_secs(1)).await;
|
||||
}
|
||||
|
||||
async fn publish_topic(client: AsyncClient, topic: &str, value: String) {
|
||||
|
||||
Reference in New Issue
Block a user