From fa4717d9079de7186b1ff2bba202c122ddc05c13 Mon Sep 17 00:00:00 2001 From: nq4t Date: Wed, 1 Feb 2023 07:32:51 +0000 Subject: [PATCH] initial commit - proof of concept --- README.md | 25 +++++++++++++++++++++++++ log4om.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 README.md create mode 100644 log4om.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..62ca039 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# Log4OM Web Status + +This python program will take UDP messages blasted at it from Log4OM and will write it to a HTML file. It will +continually update this file as messages come in. It requires you to let Log4OM automatically send status packets. + +### Usage + +Place the script on a system that can hear UDP from Log4OM and has a way of putting the resulting HTML file on a webserver +as fast as possible. + +### Basic Operation + +Log4OM has a feature that has it send out UDP messages automatically as long as specific conditions are met. This python +script/program will take in the messages sent at it's IP and parse a few things out of the XML. It writes this to an +HTML file every time a message comes in; so the HTML generated is set to auto-reload every 5 seconds. It currently displays +the following in a very basic way: + +- Your current VFO frequency and opearating mode. +- Your TX offset/split if it exists + +If no data is received from Log4OM, because you turned your rig off or shutdown Log4OM; it will indicate your radio is +off and wait for data to come back. Support is planned to show if rig is in transmit. + +The "Radio Off" message happens after 15 seconds of no data. This is done by checking the elapsed time since the timestamo +was last updated; which happens every time a message comes in. diff --git a/log4om.py b/log4om.py new file mode 100644 index 0000000..0c5695b --- /dev/null +++ b/log4om.py @@ -0,0 +1,56 @@ +from threading import * +import time +import xml.etree.ElementTree as ET +import socket + +UDP_IP = "0.0.0.0" +UDP_PORT = 2242 # Default Log4OM UDP Out Port + +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +sock.bind((UDP_IP, UDP_PORT)) +tot = time.time() + + +def monitor(): + global tot + while True: + tc = time.time() - tot # time since last timestamp + if tc < 15: # 15 seconds + time.sleep(6) + else: + writehtml(f"Radio off") + time.sleep(30) + +def log4om(): + global tot + global rstatus + while True: + data, addr = sock.recvfrom(1024) + root = ET.fromstring(data.decode("utf-8")) + freq = int(root.find("Freq").text) + tx_freq = int(root.find("TXFreq").text) + mode = root.find("Mode").text + f = freq / 100 + tf = tx_freq / 100 + sv = tf - f # Determines split value + if sv > 0: + writehtml(f"Frequency: {f}kHz {mode}
Up: {sv:.2f} kHz") + elif sv < 0: + sv = sv * -1 # Invert negative numbers + writehtml(f"Frequency: {f}kHz {mode}
Down: {sv:.2f} kHz") + else: + writehtml(f"Frequency: {f}kHz {mode}") + tot = time.time() #timestamp + time.sleep(.1) + +def writehtml(rs): + header = "\n\nFT-1000MP Status\n\n\n\n" + with open("/var/www/log/radio.html", "w") as html: # Modify file location as needed. + html.write(header + rs + "\n\n") + +T = Thread(target=monitor,daemon=True) +L = Thread(target=log4om) + +L.start() # Start the UDP thread +time.sleep(5) # Wait 5 seconds in case Log4OM is already running. +T.start() # Start monitor