Created
May 17, 2020 23:01
-
-
Save gigawatts/712bc9be6414abbeac8e002fad8e4f23 to your computer and use it in GitHub Desktop.
ESP32 MicroPython WiFi Geiger Counter (Work in Progress)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import network | |
from machine import Pin, Timer, PWM | |
import utime | |
wlan = network.WLAN(network.STA_IF) | |
wlan.active(True) | |
speaker = Pin(26, Pin.OUT) | |
MY_SSID = "attwifi" | |
my_rssi = 0 | |
tick_timer = Timer(0) ## Hardware timer | |
#tick_timer = Timer(-1) ## Virtual RTOS-based software timer | |
def tick_spkr(timer): | |
speaker.on(); utime.sleep_ms(5); speaker.off() | |
def scan(): | |
# FIXME: wlan scan freezes timer while scanning | |
nets = wlan.scan() | |
global my_rssi | |
found_my_ssid = False | |
for net in nets: | |
ssid = net[0].decode('utf-8') | |
ch = net[2] | |
rssi = net[3] | |
print( 'Ch {0:2} RSSI {1} SSID {2}'.format(ch, rssi, ssid) ) | |
if ssid == MY_SSID: | |
found_my_ssid = True | |
my_rssi = rssi | |
if found_my_ssid == True: | |
sig_period = ((abs(my_rssi) - 30) + 8)**2 ## best sig = -30 | |
# FIXME: Is this the only way to change the timer period? | |
tick_timer.init(period=sig_period, mode=Timer.PERIODIC, callback=tick_spkr) | |
print('My network found! {}'.format(sig_period) ) | |
else: | |
tick_timer.deinit() | |
while True: | |
scan() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment