Handle breaking errors in kiss_and_db.py #38
|
@ -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+")"
|
||||
|
|
Loading…
Reference in New Issue
Block a user