Created
July 13, 2016 09:55
-
-
Save RRMoelker/f2e088732834c5050e4faec0c9982c1b to your computer and use it in GitHub Desktop.
WiPy connect WiFi network on boot
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
# boot.py -- run on boot-up | |
# can run arbitrary Python, but best to keep it minimal | |
# | |
# WiPy WiFi setup, augmented code from: | |
# http://micropython.org/resources/docs/en/latest/wipy/wipy/tutorial/wlan.html#assigning-a-static-ip-address-when-booting | |
import machine | |
from network import WLAN | |
IP = '192.168.1.42' | |
SUBNET = '255.255.255.0' | |
GATEWAY = '192.168.1.1' | |
DNS_SERVER = '8.8.8.8' | |
SSID = 'myOwnWifiName' | |
WIFI_PASS = 'correcthorsebatterystaple' | |
wlan = WLAN() | |
if machine.reset_cause() != machine.SOFT_RESET: | |
wlan.init(WLAN.STA) | |
wlan.ifconfig(config=(IP, SUBNET, GATEWAY, DNS_SERVER)) | |
if not wlan.isconnected(): | |
wlan.connect(SSID, auth=(WLAN.WPA2, WIFI_PASS), timeout=5000) | |
while not wlan.isconnected(): | |
machine.idle() # save power while waiting |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment