show gps coords of last handshake in ui
This commit is contained in:
parent
1ff14c05a9
commit
9e656d4ea6
@ -1,7 +1,11 @@
|
||||
import logging
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
||||
import pwnagotchi.plugins as plugins
|
||||
import pwnagotchi.ui.fonts as fonts
|
||||
from pwnagotchi.ui.components import LabeledValue
|
||||
from pwnagotchi.ui.view import BLACK
|
||||
|
||||
|
||||
class GPS(plugins.Plugin):
|
||||
@ -12,6 +16,7 @@ class GPS(plugins.Plugin):
|
||||
|
||||
def __init__(self):
|
||||
self.running = False
|
||||
self.coordinates = None
|
||||
|
||||
def on_loaded(self):
|
||||
logging.info("gps plugin loaded for %s" % self.options['device'])
|
||||
@ -21,7 +26,7 @@ class GPS(plugins.Plugin):
|
||||
logging.info("enabling bettercap's gps module for %s" % self.options['device'])
|
||||
try:
|
||||
agent.run('gps off')
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
agent.run('set gps.device %s' % self.options['device'])
|
||||
@ -29,14 +34,74 @@ class GPS(plugins.Plugin):
|
||||
agent.run('gps on')
|
||||
self.running = True
|
||||
else:
|
||||
logging.warning("no GPS detected")
|
||||
logging.warning('no GPS detected')
|
||||
|
||||
def on_handshake(self, agent, filename, access_point, client_station):
|
||||
if self.running:
|
||||
info = agent.session()
|
||||
gps = info['gps']
|
||||
self.coordinates = info['gps']
|
||||
gps_filename = filename.replace('.pcap', '.gps.json')
|
||||
|
||||
logging.info("saving GPS to %s (%s)" % (gps_filename, gps))
|
||||
logging.info("saving GPS to %s (%s)" % (gps_filename, self.coordinates))
|
||||
with open(gps_filename, 'w+t') as fp:
|
||||
json.dump(gps, fp)
|
||||
json.dump(self.coordinates, fp)
|
||||
|
||||
def on_ui_setup(self, ui):
|
||||
# add coordinates for other displays
|
||||
if ui.is_waveshare_v2():
|
||||
lat_pos = (127, 75)
|
||||
lon_pos = (122, 84)
|
||||
alt_pos = (127, 94)
|
||||
elif ui.is_inky():
|
||||
# guessed values, add tested ones if you can
|
||||
lat_pos = (112, 30)
|
||||
lon_pos = (112, 49)
|
||||
alt_pos = (87, 63)
|
||||
else:
|
||||
# guessed values, add tested ones if you can
|
||||
lat_pos = (127, 51)
|
||||
lon_pos = (127, 56)
|
||||
alt_pos = (102, 71)
|
||||
|
||||
ui.add_element(
|
||||
"latitude",
|
||||
LabeledValue(
|
||||
color=BLACK,
|
||||
label="lat:",
|
||||
value="-",
|
||||
position=lat_pos,
|
||||
label_font=fonts.Small,
|
||||
text_font=fonts.Small,
|
||||
),
|
||||
)
|
||||
ui.add_element(
|
||||
"longitude",
|
||||
LabeledValue(
|
||||
color=BLACK,
|
||||
label="long:",
|
||||
value="-",
|
||||
position=lon_pos,
|
||||
label_font=fonts.Small,
|
||||
text_font=fonts.Small,
|
||||
),
|
||||
)
|
||||
ui.add_element(
|
||||
"altitude",
|
||||
LabeledValue(
|
||||
color=BLACK,
|
||||
label="alt:",
|
||||
value="-",
|
||||
position=alt_pos,
|
||||
label_font=fonts.Small,
|
||||
text_font=fonts.Small,
|
||||
),
|
||||
)
|
||||
|
||||
def on_ui_update(self, ui):
|
||||
if self.coordinates and all([
|
||||
# avoid 0.000... measurements
|
||||
self.coordinates["Latitude"], self.coordinates["Longitude"]
|
||||
]):
|
||||
ui.set("latitude", f"{self.coordinates['Latitude']:.4f}")
|
||||
ui.set("longitude", f" {self.coordinates['Longitude']:.4f}")
|
||||
ui.set("altitude", f" {self.coordinates['Altitude']:.1f}m")
|
||||
|
Loading…
x
Reference in New Issue
Block a user