Failsafe WLAN script

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
Post Reply
quantalume
Posts: 15
Joined: Thu Aug 04, 2016 3:04 pm

Failsafe WLAN script

Post by quantalume » Wed Sep 14, 2016 6:55 pm

I'm trying to come up with a script that will attempt to connect to the local wireless router in station mode but fall back to access point if unsuccessful. Here is what I have:

Code: Select all

# main.py -- put your code here!
from network import WLAN
import time

ssid = 'xxxxx'
auth = (WLAN.WPA2, 'xxxxxxxx')

wlan=WLAN(mode=WLAN.STA)
wlan.antenna(WLAN.EXT_ANT)
wlan.connect(ssid=ssid, auth=auth, timeout=30000)
secs = 0

while (not wlan.isconnected() and secs < 30):
    time.sleep(1)
    secs += 1

if secs == 30:
    wlan.init(mode=WLAN.AP, ssid='wipy-wlan', auth=(WLAN.WPA2,'www.wipy.io'), channel=7, antenna=WLAN.EXT_ANT)
else:
    execfile('thingspeak.py')
When the configured router is absent, the WiPy does not go into access point mode (it never appears in lists of local access points). Any idea why my script is failing? Thanks.

Post Reply