diff --git a/README.md b/README.md index efd7487..5ea46b7 100644 --- a/README.md +++ b/README.md @@ -101,11 +101,6 @@ Sending a message with `L` will respond with a list of current bulletins **(M)SG** Sending a message with `M` will respond with a list of messages that were sent to the callsign of the user requesting the list of messages. -**(P)OST** -This command posts a bulletin and needs to be sent in the following format: -```P ``` -Example: ```P Checkpoint 3 operational. Volunteers needed.``` - **(S)END** This command leaves a message for a specific user via their callsign and needs to be sent in the following format: ```S ``` @@ -113,6 +108,17 @@ Example: ```S N0CALL-1 Meet at the Trailhead at 15:00``` The BBS will send a notification to the callsign letting them know they have a message waiting. +**(P)OST** +This command posts a bulletin and needs to be sent in the following format: +```P ``` +Example: ```P Checkpoint 3 operational. Volunteers needed.``` + +**(P)OST (U)RGENT** +This command will post an urgent bulletin which will have the BBS send out a bulletin packet which will be seen by all +supported devices. It needs to be sent in the following format. +```PU ``` +Example: ```PU Highway 12 closed. Use alternate routes.``` + ## Automatically run at boot Instructions coming soon.... diff --git a/aprs_comm.py b/aprs_comm.py index d6b2362..6770389 100644 --- a/aprs_comm.py +++ b/aprs_comm.py @@ -83,6 +83,28 @@ def send_ack(ki, aprs_frame): print(f"Failed to send ACK: {e}") +def send_bulletin(bulletin_id, bulletin_text): + """Send an APRS bulletin in BLN format.""" + try: + frame_info = f":{bulletin_id:<9}:{bulletin_text}".encode('utf-8') + + frame = aprs.APRSFrame.ui( + destination="BLN", + source=config.MYCALL, + path=config.APRS_PATH, + info=frame_info + ) + + ki = aprs.TCPKISS(host=config.KISS_HOST, port=config.KISS_PORT) + ki.start() + ki.write(frame) + print(f"Urgent bulletin transmitted: {bulletin_text}") + ki.stop() + + except Exception as e: + print(f"Failed to send urgent bulletin: {e}") + + def start(): ki = aprs.TCPKISS(host=config.KISS_HOST, port=config.KISS_PORT) ki.start() diff --git a/commands.py b/commands.py index 786566f..8de96c7 100644 --- a/commands.py +++ b/commands.py @@ -37,6 +37,18 @@ def handle_command(callsign, command): return [f"Message sent to {recipient}."] return ["Usage: SEND "] + elif cmd in ['PU']: + if arg: + database.add_bulletin(normalized_callsign, f"URGENT: {arg}") + + urgent_bulletin = f"URGENT: {arg}" + bulletin_id = "BLN1" + aprs_comm.send_bulletin(bulletin_id, urgent_bulletin) + + return ["Urgent bulletin posted and transmitted."] + return ["Usage: PU "] + + else: return [ "Hello and Welcome to the TC2-BBS!", diff --git a/database.py b/database.py index e467636..e4f85cf 100644 --- a/database.py +++ b/database.py @@ -2,17 +2,21 @@ import sqlite3 from datetime import datetime, timedelta import config + def init_db(): conn = sqlite3.connect('aprs.db') cursor = conn.cursor() + cursor.execute(""" CREATE TABLE IF NOT EXISTS bulletins ( id INTEGER PRIMARY KEY AUTOINCREMENT, text TEXT NOT NULL, poster TEXT NOT NULL, - timestamp DATETIME DEFAULT CURRENT_TIMESTAMP + timestamp DATETIME DEFAULT CURRENT_TIMESTAMP, + type TEXT DEFAULT 'normal' ) """) + cursor.execute(""" CREATE TABLE IF NOT EXISTS messages ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -22,17 +26,20 @@ def init_db(): timestamp DATETIME DEFAULT CURRENT_TIMESTAMP ) """) + conn.commit() conn.close() + def format_timestamp(timestamp): dt = datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S") return dt.strftime("%b%d %H:%M").upper() -def add_bulletin(callsign, text): +def add_bulletin(callsign, text, urgent=False): conn = sqlite3.connect('aprs.db') cursor = conn.cursor() - cursor.execute("INSERT INTO bulletins (text, poster) VALUES (?, ?)", (text, callsign)) + bulletin_type = "urgent" if urgent else "normal" + cursor.execute("INSERT INTO bulletins (text, poster, type) VALUES (?, ?, ?)", (text, callsign, bulletin_type)) conn.commit() conn.close()