From 369de6f873ae1a27743b8765b29c54492fa45a36 Mon Sep 17 00:00:00 2001 From: mattbk Date: Sat, 18 Oct 2025 10:43:56 -0500 Subject: [PATCH 1/6] Make simple GET request from Spothole. --- Cargo.toml | 1 + src/main.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 8e64aae..4516ff0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ authors = ["Chris, N6CTA "] anyhow = "1.0" chrono = "0.4" clap = { version = "4", features = ["derive"] } +reqwest = { version = "0.12.24", features = ["json", "blocking"] } serde_json = "1.0.145" socket2 = "0.5" diff --git a/src/main.rs b/src/main.rs index b2f8f62..5eff6bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; use std::net::UdpSocket; use std::net::Ipv4Addr; use serde_json::json; +use reqwest; /// Validate that the provided port string can be parsed into a u16 and is nonzero. fn validate_port(port: &str) -> Result { @@ -62,6 +63,11 @@ struct Cli { /// Spotter callsign (e.g. W1CDN) #[arg(short = 's', long)] spotter: Option, + + /// Spot UI frames to Spothole + #[arg(short = 'o', long, default_value_t = false)] + spothole: bool, + } /// Convert a byte slice into a hex-dump string for debugging purposes. @@ -399,6 +405,12 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) { if cli.ui_only && summary != "UI" { return; } + + // If Spothole is enabled + if summary == "UI" && cli.spothole { + let body = reqwest::blocking::get("https://spothole.app/api/v1/spots?limit=1"); + println!("body = {body:?}"); + } // Send UDP if cli.uport != 55555 { From c9f6a4a6c5ce6c58764154e6d7fe0925e9d92f87 Mon Sep 17 00:00:00 2001 From: mattbk Date: Sat, 18 Oct 2025 11:33:38 -0500 Subject: [PATCH 2/6] Spot packets to spothole.app if desired. --- src/main.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5eff6bc..fe2aaa2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,6 +68,10 @@ struct Cli { #[arg(short = 'o', long, default_value_t = false)] spothole: bool, + /// Spotting frequency + #[arg(short = 'f', long, default_value_t = 14105000)] + freq: u32, + } /// Convert a byte slice into a hex-dump string for debugging purposes. @@ -369,6 +373,7 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) { let basic_destination = hdr.callto_str(); let timestamp = Local::now().format("%H:%M:%S").to_string(); let spotter = &cli.spotter; + let freq = &cli.freq; // Filter and compute the text from the payload only once. let text = filter_text(&frame.payload); @@ -408,8 +413,28 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) { // If Spothole is enabled if summary == "UI" && cli.spothole { - let body = reqwest::blocking::get("https://spothole.app/api/v1/spots?limit=1"); - println!("body = {body:?}"); + // curl --request POST --header "Content-Type: application/json" + // --data '{"dx_call":"M0TRT","time":1760019539, "freq":14200000, + // "comment":"Test spot please ignore", "de_call":"M0TRT"}' https://spothole.app/api/v1/spot + + // POST JSON + let packet = json!({ + "dx_call": &source, + "de_call": &spotter, + "freq": &freq, + "comment": &text, + "mode": "PKT", + "mode_type": "DATA", + "mode_source": "SPOT", + "time": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(), + }); + let client = reqwest::blocking::Client::new(); + let res = client.post("https://spothole.app/api/v1/spot") + .json(&packet) + .send(); + println!("res = {res:?}"); + + } // Send UDP @@ -423,6 +448,7 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) { "spotter": &spotter, "summary": &summary, "text": &text, + "freq": &freq, "timestamp": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(), "type": "data" }); From a62cb8630bbb6a6157198b541b67033783504b3a Mon Sep 17 00:00:00 2001 From: mattbk Date: Sun, 19 Oct 2025 21:57:14 -0500 Subject: [PATCH 3/6] Use alternative spothole URL if desired. --- src/main.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index fe2aaa2..a4e3fa8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,7 +35,7 @@ struct Cli { /// AGWPE server IP address (e.g. 127.0.0.1) #[arg(short = 'i', long)] ip: std::net::IpAddr, - + /// AGWPE server TCP port (e.g. 8000) #[arg(short = 'p', long, value_parser = validate_port)] port: u16, @@ -64,10 +64,14 @@ struct Cli { #[arg(short = 's', long)] spotter: Option, - /// Spot UI frames to Spothole + /// Spot UI frames to a Spothole server #[arg(short = 'o', long, default_value_t = false)] spothole: bool, + /// Provide a different URL than https://spothole.app/api/v1/spot + #[arg(short = 'O', long)] + spothole_alt: Option, + /// Spotting frequency #[arg(short = 'f', long, default_value_t = 14105000)] freq: u32, @@ -374,6 +378,13 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) { let timestamp = Local::now().format("%H:%M:%S").to_string(); let spotter = &cli.spotter; let freq = &cli.freq; + //let spothole_alt = &cli.spothole_alt; + + // If user provides an alternate Spothole URL, use that one + let spothole_url = match &cli.spothole_alt { + Some(spothole_alt) => spothole_alt, + None => &"https://spothole.app/api/v1/spot".to_string(), + }; // Filter and compute the text from the payload only once. let text = filter_text(&frame.payload); @@ -417,6 +428,9 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) { // --data '{"dx_call":"M0TRT","time":1760019539, "freq":14200000, // "comment":"Test spot please ignore", "de_call":"M0TRT"}' https://spothole.app/api/v1/spot + println!("spothole_url: {}", spothole_url); + + // POST JSON let packet = json!({ "dx_call": &source, @@ -429,7 +443,7 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) { "time": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(), }); let client = reqwest::blocking::Client::new(); - let res = client.post("https://spothole.app/api/v1/spot") + let res = client.post(spothole_url) .json(&packet) .send(); println!("res = {res:?}"); From 5cd273a4760d57f43573a7da2e1ca437cb711204 Mon Sep 17 00:00:00 2001 From: mattbk Date: Tue, 21 Oct 2025 21:10:43 -0500 Subject: [PATCH 4/6] Update readme. --- README.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bbed15f..3d3d52d 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ The compiled executable will be located in the `target/release` directory. Run the executable with the required arguments: ```bash -mwtchahrd -i -p [-c ] [-d] [-u] +mwtchahrd -i -p [-c ] [-d] [-u] ``` ### Command‑Line Arguments @@ -56,6 +56,30 @@ mwtchahrd -i -p [-c ] [-d] [-u] - `-u, --ui_only` Only display frames with a UI payload. When this flag is set, frames that are not UI are skipped. + +- `-b, --uip ` + Send UDP to what IP address (e.g. 127.0.0.1) [default: 127.0.0.1]. + +- `-k, --uport ` + Send UDP to what port (e.g. 8000; 55555 disables UDP) [default: 55555]. + +- `-s, --spotter ` + Spotter callsign (e.g. W1CDN). + +- `-o, --spothole` + Spot UI frames to a Spothole server. + +- `-O, --spothole-alt ` + Provide a different URL than https://spothole.app/api/v1/spot. + +- `-f, --freq ` + Spotting frequency [default: 14105000]. + +- `-h, --help` + Print help. + +- `-V, --version` + Print version. ## Examples @@ -83,6 +107,12 @@ Monitor only UI frames: mwtchahrd -i 127.0.0.1 -p 8000 -u ``` +### Spotting to [Spothole.app](https://spothole.app) API + +```bash +cargo run -- --ip 192.168.0.6 --port 8000 --spotter W1CDN --spothole --freq 14105000 +``` + ## Code Overview - **Validation Functions:** From b14f4eee6a518a45553e795e6cf29335751d634b Mon Sep 17 00:00:00 2001 From: mattbk Date: Tue, 21 Oct 2025 21:12:51 -0500 Subject: [PATCH 5/6] Add detail. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3d3d52d..8e279b8 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,8 @@ mwtchahrd -i 127.0.0.1 -p 8000 -u ### Spotting to [Spothole.app](https://spothole.app) API +Sends only UI frames and mode is hardcoded as `PKT`. Spot from callsign `W1CDN` and report fixed frequency 14.105 MHz: + ```bash cargo run -- --ip 192.168.0.6 --port 8000 --spotter W1CDN --spothole --freq 14105000 ``` From 796035ac593c72b188f8a635c0ea4dddea5d5978 Mon Sep 17 00:00:00 2001 From: mattbk Date: Tue, 21 Oct 2025 21:13:48 -0500 Subject: [PATCH 6/6] Fix command. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e279b8..27d70f6 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ mwtchahrd -i 127.0.0.1 -p 8000 -u Sends only UI frames and mode is hardcoded as `PKT`. Spot from callsign `W1CDN` and report fixed frequency 14.105 MHz: ```bash -cargo run -- --ip 192.168.0.6 --port 8000 --spotter W1CDN --spothole --freq 14105000 +mwtchahrd --ip 192.168.0.6 --port 8000 --spotter W1CDN --spothole --freq 14105000 ``` ## Code Overview