EMF_Camp_Badge/dowsingrod/main.py

61 lines
1.8 KiB
Python
Raw Permalink Normal View History

2018-09-01 11:19:28 -04:00
"""This is a dowsing rod for WiFi APs"""
2018-09-03 09:59:37 -04:00
___title___ = "Dowsing Rod"
2018-09-01 11:19:28 -04:00
___license___ = "MIT"
___dependencies___ = ["sleep", "app", "wifi", "sim800"]
___categories___ = ["EMF", "System"]
import ugfx, wifi, app
from tilda import Buttons
from time import sleep
status_height = 20
2018-09-01 12:52:47 -04:00
ssid = 'emfcamp-legacy18'
2018-09-01 11:19:28 -04:00
ugfx.init()
ugfx.clear()
ugfx.set_default_font(ugfx.FONT_FIXED)
ugfx.Label(5, 180, 240, 15, "Press A to scan, MENU to exit")
# while (not Buttons.is_pressed(Buttons.BTN_A)) and (not Buttons.is_pressed(Buttons.BTN_B)) and (not Buttons.is_pressed(Buttons.BTN_Menu)):
while not Buttons.is_pressed(Buttons.BTN_Menu):
2018-09-01 12:52:47 -04:00
if not Buttons.is_pressed(Buttons.BTN_A) and not Buttons.is_pressed(Buttons.BTN_B):
ugfx.poll()
2018-09-01 11:19:28 -04:00
continue
2018-09-01 12:52:47 -04:00
if Buttons.is_pressed(Buttons.BTN_B):
ugfx.clear()
ugfx.Label(0, 0, 240, 25, "SSID:")
ssid_box = ugfx.Textbox(0, 25, 240, 25, text=ssid)
ugfx.Keyboard(0, ugfx.height()//2, ugfx.width(), ugfx.height()//2)
ssid_box.set_focus()
while not Buttons.is_pressed(Buttons.BTN_A):
ugfx.poll()
continue
ssid = ssid_box.text()
2018-09-01 11:19:28 -04:00
ugfx.clear()
wifi.nic().active(False)
wifi.nic().active(True)
2018-09-01 11:19:28 -04:00
# networks = [{ "ssid": ap[0], "mac": ap[1], "channel": ap[2], "signal": ap[3] } for ap in wifi.nic().scan()]
2018-09-01 12:52:47 -04:00
networks = sorted([net for net in wifi.nic().scan() if net[0] == ssid], key=lambda n: n[3], reverse=True)
2018-09-01 11:19:28 -04:00
aps = []
for ap in [(net[1], net[3]) for net in networks]:
if ap[0] not in [ap[0] for ap in aps]:
aps.append(ap)
y = 0
for ap in aps[:20]:
ugfx.Label(0, y, 240, 25, "{1}dB {0}".format(*ap))
y += status_height
2018-09-01 12:22:21 -04:00
if len(aps) == 0:
2018-09-01 12:52:47 -04:00
ugfx.Label(0, y, 240, 25, "No %s APs found" % ssid)
2018-09-01 11:19:28 -04:00
ugfx.clear()
app.restart_to_default()