From 0ba325937404300a5f581d62e12108f293719b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Thu, 24 Jun 2021 14:36:17 +0000 Subject: [PATCH] network: add some useful log messages --- src/net/data_stream.rs | 8 +++----- src/net/miniconf_client.rs | 5 ++++- src/net/network_processor.rs | 12 ++++++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/net/data_stream.rs b/src/net/data_stream.rs index 61bceba..fc8aaf7 100644 --- a/src/net/data_stream.rs +++ b/src/net/data_stream.rs @@ -271,6 +271,7 @@ impl DataStream { } fn close(&mut self) { + log::info!("Closing stream"); // Note(unwrap): We guarantee that the socket is available above. let socket = self.socket.take().unwrap(); self.stack.close(socket).unwrap(); @@ -281,17 +282,14 @@ impl DataStream { self.close(); } - // If the remote address is unspecified, just close the existing socket. + // If the remote address is unspecified, don't open a new socket. if remote.ip().is_unspecified() { - if self.socket.is_some() { - self.close(); - } - return Err(()); } let mut socket = self.stack.socket().map_err(|_| ())?; + log::info!("Opening stream"); // Note(unwrap): We only connect with a new socket, so it is guaranteed to not already be // bound. self.stack.connect(&mut socket, remote).unwrap(); diff --git a/src/net/miniconf_client.rs b/src/net/miniconf_client.rs index 4eaab07..4bdd2b1 100644 --- a/src/net/miniconf_client.rs +++ b/src/net/miniconf_client.rs @@ -80,6 +80,7 @@ where // If we're no longer subscribed to the settings topic, but we are connected to the broker, // resubscribe. if !self.subscribed && mqtt_connected { + log::info!("MQTT connected, subscribing to settings"); // Note(unwrap): We construct a string with two more characters than the prefix // strucutre, so we are guaranteed to have space for storage. let mut settings_topic: String<66> = @@ -115,6 +116,8 @@ where } }; + log::info!("Settings update: `{}`", path); + let message: SettingsResponse = settings .string_set(path.split('/').peekable(), message) .map(|_| { @@ -140,13 +143,13 @@ where Ok(_) if update => UpdateState::Updated, Ok(_) => UpdateState::NoChange, Err(minimq::Error::SessionReset) => { + log::warn!("Settings MQTT session reset"); self.subscribed = false; UpdateState::NoChange } Err(minimq::Error::Network( smoltcp_nal::NetworkError::NoIpAddress, )) => UpdateState::NoChange, - Err(error) => { log::info!("Unexpected error: {:?}", error); UpdateState::NoChange diff --git a/src/net/network_processor.rs b/src/net/network_processor.rs index 13f7035..eeb4f06 100644 --- a/src/net/network_processor.rs +++ b/src/net/network_processor.rs @@ -45,12 +45,16 @@ impl NetworkProcessor { pub fn handle_link(&mut self) { // If the PHY indicates there's no more ethernet link, reset the DHCP server in the network // stack. - match self.phy.poll_link() { - true => self.network_was_reset = false, - + let link_up = self.phy.poll_link(); + match (link_up, self.network_was_reset) { + (true, true) => { + log::warn!("Network link UP"); + self.network_was_reset = false; + } // Only reset the network stack once per link reconnection. This prevents us from // sending an excessive number of DHCP requests. - false if !self.network_was_reset => { + (false, false) => { + log::warn!("Network link DOWN"); self.network_was_reset = true; self.stack.lock(|stack| stack.handle_link_reset()); }