From 5e86b40f380a628a117f69ac8767e65036c2d991 Mon Sep 17 00:00:00 2001 From: W1CDN Date: Thu, 13 Apr 2023 17:16:16 -0500 Subject: [PATCH] Stub out a KISS connection. It seems to simultaneously run the API and keep the KISS connection open in the background. --- api_app.py | 4 ++++ kiss_and_db.py | 39 +++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 -- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 kiss_and_db.py diff --git a/api_app.py b/api_app.py index 0b117ca..1eabbd1 100644 --- a/api_app.py +++ b/api_app.py @@ -53,6 +53,10 @@ log_folder = config['Settings']['log_folder'] # Load logs first (just to check for errors before page loads) data = read_logs(log_folder) +# Start subprocess to watch KISS connection +import subprocess +subprocess.Popen(["python3","kiss_and_db.py"]) + api.add_resource(Packets, '/packets') # and '/locations' is our entry point for Locations if __name__ == '__main__': diff --git a/kiss_and_db.py b/kiss_and_db.py new file mode 100644 index 0000000..fa2aa75 --- /dev/null +++ b/kiss_and_db.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +""" +Send a test frame via TCP, then read & print KISS frames from a TCP Socket. +For use with programs like Dire Wolf. +From https://github.com/python-aprs/kiss3/blob/main/examples/tcp_send_recv.py +""" +import os + +from ax253 import Frame +import kiss + + +MYCALL = os.environ.get("MYCALL", "W1CDN") +KISS_HOST = os.environ.get("KISS_HOST", "192.168.0.30") +KISS_PORT = os.environ.get("KISS_PORT", "8001") + + +def print_frame(frame): + print(Frame.from_bytes(frame)) + + +def main(): + ki = kiss.TCPKISS(host=KISS_HOST, port=int(KISS_PORT), strip_df_start=True) + ki.start() + # frame = Frame.ui( + # destination="PYKISS", + # source=MYCALL, + # path=["WIDE1-1"], + # info=">Hello World!", + # ) + #ki.write(frame) + # Write received frame to terminal + ki.read(callback=print_frame, min_frames=None) + + # put some database stuff here + + +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt index baf9fc7..8fc2f61 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,2 @@ flask flask_restful -pandas -numpy