Skip to content

Commit

Permalink
telemetry module: actually enable MQTT connection and remove config file
Browse files Browse the repository at this point in the history
  • Loading branch information
DanNixon committed Dec 3, 2024
1 parent d187bd2 commit 7847a8a
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 178 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/telemetry-module-firmware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ jobs:

- name: Clippy
env:
CONFIG: ./config.toml
WIFI_PASSWORD: "loool dont steal me"
MQTT_PASSWORD: "not real"
run: |
eval "$(nix print-dev-env)"
set -x
Expand All @@ -56,7 +57,8 @@ jobs:

- name: Build
env:
CONFIG: ./config.toml
WIFI_PASSWORD: "loool dont steal me"
MQTT_PASSWORD: "not real"
run: |
eval "$(nix print-dev-env)"
set -x
Expand Down
54 changes: 0 additions & 54 deletions telemetry-module/firmware/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions telemetry-module/firmware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ display-interface-spi = "0.5.0"
rust-mqtt = { version = "0.3.0", default-features = false, features = ["defmt"] }
serde-json-core = { version = "0.6.0", features = ["defmt"] }

[build-dependencies]
serde = { version = "1.0.215", features = ["derive"] }
toml = "0.8.19"

[profile.release]
debug = 2
lto = true
Expand Down
48 changes: 0 additions & 48 deletions telemetry-module/firmware/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//! updating `memory.x` ensures a rebuild of the application with the
//! new memory settings.
use serde::Deserialize;
use std::env;
use std::fs::File;
use std::io::Write;
Expand All @@ -34,51 +33,4 @@ fn main() {
println!("cargo:rustc-link-arg-bins=-Tlink.x");
println!("cargo:rustc-link-arg-bins=-Tlink-rp.x");
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");

// Load the config for the specific controller and set the required environment variables
Config::load_and_set();
}

#[derive(Deserialize)]
struct Config {
wifi_ssid: String,
wifi_password: String,

mqtt_broker_url: String,
mqtt_client_id: String,

online_mqtt_topic: String,
version_mqtt_topic: String,
telemetry_mqtt_topic: String,
}

impl Config {
fn load_and_set() {
let config = Self::load(env!("CONFIG"));
config.set_env_vars();
}

fn load(filename: &str) -> Self {
let config = std::fs::read_to_string(filename).unwrap();
toml::from_str(&config).unwrap()
}

fn set_env_vars(&self) {
println!("cargo::rustc-env=WIFI_SSID={}", self.wifi_ssid);
println!("cargo::rustc-env=WIFI_PASSWORD={}", self.wifi_password);
println!("cargo::rustc-env=MQTT_BROKER_URL={}", self.mqtt_broker_url);
println!("cargo::rustc-env=MQTT_CLIENT_ID={}", self.mqtt_client_id);
println!(
"cargo::rustc-env=ONLINE_MQTT_TOPIC={}",
self.online_mqtt_topic
);
println!(
"cargo::rustc-env=VERSION_MQTT_TOPIC={}",
self.version_mqtt_topic
);
println!(
"cargo::rustc-env=TELEMETRY_MQTT_TOPIC={}",
self.telemetry_mqtt_topic
);
}
}
9 changes: 0 additions & 9 deletions telemetry-module/firmware/config.toml

This file was deleted.

41 changes: 21 additions & 20 deletions telemetry-module/firmware/src/display/screens/network.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::display::{
drawables::{
info_pane_background::REGION,
measurement::{Measurement, Severity},
subtitle::Subtitle,
use crate::{
display::{
drawables::{
info_pane_background::REGION,
measurement::{Measurement, Severity},
subtitle::Subtitle,
},
state::DisplayDataState,
},
state::DisplayDataState,
wifi::MQTT_BROKER_IP,
};
use core::fmt::Write;
use embedded_graphics::{
Expand Down Expand Up @@ -99,30 +102,28 @@ impl Drawable for Network<'_> {
cursor,
value_offset,
"State",
Some(match self.state.mqtt_broker_address {
Some(_) => "Connected",
None => "Disconnected",
Some(match self.state.mqtt_broker_connected {
true => "Connected",
false => "Disconnected",
}),
Some(match self.state.mqtt_broker_address {
Some(_) => Severity::Normal,
None => Severity::Critical,
Some(match self.state.mqtt_broker_connected {
true => Severity::Normal,
false => Severity::Critical,
}),
)
.draw(target)?;

// MQTT broker IP address
let mqtt_broker_ip_str = {
let mut s = heapless::String::<16>::new();
s.write_fmt(format_args!("{}", MQTT_BROKER_IP)).unwrap();
s
};
Measurement::new(
cursor,
value_offset,
"Brkr",
self.state
.mqtt_broker_address
.map(|addr| {
let mut s = heapless::String::<16>::new();
s.write_fmt(format_args!("{}", addr)).unwrap();
s
})
.as_deref(),
Some(&mqtt_broker_ip_str),
None,
)
.draw(target)?;
Expand Down
10 changes: 5 additions & 5 deletions telemetry-module/firmware/src/display/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use defmt::warn;
use embassy_futures::select::{select, Either};
use embassy_net::{IpAddress, StaticConfigV4};
use embassy_net::StaticConfigV4;
use embassy_sync::{
blocking_mutex::raw::CriticalSectionRawMutex, pubsub::WaitResult, signal::Signal,
};
Expand All @@ -29,7 +29,7 @@ use hoshiguma_telemetry_protocol::{
pub(crate) struct DisplayDataState {
// Networking
pub(crate) ipv4_config: Option<StaticConfigV4>,
pub(crate) mqtt_broker_address: Option<IpAddress>,
pub(crate) mqtt_broker_connected: bool,

// Controller system
pub(crate) controller_git_rev: Option<TelemString>,
Expand Down Expand Up @@ -72,11 +72,11 @@ pub(crate) async fn task() {
NetworkEvent::NetworkConnected(ip_config) => {
state.ipv4_config = Some(ip_config);
}
NetworkEvent::MqttBrokerConnected(broker_address) => {
state.mqtt_broker_address = Some(broker_address);
NetworkEvent::MqttBrokerConnected => {
state.mqtt_broker_connected = true;
}
NetworkEvent::MqttBrokerDisconnected => {
state.mqtt_broker_address = None;
state.mqtt_broker_connected = false;
}
},
Either::Second(msg) => {
Expand Down
Loading

0 comments on commit 7847a8a

Please sign in to comment.