diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index 9729d3c..59bf76e 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -349,21 +349,29 @@ fn publish_to_mqtt(client: &Client, data: &Option>, str if let Some(f) = forecast.list.first() { let temp = f.main.temp; let weather = f.weather.get(0).map(|w| w.main.clone()).unwrap_or_default(); - format!("temp:{:.1}C,weather:{},out:{}min,in:{}min", + format!("temp:{:.1}C,weather:{}", temp, - weather, - straba_res.outbound_diff / 60, - straba_res.inbound_diff / 60) - } else { + weather) + } else { "no_forecast".to_string() } } else { "no_data".to_string() }; - let msg = Message::new("ledboard/data", payload, 1); + let msg = Message::new("ledboard/forecast", payload, 1); if let Err(e) = client.publish(msg) { eprintln!("Error publishing MQTT message: {}", e); } + + let payloadPT = { + format!("out:{}min,in:{}min", + straba_res.outbound_diff / 60, + straba_res.inbound_diff / 60) + }; + let ptmsg = Message::new("ledboard/public_transportation", payloadPT, 1); + if let Err(e) = client.publish(ptmsg) { + eprintln!("Error publishing MQTT message: {}", e); + } } fn main() -> ExitCode { @@ -383,9 +391,11 @@ fn main() -> ExitCode { let mut device_online = check_connection(ip.to_string()); if !device_online { println!("{} not online", ip); - return ExitCode::FAILURE; + // return ExitCode::FAILURE; } + + let receiver = openweathermap::init_forecast("Mannheim", "metric", "de", @@ -398,7 +408,7 @@ fn main() -> ExitCode { let mut straba_res = straba::fetch_data(Some(true)); println!("{:?} {:?}s", straba_res.outbound_station, straba_res.outbound_diff); println!("{:?} {:?}s", straba_res.inbound_station , straba_res.inbound_diff); - + // Initialize MQTT client from MQTT_BROKER env var (else disabled) let mqtt_client: Option = { // Read broker URL from environment @@ -472,10 +482,11 @@ fn main() -> ExitCode { // Render new image send_package(ip.to_string(), &last_data, &straba_res); // Publish data to MQTT - if let Some(ref client) = mqtt_client { + } + if let Some(ref client) = mqtt_client { publish_to_mqtt(client, &last_data, &straba_res); } - } + } } // all the other cases