feat: testing code, switch to rppal gpio lib, get mqtt working in both directions

This commit is contained in:
janishutz committed 2026-08-25 10:10:03 +02:00
1 parent 0b0efb1a0d
commit cd0f894e73
8 files changed
+727 -32

No files matched your search

+18 -8
View File
@@ -30,17 +30,27 @@ pub fn handler(config: Config) {
// Spawn thread to monitor pins
thread::spawn(move || {
let mut pin_state: Vec<u8> = vec![0; input_pins.len()];
let off: Vec<u8> = b"OFF".to_vec();
let on: Vec<u8> = b"ON".to_vec();
loop {
let mut i = 0;
for topic in input_pins.iter_mut() {
// TODO: handle fails
client
.publish(
String::from(&topic.topic) + &format!("/{}", topic.id),
QoS::AtLeastOnce,
false,
vec![read_pin(&mut topic.gpio)],
)
.unwrap_or_default();
let val = read_pin(&mut topic.gpio);
if val != pin_state[i] {
println!("Value change for pin {} detected", topic.id);
pin_state[i] = val;
client
.publish(
String::from(&topic.topic) + &format!("/{}", topic.id),
QoS::AtLeastOnce,
false,
if val == 0 { off.clone() } else { on.clone() },
)
.unwrap_or_default();
}
i += 1;
}
thread::sleep(Duration::from_millis(config.poll_interval));
}