mirror of
https://github.com/janishutz/mqtt-remote-gpio.git
synced 2026-10-08 20:56:22 +02:00
feat: systemd unit, simple install script, clean up todos
This commit is contained in:
1 parent
760895bb5c
commit
563134b0fe
5 files changed
+25
-12
No files matched your search
@@ -6,8 +6,6 @@ mqtt:
|
|||||||
password: "234"
|
password: "234"
|
||||||
user: "mqtt"
|
user: "mqtt"
|
||||||
|
|
||||||
# TODO: Consider adding an auto-off setting for out mode
|
|
||||||
# Add default setting (also only for out)
|
|
||||||
topics:
|
topics:
|
||||||
- topic: "" # The pin id is appended as /<id> to the topic.
|
- topic: "" # The pin id is appended as /<id> to the topic.
|
||||||
pin: 0
|
pin: 0
|
||||||
|
|||||||
Executable
+5
@@ -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/
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/bin/mqtt-remote-gpio
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Restart=always
|
||||||
|
RestartSec=10
|
||||||
+13
-7
@@ -1,17 +1,23 @@
|
|||||||
|
use std::fs;
|
||||||
|
|
||||||
mod conf;
|
mod conf;
|
||||||
mod gpio_utils;
|
mod gpio_utils;
|
||||||
mod mqtt;
|
mod mqtt;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// TODO: Proper cli interface and start screen
|
println!(r"
|
||||||
// CLI interface should allow setting the config file
|
__ _ _ _ _ __ _ _ __ _
|
||||||
println!("mqtt-remote-gpio");
|
_ __ / _` || |_ | |_ _ _ ___ _ __ ___ | |_ ___ / _` || '_ \(_) ___
|
||||||
|
| ' \ \__. || _|| _| | '_|/ -_)| ' \ / _ \| _|/ -_) \__. || .__/| |/ _ \
|
||||||
|
|_|_|_| |_| \__| \__| |_| \___||_|_|_|\___/ \__|\___| |___/ |_| |_|\___/
|
||||||
|
");
|
||||||
|
|
||||||
// let config = conf::load_config("config.yml").unwrap();
|
let mut conf_path = std::env::args().nth(1).unwrap_or("config.yml".to_string());
|
||||||
let config = conf::load_config("config.secret.yml").unwrap();
|
if fs::exists(conf_path).unwrap_or(false) {
|
||||||
|
conf_path = "/etc/mqtt-remote-gpio.config.yml".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Remove this when done
|
let config = conf::load_config(&conf_path).unwrap();
|
||||||
println!("{:#?}", config);
|
|
||||||
|
|
||||||
mqtt::handler(config);
|
mqtt::handler(config);
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,6 @@ pub fn handler(config: Config) {
|
|||||||
loop {
|
loop {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for topic in input_pins.iter_mut() {
|
for topic in input_pins.iter_mut() {
|
||||||
// TODO: handle fails
|
|
||||||
let val = read_pin(&mut topic.gpio);
|
let val = read_pin(&mut topic.gpio);
|
||||||
if val != pin_state[i] {
|
if val != pin_state[i] {
|
||||||
pin_state[i] = val;
|
pin_state[i] = val;
|
||||||
@@ -65,8 +64,6 @@ pub fn handler(config: Config) {
|
|||||||
controller.handle_event(&content);
|
controller.handle_event(&content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// println!("Notification {:?}", msg);
|
|
||||||
thread::sleep(Duration::from_millis(config.poll_interval / 2));
|
thread::sleep(Duration::from_millis(config.poll_interval / 2));
|
||||||
// TODO: Handle pin value change instructions
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user