Made tls optional
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Dreaded_X 2023-01-17 18:12:03 +01:00
parent 90eedbf86e
commit 614b4b5e43
Signed by: Dreaded_X
GPG Key ID: 76BDEC4E165D8AD9
4 changed files with 8 additions and 1 deletions

View File

@ -6,6 +6,7 @@ host="olympus.vpn.huizinga.dev"
port=8883
username="mqtt"
password="${MQTT_PASSWORD}"
tls=true
[ntfy]
topic = "${NTFY_TOPIC}"

View File

@ -6,6 +6,7 @@ host="olympus.lan.huizinga.dev"
port=8883
username="mqtt"
password="${MQTT_PASSWORD}"
tls=true
[ntfy]
topic = "${NTFY_TOPIC}"

View File

@ -34,6 +34,8 @@ pub struct MqttConfig {
pub port: u16,
pub username: String,
pub password: String,
#[serde(default)]
pub tls: bool
}
#[derive(Debug, Deserialize)]

View File

@ -64,7 +64,10 @@ async fn app() -> Result<(), Box<dyn std::error::Error>> {
let mut mqttoptions = MqttOptions::new("rust-test", mqtt.host, mqtt.port);
mqttoptions.set_credentials(mqtt.username, mqtt.password);
mqttoptions.set_keep_alive(Duration::from_secs(5));
mqttoptions.set_transport(Transport::tls_with_default_config());
if mqtt.tls {
mqttoptions.set_transport(Transport::tls_with_default_config());
}
// Create a mqtt client and wrap the eventloop
let (client, eventloop) = AsyncClient::new(mqttoptions, 10);