I recently bought a Wipy development board to try MicroPython as a friend of mine is a big fan, and I whet a TI CC3200 (ARM Cortex-M4+wifi) development board even if I prefer to develop it in C.
Here is just a snippet allowing to ground or set to 3.3V GP4 in order to connect to home WLAN or set the card as an access point. Great for on-the-go development!
# boot.py -- run on boot-up
# can run arbitrary Python, but best to keep it minimal
# Import libraries
from machine import Pin
from network import WLAN
# Set variables
staSsid = 'ssidToConnect'
staPassword = 'password'
apSsid = 'ssidInAccessPoint'
apPassword = 'passwordMoreThan8char'
# Declare Pin
p_select = Pin( 'GP5', mode=Pin.IN )
# Select Wifi mode regarding Pin state
if p_select.value() == 1:
wlan = WLAN( mode=WLAN.AP )
wlan.init( mode=WLAN.AP, ssid=apSsid, auth=(WLAN.WPA2,apPassword), channel=7, antenna=WLAN.INT_ANT )
else:
wlan = WLAN( mode=WLAN.STA )
nets = wlan.scan()
for net in nets:
if net.ssid == staSsid:
wlan.connect( net.ssid, auth=(net.sec, staPassword), timeout=5000 )
while not wlan.isconnected():
# Save power while waiting
machine.idle()
print( 'WLAN connection succeeded!' )
break
Share this post
Twitter
Google+
Facebook
Reddit
LinkedIn
StumbleUpon
Pinterest
Email