Publish in seperate MQTT topics

This commit is contained in:
Ollo
2026-02-27 21:44:38 +01:00
parent 1da8bb5420
commit 12c7a05b91

View File

@@ -51,14 +51,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
"Inbound: {} in {} seconds",
departure_data.inbound_station, departure_data.inbound_diff
);
client
.publish("departure/outbound", QoS::AtLeastOnce, false, outbound_msg.as_bytes())
.await?;
client
.publish("departure/inbound", QoS::AtLeastOnce, false, inbound_msg.as_bytes())
.await?;
println!("{}", outbound_msg);
println!("{}", inbound_msg);
}
@@ -69,7 +61,23 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(Event::Incoming(Packet::ConnAck(_))) => {
println!("Connected to MQTT broker");
}
Ok(_) => {}
Ok(_) => {
client
.publish("departure/outbound/station", QoS::AtLeastOnce, false, departure_data.outbound_station.as_bytes())
.await?;
client
.publish("departure/outbound/diff", QoS::AtLeastOnce, false, format!("{}", departure_data.outbound_diff))
.await?;
client
.publish("departure/inbound/station", QoS::AtLeastOnce, false, departure_data.inbound_station.as_bytes())
.await?;
client
.publish("departure/inbound/diff", QoS::AtLeastOnce, false, format!("{}", departure_data.inbound_diff))
.await?;
}
Err(e) => {
println!("Error: {:?}", e);
sleep(Duration::from_secs(1)).await;