From dc7d4ed8a39a870441ee598ee8ec9d7bca0798d5 Mon Sep 17 00:00:00 2001 From: W1CDN Date: Sun, 10 Dec 2023 13:30:51 -0600 Subject: [PATCH] Commit deployed changes from a while back. --- kiss_and_db.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/kiss_and_db.py b/kiss_and_db.py index c799a70..ae43f14 100644 --- a/kiss_and_db.py +++ b/kiss_and_db.py @@ -7,6 +7,8 @@ import aprslib import configparser import time import logging +from apscheduler.schedulers.asyncio import AsyncIOScheduler +import time def read_config(): config = configparser.ConfigParser() @@ -18,6 +20,15 @@ def get_db_connection(): conn.row_factory = sqlite3.Row return conn +def refresh_kiss_connection(kiss_conn): + logging.debug("Restarting KISS connection on schedule") + logging.debug("Stopping current connection") + kiss_conn.stop() + logging.debug("Waiting 5 seconds") + time.sleep(5) + logging.debug("Starting new connection") + kiss_conn.start() + def main(): # Add the call and location of this station to the packet info @@ -33,6 +44,9 @@ def main(): ki = aprs.TCPKISS(host=config['Settings']['kiss_host'], port=int(config['Settings']['kiss_port'])) ki.start() + scheduler = AsyncIOScheduler() + scheduler.add_job(refresh_kiss_connection, 'interval', hours = 1, args = [ki]) + scheduler.start() # Make a simple frame and send it frame = aprs.APRSFrame.ui( @@ -47,6 +61,7 @@ def main(): while True: conn = get_db_connection() for frame in ki.read(min_frames=1): + logging.debug("New packet, trying to parse") try: a = aprslib.parse(str(frame)) a['station_call'] = config['Settings']['station_call'] @@ -66,7 +81,7 @@ def main(): attrib_names = ', '.join('"%s"' % w for w in a.keys()) attrib_values = ", ".join("?" * len(a.keys())) - + logging.debug("Inserting into database") try: # Insert data sql = "INSERT INTO frames ("+attrib_names+") VALUES ("+attrib_values+")"