Commit deployed changes from a while back.
This commit is contained in:
parent
e1211fe108
commit
dc7d4ed8a3
|
@ -7,6 +7,8 @@ import aprslib
|
||||||
import configparser
|
import configparser
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
|
import time
|
||||||
|
|
||||||
def read_config():
|
def read_config():
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
@ -18,6 +20,15 @@ def get_db_connection():
|
||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
return conn
|
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():
|
def main():
|
||||||
|
|
||||||
# Add the call and location of this station to the packet info
|
# 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 = aprs.TCPKISS(host=config['Settings']['kiss_host'], port=int(config['Settings']['kiss_port']))
|
||||||
ki.start()
|
ki.start()
|
||||||
|
|
||||||
|
scheduler = AsyncIOScheduler()
|
||||||
|
scheduler.add_job(refresh_kiss_connection, 'interval', hours = 1, args = [ki])
|
||||||
|
scheduler.start()
|
||||||
|
|
||||||
# Make a simple frame and send it
|
# Make a simple frame and send it
|
||||||
frame = aprs.APRSFrame.ui(
|
frame = aprs.APRSFrame.ui(
|
||||||
|
@ -47,6 +61,7 @@ def main():
|
||||||
while True:
|
while True:
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
for frame in ki.read(min_frames=1):
|
for frame in ki.read(min_frames=1):
|
||||||
|
logging.debug("New packet, trying to parse")
|
||||||
try:
|
try:
|
||||||
a = aprslib.parse(str(frame))
|
a = aprslib.parse(str(frame))
|
||||||
a['station_call'] = config['Settings']['station_call']
|
a['station_call'] = config['Settings']['station_call']
|
||||||
|
@ -66,7 +81,7 @@ def main():
|
||||||
attrib_names = ', '.join('"%s"' % w for w in a.keys())
|
attrib_names = ', '.join('"%s"' % w for w in a.keys())
|
||||||
attrib_values = ", ".join("?" * len(a.keys()))
|
attrib_values = ", ".join("?" * len(a.keys()))
|
||||||
|
|
||||||
|
logging.debug("Inserting into database")
|
||||||
try:
|
try:
|
||||||
# Insert data
|
# Insert data
|
||||||
sql = "INSERT INTO frames ("+attrib_names+") VALUES ("+attrib_values+")"
|
sql = "INSERT INTO frames ("+attrib_names+") VALUES ("+attrib_values+")"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user