10 Commits

Author SHA1 Message Date
mattbk
c9f6a4a6c5 Spot packets to spothole.app if desired. 2025-10-18 11:33:38 -05:00
mattbk
369de6f873 Make simple GET request from Spothole. 2025-10-18 10:43:56 -05:00
ab4f190138 Merge pull request 'Pass UDP data out of mwtchahrd structured as JSON' (#1) from udp into dev
Reviewed-on: #1
2025-10-17 21:47:24 +00:00
mattbk
a768d908ed Make spotter optional. 2025-10-17 16:39:19 -05:00
mattbk
c8d7b6a817 Add spotter as an argument. 2025-10-15 21:19:27 -05:00
mattbk
98da8b95d5 Send a UDP message to the server that says you are connected. 2025-10-12 21:06:49 -05:00
mattbk
7957fa7c2c Pass data as JSON over UDP. 2025-10-05 18:21:16 -05:00
mattbk
6101932b0d Add defaults for UDP arguments to not get in the way. 2025-10-04 22:42:14 -05:00
mattbk
8065fcc24e Pass raw frame text over UDP. 2025-09-28 21:47:26 -05:00
mattbk
3aa395dc4e Rough out sending a basic UDP notification. 2025-09-28 21:20:46 -05:00
2 changed files with 89 additions and 1 deletions

View File

@@ -8,6 +8,8 @@ authors = ["Chris, N6CTA <mail@n6cta.com>"]
anyhow = "1.0" anyhow = "1.0"
chrono = "0.4" chrono = "0.4"
clap = { version = "4", features = ["derive"] } clap = { version = "4", features = ["derive"] }
reqwest = { version = "0.12.24", features = ["json", "blocking"] }
serde_json = "1.0.145"
socket2 = "0.5" socket2 = "0.5"
[profile.release] [profile.release]

View File

@@ -7,7 +7,11 @@ use std::convert::TryInto;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::net::TcpStream; use std::net::TcpStream;
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; 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. /// Validate that the provided port string can be parsed into a u16 and is nonzero.
fn validate_port(port: &str) -> Result<u16, String> { fn validate_port(port: &str) -> Result<u16, String> {
@@ -47,6 +51,27 @@ struct Cli {
/// Only monitor UI frames /// Only monitor UI frames
#[arg(short = 'u', long, default_value_t = false)] #[arg(short = 'u', long, default_value_t = false)]
ui_only: bool, ui_only: bool,
/// Send UDP to what IP address (e.g. 127.0.0.1)
#[arg(short = 'b', long, default_value_t = std::net::IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)))]
uip: std::net::IpAddr,
/// Send UDP to what port (e.g. 8000; 55555 disables UDP)
#[arg(short = 'k', long, value_parser = validate_port, default_value_t = 55555)]
uport: u16,
/// Spotter callsign (e.g. W1CDN)
#[arg(short = 's', long)]
spotter: Option<String>,
/// Spot UI frames to Spothole
#[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. /// Convert a byte slice into a hex-dump string for debugging purposes.
@@ -347,6 +372,8 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) {
let source = hdr.callfrom_str(); let source = hdr.callfrom_str();
let basic_destination = hdr.callto_str(); let basic_destination = hdr.callto_str();
let timestamp = Local::now().format("%H:%M:%S").to_string(); 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. // Filter and compute the text from the payload only once.
let text = filter_text(&frame.payload); let text = filter_text(&frame.payload);
@@ -383,6 +410,50 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) {
if cli.ui_only && summary != "UI" { if cli.ui_only && summary != "UI" {
return; return;
} }
// If Spothole is enabled
if summary == "UI" && cli.spothole {
// 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
if cli.uport != 55555 {
let uaddr = format!("{}:{}", cli.uip, cli.uport);
let socket = UdpSocket::bind("0.0.0.0:0");
let packet = json!({
"final_destination": &final_destination,
"source": &source,
"spotter": &spotter,
"summary": &summary,
"text": &text,
"freq": &freq,
"timestamp": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(),
"type": "data"
});
let _ = socket.expect("REASON").send_to(packet.to_string().as_bytes(), uaddr);
}
// In non-debug mode, print the session line and any additional lines. // In non-debug mode, print the session line and any additional lines.
if !cli.debug { if !cli.debug {
@@ -403,7 +474,22 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) {
fn main() -> Result<()> { fn main() -> Result<()> {
let cli = Cli::parse(); let cli = Cli::parse();
let addr = format!("{}:{}", cli.ip, cli.port); let addr = format!("{}:{}", cli.ip, cli.port);
let uaddr = format!("{}:{}", cli.uip, cli.uport);
let reconnect_delay_ms = 5000; let reconnect_delay_ms = 5000;
if cli.uport != 55555 {
// Bind the client socket to any available address and port
let socket = UdpSocket::bind("0.0.0.0:0")?;
println!("UDP client started at {}:{}", cli.uip, cli.uport);
// Send a message to the server
let packet = json!({
"text": "UDP client connected",
"timestamp": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(),
"type": "status"
});
//let message = "UDP client connected";
socket.send_to(packet.to_string().as_bytes(), uaddr)?;
}
loop { loop {
println!("Connecting to AGWPE server at {addr}"); println!("Connecting to AGWPE server at {addr}");