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() {
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)
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",
@ -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 {
publish_to_mqtt(client, &last_data, &straba_res);
}
}
}
}
// all the other cases