Initial Version
This commit is contained in:
Generated
+115
@@ -15,12 +15,27 @@ dependencies = [
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atomic-waker"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
||||
|
||||
[[package]]
|
||||
name = "aws-lc-rs"
|
||||
version = "1.17.0"
|
||||
@@ -97,6 +112,19 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"
|
||||
dependencies = [
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"wasm-bindgen",
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cmake"
|
||||
version = "0.1.58"
|
||||
@@ -553,6 +581,30 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.65"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"log",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icu_collections"
|
||||
version = "2.2.0"
|
||||
@@ -776,6 +828,15 @@ version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.4"
|
||||
@@ -2003,6 +2064,7 @@ dependencies = [
|
||||
name = "weather"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"reqwest 0.13.4",
|
||||
"rumqttc",
|
||||
"scraper 0.27.0",
|
||||
@@ -2054,12 +2116,65 @@ dependencies = [
|
||||
"rustls-pki-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.62.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-link",
|
||||
"windows-result",
|
||||
"windows-strings",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-implement"
|
||||
version = "0.60.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-interface"
|
||||
version = "0.59.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-strings"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
|
||||
@@ -12,6 +12,7 @@ rumqttc = "0.25.1"
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_derive = "1.0.228"
|
||||
serde_json = "1.0.149"
|
||||
chrono = "0.4.45"
|
||||
|
||||
# Raspberrypi
|
||||
# cross build --release --target aarch64-unknown-linux-gnu
|
||||
|
||||
+33
-53
@@ -1,5 +1,5 @@
|
||||
mod weather_data;
|
||||
|
||||
use chrono::{Local};
|
||||
use crate::weather_data::{DwdWeather, MucWeather};
|
||||
use rumqttc::{AsyncClient, EventLoop, MqttOptions, QoS};
|
||||
use scraper::{Html as HtmlScraper, Selector};
|
||||
@@ -43,6 +43,7 @@ async fn main() {
|
||||
}
|
||||
|
||||
pub async fn meteo_weather(latitude: f64, longitude: f64) -> Result<MucWeather, reqwest::Error> {
|
||||
|
||||
let response = trpl::get(METEO_MUNICH_API_URL).await;
|
||||
let response_text = response.text().await;
|
||||
|
||||
@@ -51,14 +52,14 @@ pub async fn meteo_weather(latitude: f64, longitude: f64) -> Result<MucWeather,
|
||||
let mut humidity = 0.0;
|
||||
let mut pressure = 0.0;
|
||||
let mut precipitation = 0.0;
|
||||
|
||||
let profilwerte = Selector::parse("#messwerte-profilwerte").unwrap();
|
||||
let winddruck = Selector::parse("#messwerte-winddruck").unwrap();
|
||||
let niederschlag = Selector::parse("#messwerte-niederschlag").unwrap();
|
||||
|
||||
let profile_selector = Selector::parse("#messwerte-profilwerte").unwrap();
|
||||
let pressure_selector = Selector::parse("#messwerte-winddruck").unwrap();
|
||||
let precipitation_selector = Selector::parse("#messwerte-niederschlag").unwrap();
|
||||
let row_selector = Selector::parse("tr").unwrap();
|
||||
let cell_selector = Selector::parse("td").unwrap();
|
||||
|
||||
if let Some(table) = fragment.select(&profilwerte).next() {
|
||||
if let Some(table) = fragment.select(&profile_selector).next() {
|
||||
for row in table.select(&row_selector) {
|
||||
let mut row_data = Vec::new();
|
||||
for cell in row.select(&cell_selector) {
|
||||
@@ -74,7 +75,7 @@ pub async fn meteo_weather(latitude: f64, longitude: f64) -> Result<MucWeather,
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(table) = fragment.select(&winddruck).next() {
|
||||
if let Some(table) = fragment.select(&pressure_selector).next() {
|
||||
for row in table.select(&row_selector) {
|
||||
let mut row_data = Vec::new();
|
||||
for cell in row.select(&cell_selector) {
|
||||
@@ -87,7 +88,7 @@ pub async fn meteo_weather(latitude: f64, longitude: f64) -> Result<MucWeather,
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(table) = fragment.select(&niederschlag).next() {
|
||||
if let Some(table) = fragment.select(&precipitation_selector).next() {
|
||||
for row in table.select(&row_selector) {
|
||||
let mut row_data = Vec::new();
|
||||
for cell in row.select(&cell_selector) {
|
||||
@@ -99,13 +100,13 @@ pub async fn meteo_weather(latitude: f64, longitude: f64) -> Result<MucWeather,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if temperature == 999.0 {
|
||||
let url = format!(
|
||||
"https://api.brightsky.dev/current_weather?lat={}&lon={}",
|
||||
latitude, longitude
|
||||
);
|
||||
println!("Fetching {}", url);
|
||||
println!("Fetching DWD {}", url);
|
||||
let result = trpl::get(&url).await.text().await;
|
||||
let dwd_weather: DwdWeather = serde_json::from_str(&result).unwrap();
|
||||
temperature = dwd_weather.weather.temperature.unwrap();
|
||||
@@ -114,64 +115,43 @@ pub async fn meteo_weather(latitude: f64, longitude: f64) -> Result<MucWeather,
|
||||
precipitation = dwd_weather.weather.precipitation;
|
||||
}
|
||||
|
||||
let precipitation = (precipitation * 100.0).round() / 100.00;
|
||||
let cur_date = Local::now();
|
||||
let cur_date_formatted = format!("{}", cur_date.format("%Y-%m-%d %H:%M"));
|
||||
let weather = MucWeather {
|
||||
temperature,
|
||||
pressure,
|
||||
humidity,
|
||||
precipitation,
|
||||
date: cur_date_formatted
|
||||
};
|
||||
println!("Zeile: {:?}", weather);
|
||||
Ok(weather)
|
||||
}
|
||||
|
||||
async fn publish(client: AsyncClient, muc: &MucWeather) {
|
||||
// Serialize it to a JSON string.
|
||||
|
||||
let json = serde_json::to_string(&muc);
|
||||
client
|
||||
.publish("munich/weather", QoS::AtLeastOnce, false, json.unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
client
|
||||
.publish(
|
||||
"munich/temperature",
|
||||
QoS::AtLeastOnce,
|
||||
false,
|
||||
muc.temperature.to_string(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
client
|
||||
.publish(
|
||||
"munich/pressure",
|
||||
QoS::AtLeastOnce,
|
||||
false,
|
||||
muc.pressure.to_string(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
client
|
||||
.publish(
|
||||
"munich/humidity",
|
||||
QoS::AtLeastOnce,
|
||||
false,
|
||||
muc.humidity.to_string(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
client
|
||||
.publish(
|
||||
"munich/precipitation",
|
||||
QoS::AtLeastOnce,
|
||||
false,
|
||||
muc.precipitation.to_string(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
publish_topic(client.clone(), "munich/weather", json.unwrap()).await;
|
||||
publish_topic(client.clone(), "munich/temperature", muc.temperature.to_string()).await;
|
||||
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;
|
||||
}
|
||||
|
||||
async fn publish_topic(client: AsyncClient, topic: &str, value: String) {
|
||||
client
|
||||
.publish(
|
||||
topic,
|
||||
QoS::AtLeastOnce,
|
||||
false,
|
||||
value,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn create_conn() -> (AsyncClient, EventLoop) {
|
||||
let mut mqttoptions = MqttOptions::new("rust-mqqt", "192.168.1.37", 1883);
|
||||
mqttoptions
|
||||
|
||||
@@ -10,6 +10,8 @@ pub struct MucWeather {
|
||||
pub(crate) pressure: f64,
|
||||
#[serde(rename = "Precipitation")]
|
||||
pub(crate) precipitation: f64,
|
||||
#[serde(rename = "Date")]
|
||||
pub(crate) date: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user