Skip to content

Commit

Permalink
Merge pull request #1171 from ltindall/gps_keys
Browse files Browse the repository at this point in the history
Fix missing key error and update heading when using external gps.
  • Loading branch information
rashley-iqt authored Feb 16, 2024
2 parents c4071fb + 7d9a3ad commit fddf26c
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions gamutrf/mqtt_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def get_heading(self):
if heading_result is None:
logging.error("could not update external heading")
else:
self.heading = float(json.loads(heading_result.text)["heading"])
heading_json = json.loads(heading_result.text)
if "heading" in heading_json:
self.heading = float(heading_json["heading"])
else:
heading_result = http_get(f"http://{self.gps_server}:8000/v1/heading")
if heading_result is None:
Expand Down Expand Up @@ -103,20 +105,22 @@ def add_gps(self, publish_args):
if external_gps_msg is None:
logging.error("could not update with external GPS")
else:
self.get_heading()
self.external_gps_msg = json.loads(external_gps_msg.text)
publish_args.update(
{
"position": (
self.external_gps_msg["latitude"],
self.external_gps_msg["longitude"],
),
"altitude": self.external_gps_msg["altitude"],
"gps_time": self.external_gps_msg["time_usec"],
"map_url": None,
"heading": self.heading,
"gps": "fix",
}
)
if "error" not in self.external_gps_msg:
publish_args.update(
{
"position": (
self.external_gps_msg["latitude"],
self.external_gps_msg["longitude"],
),
"altitude": self.external_gps_msg["altitude"],
"gps_time": self.external_gps_msg["time_usec"],
"map_url": None,
"heading": self.heading,
"gps": "fix",
}
)

# Use internal GPIO GPS
else:
Expand Down

0 comments on commit fddf26c

Please sign in to comment.