mirror of
https://codeberg.org/mclemens/NoiseFloorLogger.git
synced 2024-10-01 06:46:02 -04:00
added more comments/print outs
This commit is contained in:
parent
def9d5f151
commit
8ddd87cc49
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import telnetlib
|
||||
import time
|
||||
import sys
|
||||
@ -8,6 +7,8 @@ import os.path
|
||||
import config as cfg
|
||||
from airium import Airium
|
||||
|
||||
# Read config parameters from config.py
|
||||
# and store them into variables
|
||||
host = cfg.host
|
||||
port = cfg.port
|
||||
timeout = cfg.timeout
|
||||
@ -28,20 +29,26 @@ def init_db():
|
||||
# Connect to the rig via Telnet to rigctld
|
||||
def connect_rig():
|
||||
try:
|
||||
print("Connecting to " + host + ":" + str(port) + "...")
|
||||
session = telnetlib.Telnet(host, port, timeout)
|
||||
print("Connection successful.")
|
||||
return session
|
||||
except Exception as e:
|
||||
print("Connecting to " + host + ":" + port + " failed:")
|
||||
print("Connection failed:")
|
||||
print(e)
|
||||
|
||||
# Query the rig for signal strength (l STRENGTH)
|
||||
# and write the output into the database
|
||||
def query_rig(session):
|
||||
global db_file
|
||||
# read signal strength from TRX
|
||||
session.write(b"l STRENGTH\n")
|
||||
# wait a moment
|
||||
time.sleep(0.1)
|
||||
# read the answer
|
||||
strength = session.read_very_eager().decode("utf-8")
|
||||
x = strength.replace("\n", "")
|
||||
# write the value returned from rigctld to the DB
|
||||
if x:
|
||||
rrdtool.update(db_file, 'N:%s' % x)
|
||||
else:
|
||||
@ -54,6 +61,7 @@ def print_graph(filename,title,time_window):
|
||||
global db_file
|
||||
global web_path
|
||||
|
||||
# Definition of the graph and the output file
|
||||
graphv_args = [
|
||||
web_path+"/"+filename,
|
||||
'--title', title,
|
||||
@ -66,6 +74,7 @@ def print_graph(filename,title,time_window):
|
||||
'DEF:noiselevel='+db_file+':dbm:AVERAGE',
|
||||
'LINE1:noiselevel#ff0000:"This is a red line"'
|
||||
]
|
||||
# generate the output file
|
||||
rrdtool.graphv(*graphv_args)
|
||||
|
||||
# Generate an index.html file containing some graphs
|
||||
@ -73,12 +82,12 @@ def gen_html():
|
||||
global web_path
|
||||
a = Airium()
|
||||
|
||||
# Generate the HTML code
|
||||
a('<!DOCTYPE html>')
|
||||
with a.html(lang="en"):
|
||||
with a.head():
|
||||
a.meta(charset="utf-8")
|
||||
a.title(_t="Noise Floor")
|
||||
|
||||
with a.body():
|
||||
with a.h3():
|
||||
a("Last 1 hour")
|
||||
@ -97,19 +106,19 @@ def gen_html():
|
||||
with a.div():
|
||||
a.img(src='4.png', alt='alt text')
|
||||
|
||||
html = str(a) # casting to string extracts the value
|
||||
|
||||
html = str(a)
|
||||
# write the html code to disk as index.html
|
||||
with open(web_path + "/index.html", "w") as html_file:
|
||||
print(f"{html}", file=html_file)
|
||||
|
||||
# Main functionality
|
||||
init_db()
|
||||
s = connect_rig()
|
||||
init_db() # If no DB exists, create one
|
||||
s = connect_rig() # Connect via Telnet to rigctld
|
||||
while s:
|
||||
query_rig(s)
|
||||
print_graph("1.png","Noise Floor","-1h")
|
||||
print_graph("2.png","Noise Floor","-4h")
|
||||
print_graph("3.png","Noise Floor","-12h")
|
||||
print_graph("4.png","Noise Floor","-24h")
|
||||
gen_html()
|
||||
time.sleep(5)
|
||||
query_rig(s) # Query the signal strength and write it to the DB
|
||||
print_graph("1.png","Noise Floor","-1h") # create a graph as PNG file
|
||||
print_graph("2.png","Noise Floor","-4h") # ^
|
||||
print_graph("3.png","Noise Floor","-12h") # ^
|
||||
print_graph("4.png","Noise Floor","-24h") # ^
|
||||
gen_html() # create and write a html file
|
||||
time.sleep(5) # wait 5 seconds
|
||||
|
Loading…
Reference in New Issue
Block a user