From aad026161f97aedb103f718a37fe6ceb84e5d060 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 29 Apr 2021 11:28:35 +0200 Subject: [PATCH] Refactoring to support DHCP --- Cargo.lock | 4 ++-- Cargo.toml | 6 +++--- src/net/mqtt_interface.rs | 19 +++++++++++++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a002739..aef5a92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -427,7 +427,7 @@ dependencies = [ [[package]] name = "minimq" version = "0.2.0" -source = "git+https://github.com/quartiq/minimq.git?branch=rs/issue-40/copyable-properties#c95c758b620ee98752852bb643df8557a7200f3f" +source = "git+https://github.com/quartiq/minimq.git?rev=b3f364d#b3f364d55dea35da6572f78ddb91c87bfbb453bf" dependencies = [ "bit_field", "embedded-nal", @@ -690,7 +690,7 @@ dependencies = [ [[package]] name = "serde-json-core" version = "0.2.0" -source = "git+https://github.com/quartiq/serde-json-core.git?branch=feature/dependency-update#a304506a1efb4a90a6ef3faf71ec3ef5f8433fb4" +source = "git+https://github.com/rust-embedded-community/serde-json-core.git?rev=da460d1#da460d123e217f0e822a3977eb2170ed5d279d5e" dependencies = [ "heapless 0.6.1", "ryu", diff --git a/Cargo.toml b/Cargo.toml index 095fb74..4ab885e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,11 +64,11 @@ rev = "8468f11" [dependencies.minimq] git = "https://github.com/quartiq/minimq.git" -branch = "rs/issue-40/copyable-properties" +rev = "b3f364d" [patch.crates-io.serde-json-core] -git = "https://github.com/quartiq/serde-json-core.git" -branch = "feature/dependency-update" +git = "https://github.com/rust-embedded-community/serde-json-core.git" +rev = "da460d1" [features] semihosting = ["panic-semihosting", "cortex-m-log/semihosting"] diff --git a/src/net/mqtt_interface.rs b/src/net/mqtt_interface.rs index bcc6ae7..374714d 100644 --- a/src/net/mqtt_interface.rs +++ b/src/net/mqtt_interface.rs @@ -22,7 +22,7 @@ where phy: EthernetPhy, network_was_reset: bool, subscribed: bool, - id: String, + id: String, } impl MqttInterface @@ -99,9 +99,24 @@ where self.network_was_reset = false; } + let mqtt_connected = match self.mqtt.borrow_mut().is_connected() { + Ok(connected) => connected, + Err(minimq::Error::Network( + smoltcp_nal::NetworkError::NoIpAddress, + )) => false, + Err(minimq::Error::Network(error)) => { + log::info!("Unexpected network error: {:?}", error); + false + } + Err(error) => { + log::warn!("Unexpected MQTT error: {:?}", error); + false + } + }; + // If we're no longer subscribed to the settings topic, but we are connected to the broker, // resubscribe. - if !self.subscribed && self.mqtt.borrow_mut().is_connected().unwrap() { + if !self.subscribed && mqtt_connected { let mut settings_topic: String = String::new(); write!(&mut settings_topic, "{}/settings/#", self.id.as_str()) .unwrap();