Cleaning up API
This commit is contained in:
parent
5c4ba78dd1
commit
1f8f63018a
@ -2,8 +2,6 @@ use crate::hardware::{
|
|||||||
design_parameters::MQTT_BROKER, CycleCounter, EthernetPhy, NetworkStack,
|
design_parameters::MQTT_BROKER, CycleCounter, EthernetPhy, NetworkStack,
|
||||||
};
|
};
|
||||||
|
|
||||||
use core::fmt::Write;
|
|
||||||
|
|
||||||
use heapless::{consts, String};
|
use heapless::{consts, String};
|
||||||
|
|
||||||
use super::{Action, MqttMessage, SettingsResponse};
|
use super::{Action, MqttMessage, SettingsResponse};
|
||||||
@ -46,13 +44,11 @@ where
|
|||||||
minimq::MqttClient::new(MQTT_BROKER.into(), client_id, stack)
|
minimq::MqttClient::new(MQTT_BROKER.into(), client_id, stack)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut response_topic: String<consts::U128> = String::new();
|
let mut response_topic: String<consts::U128> = String::from(prefix);
|
||||||
write!(&mut response_topic, "{}/log", prefix).unwrap();
|
response_topic.push_str("/log").unwrap();
|
||||||
|
|
||||||
let mut settings_prefix: String<consts::U64> = String::new();
|
let mut settings_prefix: String<consts::U64> = String::from(prefix);
|
||||||
write!(&mut settings_prefix, "{}/settings", prefix).unwrap();
|
settings_prefix.push_str("/settings").unwrap();
|
||||||
|
|
||||||
// Ensure we have two remaining spaces
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
mqtt,
|
mqtt,
|
||||||
@ -83,16 +79,17 @@ where
|
|||||||
|
|
||||||
// If the PHY indicates there's no more ethernet link, reset the DHCP server in the network
|
// If the PHY indicates there's no more ethernet link, reset the DHCP server in the network
|
||||||
// stack.
|
// stack.
|
||||||
if self.phy.poll_link() == false {
|
match self.phy.poll_link() {
|
||||||
|
true => self.network_was_reset = false,
|
||||||
|
|
||||||
// Only reset the network stack once per link reconnection. This prevents us from
|
// Only reset the network stack once per link reconnection. This prevents us from
|
||||||
// sending an excessive number of DHCP requests.
|
// sending an excessive number of DHCP requests.
|
||||||
if !self.network_was_reset {
|
false if !self.network_was_reset => {
|
||||||
self.network_was_reset = true;
|
self.network_was_reset = true;
|
||||||
self.mqtt.network_stack.handle_link_reset();
|
self.mqtt.network_stack.handle_link_reset();
|
||||||
}
|
}
|
||||||
} else {
|
_ => {},
|
||||||
self.network_was_reset = false;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
let mqtt_connected = match self.mqtt.is_connected() {
|
let mqtt_connected = match self.mqtt.is_connected() {
|
||||||
Ok(connected) => connected,
|
Ok(connected) => connected,
|
||||||
@ -160,6 +157,8 @@ where
|
|||||||
.publish(
|
.publish(
|
||||||
response.topic,
|
response.topic,
|
||||||
&response.message,
|
&response.message,
|
||||||
|
// TODO: When Minimq supports more QoS levels, this should be increased to
|
||||||
|
// ensure that the client has received it at least once.
|
||||||
minimq::QoS::AtMostOnce,
|
minimq::QoS::AtMostOnce,
|
||||||
&response.properties,
|
&response.properties,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user