diff --git a/db_test.py b/db_test.py new file mode 100644 index 0000000..e098f01 --- /dev/null +++ b/db_test.py @@ -0,0 +1,14 @@ +import sqlite3 + +def get_db_connection(): + conn = sqlite3.connect('database.db') + conn.row_factory = sqlite3.Row + return conn + +frame1 = "W1CDN-1>APDW16,K0UND-2*:;147.390GF*111111z4755.45N/09700.58Wr147.390MHz +060 https://www.wa0jxt.org/" + +conn = get_db_connection() +conn.execute('INSERT INTO frames (frame) VALUES (?)', + (frame1,)) +conn.commit() +conn.close() diff --git a/init_db.py b/init_db.py new file mode 100644 index 0000000..cf2eaf7 --- /dev/null +++ b/init_db.py @@ -0,0 +1,19 @@ +import sqlite3 + +connection = sqlite3.connect('database.db') + +with open('schema.sql') as f: + connection.executescript(f.read()) + +cur = connection.cursor() + +# cur.execute("INSERT INTO posts (title, content) VALUES (?, ?)", +# ('First Post', 'Content for the first post') +# ) +# +# cur.execute("INSERT INTO posts (title, content) VALUES (?, ?)", +# ('Second Post', 'Content for the second post') +# ) + +connection.commit() +connection.close() diff --git a/kiss_and_db.py b/kiss_and_db.py index fa2aa75..5c596e8 100644 --- a/kiss_and_db.py +++ b/kiss_and_db.py @@ -33,7 +33,12 @@ def main(): ki.read(callback=print_frame, min_frames=None) # put some database stuff here - + print(Frame.from_bytes(frame)) + conn = get_db_connection() + conn.execute('INSERT INTO frames (frame) VALUES (?)', + (Frame.from_bytes(frame))) + conn.commit() + conn.close() if __name__ == "__main__": main() diff --git a/schema.sql b/schema.sql new file mode 100644 index 0000000..e658834 --- /dev/null +++ b/schema.sql @@ -0,0 +1,7 @@ +DROP TABLE IF EXISTS frames; + +CREATE TABLE frames ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + frame TEXT NOT NULL +); diff --git a/tcp_send_recv.py b/tcp_send_recv.py new file mode 100644 index 0000000..bf09b0e --- /dev/null +++ b/tcp_send_recv.py @@ -0,0 +1,49 @@ + + + #!/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. +""" +import os +import sqlite3 +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 get_db_connection(): + conn = sqlite3.connect('database.db') + conn.row_factory = sqlite3.Row + return conn + +def print_frame(frame): + print(Frame.from_bytes(frame)) + a = str(Frame.from_bytes(frame)) + dir(frame) + return(a) + +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) + ki.read(callback=print_frame, min_frames=None) + + conn = get_db_connection() + print(ki.read(callback=print_frame, min_frames=None),) + #conn.execute('INSERT INTO frames (frame) VALUES (?)', + # ((,)) + conn.commit() + conn.close() + +if __name__ == "__main__": + main()