Skip to content

Commit

Permalink
mqtt and aprs need own threads
Browse files Browse the repository at this point in the history
  • Loading branch information
EricAndrechek committed Apr 14, 2024
1 parent edf0420 commit 30dcc99
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 92 deletions.
51 changes: 26 additions & 25 deletions tracking-dashboard/backend/aprs-syncer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# connect to APRS-IS and listen for all callsigns in items database, mirroring their data to our database

import aprslib
from sql.helpers import get_all_callsigns
from sql.helpers import check_item_id, add_item_id, get_all_callsigns
from utils.api import Data

# ----- APRS SETUP -----

# get all callsigns in items database
callsigns = get_all_callsigns()
# get just first item from each tuple
callsigns = [callsign[0] for callsign in callsigns]
# just unique callsigns
callsigns = list(set(callsigns))
# create filter string
filter = "p/" + "/".join(callsigns)
print(filter)

def callback(packet):
data_obj = Data()

Expand All @@ -28,6 +38,19 @@ def callback(packet):
data_obj.parse()
except Exception as e:
print("parse error: ", e)

# check if callsign exists in items table
print("Data: ", data_obj.data)
name = data_obj.data['callsign'] + "-" + str(data_obj.data['ssid'])
item = check_item_id(name)
if item is None:
# add item to items table
add_item_id(name, data_obj.data['callsign'], data_obj.data['ssid'], data_obj.data['symbol'])
else:
# change callsign, name, and symbol to item values
data_obj.data['callsign'] = item.callsign
data_obj.data['ssid'] = item.ssid
data_obj.data['symbol'] = item.symbol

# save data
try:
Expand All @@ -39,28 +62,6 @@ def callback(packet):
except Exception as e:
print("save error: ", e)

# get all callsigns in items database
callsigns = get_all_callsigns()
# get just first item from each tuple
callsigns = [callsign[0] for callsign in callsigns]
# just unique callsigns
callsigns = list(set(callsigns))
callsigns.append("KF8ABL")
callsigns.append("W8AXP")
callsigns.append("N9FEB")
callsigns.append("KB6OJE")
callsigns.append("KJ7MLW")
callsigns.append("KJ6ZOY")
callsigns.append("N4KCB")
callsigns.append("DK3MM")
callsigns.append("ZBPDT")
callsigns.append("JH0EYA")
callsigns.append("KC7RUF")
callsigns.append("VE7IKX")
# create filter string
filter = "p/" + "/".join(callsigns)
print(filter)

# connect to APRS-IS and listen for all callsigns in items database
aprs = aprslib.IS("N0CALL", port=14580)
aprs.set_filter(filter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from sql.helpers import check_item_id, add_item_id, get_all_callsigns
from utils.api import Data
import json
import aprslib

# ----- MQTT SETUP -----

Expand All @@ -20,72 +19,6 @@
old_messages = {}
message_building = {}

# ----- APRS SETUP -----

# get all callsigns in items database
callsigns = get_all_callsigns()
# get just first item from each tuple
callsigns = [callsign[0] for callsign in callsigns]
# just unique callsigns
callsigns = list(set(callsigns))
# create filter string
filter = "p/" + "/".join(callsigns)
print(filter)

def callback(packet):
data_obj = Data()

# receive data from request
data = packet
data["type"] = "aprs"

print("Received data: ", data)

# accept upload data
try:
data_obj.upload(data)
except Exception as e:
print("upload error: ", e)

data_obj.info['ip'] = '127.0.0.1'

print("About to parse")

# parse data
try:
data_obj.parse()
except Exception as e:
print("parse error: ", e)

# check if callsign exists in items table
print("Data: ", data_obj.data)
name = data_obj.data['callsign'] + "-" + str(data_obj.data['ssid'])
item = check_item_id(name)
if item is None:
# add item to items table
add_item_id(name, data_obj.data['callsign'], data_obj.data['ssid'], data_obj.data['symbol'])
else:
# change callsign, name, and symbol to item values
data_obj.data['callsign'] = item.callsign
data_obj.data['ssid'] = item.ssid
data_obj.data['symbol'] = item.symbol

# save data
try:
status_code = data_obj.save()
if status_code == 201 or status_code == 202:
print("New data saved")
elif status_code == 208:
print("Data already exists")
except Exception as e:
print("save error: ", e)

# connect to APRS-IS and listen for all callsigns in items database
aprs = aprslib.IS("N0CALL", port=14580)
aprs.set_filter(filter)
aprs.connect()
aprs.consumer(callback)

# ----- FUNCTIONS -----

def build_json_message(id):
Expand Down

0 comments on commit 30dcc99

Please sign in to comment.