feat: systemd unit, simple install script, clean up todos

This commit is contained in:
janishutz committed 2026-08-25 10:57:49 +02:00
1 parent 760895bb5c
commit 563134b0fe
5 files changed
+25 -12

No files matched your search

-2
View File
@@ -6,8 +6,6 @@ mqtt:
password: "234"
user: "mqtt"
# TODO: Consider adding an auto-off setting for out mode
# Add default setting (also only for out)
topics:
- topic: "" # The pin id is appended as /<id> to the topic.
pin: 0
Executable
+5
View File
@@ -0,0 +1,5 @@
#!/bin/sh
cargo install
sudo cp ./config.yml /etc/mqtt-remote-gpio.config.yml
sudo cp ./mqtt-remote-gpio.service /etc/systemd/system/
+7
View File
@@ -0,0 +1,7 @@
[Service]
Type=simple
ExecStart=/usr/bin/mqtt-remote-gpio
[Unit]
Restart=always
RestartSec=10
+13 -7
View File
@@ -1,17 +1,23 @@
use std::fs;
mod conf;
mod gpio_utils;
mod mqtt;
fn main() {
// TODO: Proper cli interface and start screen
// CLI interface should allow setting the config file
println!("mqtt-remote-gpio");
println!(r"
__ _ _ _ _ __ _ _ __ _
_ __ / _` || |_ | |_ _ _ ___ _ __ ___ | |_ ___ / _` || '_ \(_) ___
| ' \ \__. || _|| _| | '_|/ -_)| ' \ / _ \| _|/ -_) \__. || .__/| |/ _ \
|_|_|_| |_| \__| \__| |_| \___||_|_|_|\___/ \__|\___| |___/ |_| |_|\___/
");
// let config = conf::load_config("config.yml").unwrap();
let config = conf::load_config("config.secret.yml").unwrap();
let mut conf_path = std::env::args().nth(1).unwrap_or("config.yml".to_string());
if fs::exists(conf_path).unwrap_or(false) {
conf_path = "/etc/mqtt-remote-gpio.config.yml".to_string();
}
// TODO: Remove this when done
println!("{:#?}", config);
let config = conf::load_config(&conf_path).unwrap();
mqtt::handler(config);
}
-3
View File
@@ -36,7 +36,6 @@ pub fn handler(config: Config) {
loop {
let mut i = 0;
for topic in input_pins.iter_mut() {
// TODO: handle fails
let val = read_pin(&mut topic.gpio);
if val != pin_state[i] {
pin_state[i] = val;
@@ -65,8 +64,6 @@ pub fn handler(config: Config) {
controller.handle_event(&content);
}
}
// println!("Notification {:?}", msg);
thread::sleep(Duration::from_millis(config.poll_interval / 2));
// TODO: Handle pin value change instructions
}
}