Publish in seperate MQTT topics
This commit is contained in:
26
src/main.rs
26
src/main.rs
@@ -51,14 +51,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
"Inbound: {} in {} seconds",
|
"Inbound: {} in {} seconds",
|
||||||
departure_data.inbound_station, departure_data.inbound_diff
|
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!("{}", outbound_msg);
|
||||||
println!("{}", inbound_msg);
|
println!("{}", inbound_msg);
|
||||||
}
|
}
|
||||||
@@ -69,7 +61,23 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
Ok(Event::Incoming(Packet::ConnAck(_))) => {
|
Ok(Event::Incoming(Packet::ConnAck(_))) => {
|
||||||
println!("Connected to MQTT broker");
|
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) => {
|
Err(e) => {
|
||||||
println!("Error: {:?}", e);
|
println!("Error: {:?}", e);
|
||||||
sleep(Duration::from_secs(1)).await;
|
sleep(Duration::from_secs(1)).await;
|
||||||
|
|||||||
Reference in New Issue
Block a user