Created
May 9, 2019 19:16
-
-
Save blippy/5131d1ac01cb5e6bdacdef4512fb9966 to your computer and use it in GitHub Desktop.
Test wifi connectivity
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 machine | |
import network | |
import time | |
# because we use onbaord GPIO, we invert the meaning of the pin | |
# so 0 turns it on, 1 turn it off | |
pin = machine.Pin(16, machine.Pin.OUT) | |
def poff(): pin.value(1) | |
def pon(): pin.value(0) | |
poff() | |
def tmain1(): | |
wlan = network.WLAN(network.STA_IF) | |
try: | |
while True: | |
wlan.active(True) | |
try: | |
nets = wlan.scan() | |
pon() | |
except OSError: | |
poff() | |
wlan.active(False) | |
time.sleep_ms(500) | |
finally: | |
poff() | |
wlan.active(False) | |
tmain1() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This project tests to see if there's a Wifi connection within range. It is useful if you want to know if your device will be able to attach to a Wifi point, or if it is out of range.
The code is written in MicroPython for a nodemcu/ESP8226/etc.. Notes:
main.py
add the lineimport tcw
. You can, alternatively, run the program in uPython'srepl
, although you will probably want to try the device disconnected from your computerThe picture belows shows a setup. The LED is alight, demonstrating that there is Wifi within connectivity distance.