Fix: ignore dublicated uuids

This commit is contained in:
Dorian Zedler 2023-02-17 12:15:04 +01:00
parent e9f72cf791
commit 5b2aefe659
Signed by: dorian
GPG key ID: 989DE36109AFA354

View file

@ -25,6 +25,7 @@ pub struct Comm {
handler: TimeCallback,
crypto: Crypto,
topic: String,
last_uuids: RefCell<Vec<uuid::Uuid>>
}
impl Comm {
@ -36,9 +37,11 @@ impl Comm {
let mut create_opts =
mqtt::MqttOptions::new(uuid::Uuid::new_v4().to_string(), broker_domain, 8883);
create_opts.set_keep_alive(Duration::from_secs(5));
let transport = mqtt::Transport::Tls(mqtt::TlsConfiguration::default());
create_opts.set_transport(transport);
let (mut cli, conn) = mqtt::Client::new(create_opts, 10);
let (mut cli, conn) = mqtt::Client::new(create_opts, 10);
let crypto = Crypto::new(password, broker_domain);
@ -53,6 +56,7 @@ impl Comm {
handler,
crypto,
topic,
last_uuids: RefCell::new(Vec::new())
})
}
@ -95,6 +99,12 @@ impl Comm {
return;
}
if self.last_uuids.borrow().contains(&msg.id) {
return;
}
self.last_uuids.borrow_mut().push(msg.id);
if (self.handler)(msg.time).is_err() {
println!("[WARN] error in time handler -> not sending confirmation");
return;