Compare commits

...

3 Commits

Author SHA1 Message Date
fe4efdda81 pm3: id must be read twice
to avoid false reads
2025-05-22 15:52:22 +02:00
64299960a5 kill orphaned pm3 on startup 2025-05-22 15:51:55 +02:00
ed0942e332 moved systemd service file 2025-05-22 15:50:48 +02:00
3 changed files with 53 additions and 21 deletions

24
fwa.service Normal file
View File

@@ -0,0 +1,24 @@
[Unit]
Description=Feuerwehr Anwesenheit Service
Requires=local-fs.target
After=local-fs.target
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
Type=simple
ExecStart=/usr/local/bin/fwa
Restart=on-failure
RestartSec=5
User=root
Group=root
RuntimeDirectory=/var/lib/fwa
Environment="PM3_BIN=/usr/local/bin/pm3/pm3"
#Environment="LOG_LEVEL=warn"
#Environment="HOTSPOT_IDS=578B5DF2;c1532b57"
#Environment="HOTSPOT_SSID=fwa"
#Environment="HOTSPOT_PW=a9LG2kUVrsRRVUo1"
[Install]
WantedBy=multi-user.target

View File

@@ -1,19 +0,0 @@
[Unit]
Description=Feuerwehr Anwesenheit Service
Requires=local-fs.target
After=local-fs.target
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
Type=simple
ExecStart=/home/pi/fw-anwesenheit
Restart=on-failure
RestartSec=5
User=root
Group=root
Environment="PM3_BIN=/home/pi/proxmark3/pm3"
RuntimeDirectory=/home/pi
[Install]
WantedBy=multi-user.target

View File

@@ -1,4 +1,4 @@
use log::{info, trace};
use log::{debug, info, trace, warn};
use std::env;
use std::error::Error;
use std::process::Stdio;
@@ -10,6 +10,8 @@ use tokio::sync::broadcast;
/// The pm3 binary is ether set in the env var PM3_BIN or found in the path
/// The ouput is parsed and send via the `tx` channel
pub async fn run_pm3(tx: broadcast::Sender<String>) -> Result<(), Box<dyn Error>> {
kill_orphans().await;
let pm3_path = match env::var("PM3_BIN") {
Ok(path) => path,
Err(_) => {
@@ -32,10 +34,15 @@ pub async fn run_pm3(tx: broadcast::Sender<String>) -> Result<(), Box<dyn Error>
let mut reader = BufReader::new(stdout).lines();
let mut last_id: String = "".to_owned();
while let Some(line) = reader.next_line().await? {
trace!("PM3: {line}");
if let Some(uid) = super::parser::parse_line(&line) {
tx.send(uid)?;
if last_id == uid {
tx.send(uid.clone())?;
}
last_id = uid.to_owned();
}
}
@@ -47,3 +54,23 @@ pub async fn run_pm3(tx: broadcast::Sender<String>) -> Result<(), Box<dyn Error>
Err("PM3 exited with a non zero exit code".into())
}
}
/// Kills any open pm3 instances
/// Also funny name. hehehe.
async fn kill_orphans() {
let kill_result = Command::new("pkill")
.arg("-KILL")
.arg("-x")
.arg("proxmark3")
.output()
.await;
match kill_result {
Ok(_) => {
debug!("Successfully killed orphaned pm3 instances");
}
Err(e) => {
warn!("Failed to kill pm3 orphans: {e} Continuing anyway");
}
}
}