Coding style enforced
This commit is contained in:
43
main.py
43
main.py
@@ -10,48 +10,59 @@ if aabiot.DoubleReset():
|
||||
print("Double Reset - Starting AP")
|
||||
AP()
|
||||
|
||||
#import settings
|
||||
settings=json.loads(''.join(open('settings.json').readlines()))
|
||||
LED=aabiot.LED.LED()
|
||||
# import settings
|
||||
settings = json.loads("".join(open("settings.json").readlines()))
|
||||
LED = aabiot.LED.LED()
|
||||
|
||||
|
||||
def netstop():
|
||||
n=network.WLAN(network.STA_IF)
|
||||
n = network.WLAN(network.STA_IF)
|
||||
n.active(False)
|
||||
n=network.WLAN(network.AP_IF)
|
||||
n = network.WLAN(network.AP_IF)
|
||||
n.active(False)
|
||||
|
||||
|
||||
def STA():
|
||||
"""Connects Board as Client to WiFi-Network. LED.Blinks 5 times short if successful and then displays the IP address in morse code"""
|
||||
sta=network.WLAN(network.STA_IF)
|
||||
sta = network.WLAN(network.STA_IF)
|
||||
if sta.isconnected():
|
||||
LED.Blink(5)
|
||||
return True
|
||||
sta.active(True)
|
||||
if ('NetMask') in settings and 'DNS' in settings and 'Gateway' in settings and 'IP' in settings:
|
||||
if (
|
||||
("NetMask") in settings
|
||||
and "DNS" in settings
|
||||
and "Gateway" in settings
|
||||
and "IP" in settings
|
||||
):
|
||||
print("Static configuration active")
|
||||
sta.ifconfig((settings["IP"],settings["NetMask"],settings["Gateway"],settings["DNS"]))
|
||||
sta.ifconfig(
|
||||
(settings["IP"], settings["NetMask"], settings["Gateway"], settings["DNS"])
|
||||
)
|
||||
else:
|
||||
print("DHCP active")
|
||||
sta.connect(settings['ssid'],settings['password'])
|
||||
timeout=0
|
||||
sta.connect(settings["ssid"], settings["password"])
|
||||
timeout = 0
|
||||
while timeout < 30:
|
||||
if sta.isconnected():
|
||||
LED.Morse('ip %s'%sta.ifconfig()[0],1)
|
||||
LED.Morse("ip %s" % sta.ifconfig()[0], 1)
|
||||
return True
|
||||
else:
|
||||
LED.Blink(1,.05,.95)
|
||||
LED.Blink(1, 0.05, 0.95)
|
||||
timeout += 1
|
||||
print("Time waiting: %s sec"%timeout)
|
||||
print("Time waiting: %s sec" % timeout)
|
||||
sta.active(False)
|
||||
return False
|
||||
|
||||
|
||||
def AP():
|
||||
"""Provides Access point with settings in settings.json. LED blinks 'AP' in morse code on success"""
|
||||
ap=network.WLAN(network.AP_IF)
|
||||
ap = network.WLAN(network.AP_IF)
|
||||
ap.active(True)
|
||||
ap.config(essid=settings['AP-ssid'],password=settings['AP-password'])
|
||||
ap.config(essid=settings["AP-ssid"], password=settings["AP-password"])
|
||||
print("AP configured")
|
||||
LED.Morse ('AP')
|
||||
LED.Morse("AP")
|
||||
|
||||
|
||||
netstop()
|
||||
if STA() != True:
|
||||
|
||||
Reference in New Issue
Block a user