Compare commits

...

2 Commits

Author SHA1 Message Date
W1CDN
50085de7db Try to catch exceptions. 2023-12-12 20:25:00 -06:00
W1CDN
e7002c712c Flail. 2023-12-11 21:41:57 -06:00
2 changed files with 29 additions and 27 deletions

View File

@ -3,6 +3,7 @@ db_frames_fields = ("id",
"addresse",
"alive",
"altitude",
"body",
"comment",
"course",
"created",
@ -11,6 +12,7 @@ db_frames_fields = ("id",
"frame",
"from",
"gpsfixstatus",
"id",
"latitude",
"longitude",
"mbits",
@ -44,6 +46,7 @@ db_frames_fields = ("id",
"tEQNS",
"tPARM",
"tUNIT",
"type",
"via",
"weather",
"wx_raw_timestamp")

View File

@ -24,18 +24,10 @@ 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("Waiting 5 seconds")
#time.sleep(5)
logging.debug("Starting new connection")
kiss_conn.start()
# alive_frame = aprs.APRSFrame.ui(
# destination="TEST",
# source=config['Settings']['mycall'],
# path=None,
# info=b">None",
# )
# logging.debug("Sending empty frame to keep connection alive")
# kiss_conn.write(alive_frame)
def main():
@ -47,40 +39,45 @@ def main():
logging.basicConfig(filename=config['Settings']['log_path'], level=logging.DEBUG, \
format='%(asctime)s - %(message)s')
logging.debug('kiss_and_db.py running')
logging.debug('============= kiss_and_db.py running =============')
ki = aprs.TCPKISS(host=config['Settings']['kiss_host'], port=int(config['Settings']['kiss_port']))
ki.start()
print(str(ki))
ki.stop()
print(str(ki))
scheduler = AsyncIOScheduler()
scheduler.add_job(refresh_kiss_connection, 'interval', minutes = 1, args = [ki])
scheduler.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(
# destination="APZ001",
# source=config['Settings']['mycall'],
# path=['WIDE1-1'],
# info=b">Hello World!",
# )
# frame = aprs.APRSFrame.ui(
# destination="APZ001",
# source=config['Settings']['mycall'],
# path=["WIDE1-1"],
# info=b">Hello World!",
# )
#ki.write(frame)
# Watch for new packets to come in
while True:
conn = get_db_connection()
for frame in ki.read(min_frames=1):
logging.debug("New packet, trying to parse")
logging.debug(str(frame))
try:
a = aprslib.parse(str(frame))
try:
a = aprslib.parse(str(frame))
except Exception as error:
logging.error("Error with aprslib:", error)
a['station_call'] = config['Settings']['station_call']
a['station_lat'] = config['Settings']['station_lat']
a['station_lon'] = config['Settings']['station_lon']
a['created_unix'] = int(time.time())
print(a)
# Make this a string and deal with it later (probably a mistake)
a['path'] = str(a['path'])
if 'subpacket' in a:
a['subpacket'] = str(a['subpacket'])
#logging.debug(a['path'])
# Store true/false as 1/0
if 'alive' in a:
if a['alive'] == True:
@ -90,6 +87,8 @@ def main():
# Build an INSERT statement based on the fields we have from the frame
attrib_names = ', '.join('"%s"' % w for w in a.keys())
attrib_values = ", ".join("?" * len(a.keys()))
logging.debug(attrib_names)
logging.debug(a.values())
logging.debug("Inserting into database")
try:
@ -125,9 +124,9 @@ def main():
except:
#print("Error with SQLite!")
logging.error("Error with SQLite!")
except:
except Exception as error:
#print("Frame could not be parsed.")
logging.error("Frame could not be parsed.")
logging.error("Frame could not be parsed:", error)
conn.close()