mirror of
https://github.com/TheCommsChannel/TC2-APRS-BBS.git
synced 2025-02-05 01:45:24 -05:00
Add Urgent Bulletins
This commit is contained in:
parent
bd784eeb05
commit
311fea5b6b
16
README.md
16
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 <text>```
|
||||
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 <callsign> <text>```
|
||||
@ -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 <text>```
|
||||
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 <text>```
|
||||
Example: ```PU Highway 12 closed. Use alternate routes.```
|
||||
|
||||
## Automatically run at boot
|
||||
|
||||
Instructions coming soon....
|
||||
|
22
aprs_comm.py
22
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()
|
||||
|
12
commands.py
12
commands.py
@ -37,6 +37,18 @@ def handle_command(callsign, command):
|
||||
return [f"Message sent to {recipient}."]
|
||||
return ["Usage: SEND <callsign> <text>"]
|
||||
|
||||
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 <text>"]
|
||||
|
||||
|
||||
else:
|
||||
return [
|
||||
"Hello and Welcome to the TC2-BBS!",
|
||||
|
13
database.py
13
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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user