Hacked MQTT output without panel

This commit is contained in:
Ollo 2025-04-26 15:41:24 +02:00
parent 06ce74da9f
commit fbdf1ea24b

View File

@ -349,21 +349,29 @@ fn publish_to_mqtt(client: &Client, data: &Option<Result<Forecast, String>>, str
if let Some(f) = forecast.list.first() { if let Some(f) = forecast.list.first() {
let temp = f.main.temp; let temp = f.main.temp;
let weather = f.weather.get(0).map(|w| w.main.clone()).unwrap_or_default(); 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, temp,
weather, weather)
straba_res.outbound_diff / 60, } else {
straba_res.inbound_diff / 60)
} else {
"no_forecast".to_string() "no_forecast".to_string()
} }
} else { } else {
"no_data".to_string() "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) { if let Err(e) = client.publish(msg) {
eprintln!("Error publishing MQTT message: {}", e); 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 { fn main() -> ExitCode {
@ -383,9 +391,11 @@ fn main() -> ExitCode {
let mut device_online = check_connection(ip.to_string()); let mut device_online = check_connection(ip.to_string());
if !device_online { if !device_online {
println!("{} not online", ip); println!("{} not online", ip);
return ExitCode::FAILURE; // return ExitCode::FAILURE;
} }
let receiver = openweathermap::init_forecast("Mannheim", let receiver = openweathermap::init_forecast("Mannheim",
"metric", "metric",
"de", "de",
@ -398,7 +408,7 @@ fn main() -> ExitCode {
let mut straba_res = straba::fetch_data(Some(true)); let mut straba_res = straba::fetch_data(Some(true));
println!("{:?} {:?}s", straba_res.outbound_station, straba_res.outbound_diff); println!("{:?} {:?}s", straba_res.outbound_station, straba_res.outbound_diff);
println!("{:?} {:?}s", straba_res.inbound_station , straba_res.inbound_diff); println!("{:?} {:?}s", straba_res.inbound_station , straba_res.inbound_diff);
// Initialize MQTT client from MQTT_BROKER env var (else disabled) // Initialize MQTT client from MQTT_BROKER env var (else disabled)
let mqtt_client: Option<Client> = { let mqtt_client: Option<Client> = {
// Read broker URL from environment // Read broker URL from environment
@ -472,10 +482,11 @@ fn main() -> ExitCode {
// Render new image // Render new image
send_package(ip.to_string(), &last_data, &straba_res); send_package(ip.to_string(), &last_data, &straba_res);
// Publish data to MQTT // 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); publish_to_mqtt(client, &last_data, &straba_res);
} }
}
} }
} }
// all the other cases // all the other cases