more MQTT printf debugging
This commit is contained in:
@@ -404,6 +404,7 @@ fn check_connection(ipaddress: String) -> bool {
|
||||
}
|
||||
/// Publishes weather and transit data to MQTT broker
|
||||
fn publish_to_mqtt(client: &Client, data: &Option<Result<Forecast, String>>, straba_res: &NextDeparture) {
|
||||
|
||||
let payload = if let Some(Ok(forecast)) = data {
|
||||
if let Some(f) = forecast.list.first() {
|
||||
let temp = f.main.temp;
|
||||
@@ -417,20 +418,28 @@ fn publish_to_mqtt(client: &Client, data: &Option<Result<Forecast, String>>, str
|
||||
} else {
|
||||
"no_data".to_string()
|
||||
};
|
||||
let msg = MqttMessage::new("ledboard/forecast", payload, 1);
|
||||
let msg = MqttMessage::new("ledboard/forecast", payload.clone(), 1);
|
||||
if let Err(e) = client.publish(msg) {
|
||||
eprintln!("Error publishing MQTT message: {}", e);
|
||||
}
|
||||
else
|
||||
{
|
||||
println!("MQTT | Publish {0} = {1}", "ledboard/forecast", payload.clone());
|
||||
}
|
||||
|
||||
let payloadPT = {
|
||||
format!("out:{}min,in:{}min",
|
||||
straba_res.outbound_diff / 60,
|
||||
straba_res.inbound_diff / 60)
|
||||
};
|
||||
let ptmsg = MqttMessage::new("ledboard/public_transportation", payloadPT, 1);
|
||||
let ptmsg = MqttMessage::new("ledboard/public_transportation", payloadPT.clone(), 1);
|
||||
if let Err(e) = client.publish(ptmsg) {
|
||||
eprintln!("Error publishing MQTT message: {}", e);
|
||||
}
|
||||
else
|
||||
{
|
||||
println!("MQTT | Publish {0} = {1}", "ledboard/public_transportation", payloadPT.clone());
|
||||
}
|
||||
}
|
||||
|
||||
struct Message {
|
||||
@@ -542,7 +551,6 @@ fn main_function(parameter1: String, parameter2: Option<String>) -> ExitCode {
|
||||
};
|
||||
|
||||
// Define the set of options for the connection
|
||||
|
||||
// move local instance to global scope
|
||||
gmc.set_mqtt_client(mqtt_client);
|
||||
}
|
||||
@@ -565,11 +573,18 @@ fn main_function(parameter1: String, parameter2: Option<String>) -> ExitCode {
|
||||
// Render start
|
||||
send_package(GlobalConfiguration.lock().unwrap().panelIPAddress.clone(), &last_data, &straba_res, Some("MQTT: room/ledboard".to_string()));
|
||||
}
|
||||
|
||||
|
||||
if GlobalConfiguration.lock().is_ok() && GlobalConfiguration.lock().unwrap().mqttPrefix.len() > 0
|
||||
else
|
||||
{
|
||||
if let Some(ref client) = &(MQTTCLIENT.lock().unwrap().get_mqtt_client()) {
|
||||
println!("PANEL | No Panel updated");
|
||||
}
|
||||
|
||||
if GlobalConfiguration.lock().is_ok()
|
||||
{
|
||||
let l_mqtt_prefix = &GlobalConfiguration.lock().unwrap().mqttPrefix;
|
||||
println!("MQTT | Publish to {0}", l_mqtt_prefix);
|
||||
|
||||
if let Some(ref client) = MQTTCLIENT.lock().unwrap().get_mqtt_client() {
|
||||
println!("MQTT | Client is {0:?}", client.client_id());
|
||||
publish_to_mqtt(client, &last_data, &straba_res);
|
||||
}
|
||||
else
|
||||
@@ -577,6 +592,10 @@ fn main_function(parameter1: String, parameter2: Option<String>) -> ExitCode {
|
||||
eprintln!("MQTT | client for publishing not found");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
println!("MQTT | No Topic updated");
|
||||
}
|
||||
|
||||
|
||||
loop {
|
||||
|
||||
Reference in New Issue
Block a user