Skip to content

Instantly share code, notes, and snippets.

@RRMoelker
Created July 13, 2016 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RRMoelker/f2e088732834c5050e4faec0c9982c1b to your computer and use it in GitHub Desktop.
Save RRMoelker/f2e088732834c5050e4faec0c9982c1b to your computer and use it in GitHub Desktop.
WiPy connect WiFi network on boot
# 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