Skip to content

Commit

Permalink
forgot to cast lat long and course to floats
Browse files Browse the repository at this point in the history
  • Loading branch information
EricAndrechek committed Apr 10, 2024
1 parent 150bdfe commit ef5f41c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tracking-dashboard/backend/mqtt-syncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def build_json_message(id):
# build a source packet of the type the API likes from a message
def build_source_packet(message):
source = {}
source['timestamp'] = datetime.now().isoformat()
source['timestamp'] = str(datetime.now().isoformat())
source['callsign'] = "UMSERV"
source['ssid'] = 0
source['ip'] = "127.0.0.1"
Expand All @@ -90,7 +90,7 @@ def build_source_packet(message):
def on_message(client, userdata, message):
topic = message.topic
payload = message.payload.decode()
timestamp = datetime.now().isoformat()
timestamp = str(datetime.now().isoformat())

# split topic
topics = topic.split("/")
Expand Down
16 changes: 16 additions & 0 deletions tracking-dashboard/backend/utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def parse_data(self):
try:
callsign = self.raw["data"]["callsign"]
ssid = self.raw["data"]["ssid"]
try:
ssid = int(ssid)
except ValueError:
raise Exception("Invalid ssid")
symbol = self.raw["data"]["symbol"]
if callsign is None or ssid is None or symbol is None:
raise KeyError
Expand All @@ -97,6 +101,10 @@ def parse_data(self):
lat = None
try:
lat = self.raw["data"]["lat"]
try:
lat = float(lat)
except ValueError:
raise Exception("Invalid latitude")
if lat < -90 or lat > 90:
raise Exception("Invalid latitude")
except KeyError:
Expand All @@ -105,6 +113,10 @@ def parse_data(self):
lon = None
try:
lon = self.raw["data"]["lon"]
try:
lon = float(lon)
except ValueError:
raise Exception("Invalid longitude")
if lon < -180 or lon > 180:
raise Exception("Invalid longitude")
except KeyError:
Expand All @@ -119,6 +131,10 @@ def parse_data(self):
course = None
try:
course = self.raw["data"]["course"]
try:
course = float(course)
except ValueError:
raise Exception("Invalid course")
if course < 0 or course > 360:
raise Exception("Invalid course")
except KeyError:
Expand Down

0 comments on commit ef5f41c

Please sign in to comment.