本文整理汇总了Python中network.WLAN.connect方法的典型用法代码示例。如果您正苦于以下问题:Python WLAN.connect方法的具体用法?Python WLAN.connect怎么用?Python WLAN.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network.WLAN
的用法示例。
在下文中一共展示了WLAN.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_connect
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
def do_connect():
from network import WLAN
sta_if = WLAN(network.STA_IF)
if not sta_if.isconnected():
print('connecting to network...')
sta_if.active(True)
sta_if.connect(WIFISSID, WIFIPASS)
while not sta_if.isconnected():
pass
print('network config:', sta_if.ifconfig())
示例2: connect
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
def connect(ssid, key):
""" Scans for and connects to the specified wifi network using key as password """
wlan = WLAN(mode=WLAN.STA)
nets = wlan.scan()
for net in nets:
if net.ssid == ssid:
wlan.connect(net.ssid, auth=(net.sec, key), timeout=5000)
while not wlan.isconnected():
machine.idle() # save power while waiting
break
示例3: connectLocalBox
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
def connectLocalBox(configFilePath):
f = open(configFilePath, 'r')
config=ujson.load(f)
f.close()
wlan = WLAN(mode=WLAN.STA)
wlan.ifconfig(config=(config["ip"], config["mask"],config["gateway"], config["dns"]))
wlan.scan()
wlan.connect(config["ssid"], auth=(WLAN.WPA2, config["password"]))
while not wlan.isconnected():
pass
return wlan;
示例4: wlan_connect
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
def wlan_connect():
wifi = WLAN(mode=WLAN.STA)
wifi.ifconfig(config=(__myip, __netmask, __gateway, __dns))
wifi.scan() # scan for available networks
wifi.connect(ssid=__ssid, auth=(WLAN.WPA2, __nwpass))
while not wifi.isconnected():
pass
syslog('WiPy is up and running')
wifi.irq(trigger=WLAN.ANY_EVENT, wake=machine.SLEEP)
machine.sleep()
示例5: connect_wifi
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
def connect_wifi(cfg=None):
if not cfg:
from config import Config
cfg = Config.load(debug=True)
from network import WLAN
import machine
print('Starting WLAN, attempting to connect to ' + cfg.wifi_ssid)
wlan = WLAN(0, WLAN.STA)
wlan.ifconfig(config='dhcp')
wlan.connect(ssid=cfg.wifi_ssid, auth=(WLAN.WPA2, cfg.wifi_key))
while not wlan.isconnected():
machine.idle()
print('Connected')
示例6: connect_to_wifi_wipy
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
def connect_to_wifi_wipy(ssid, password, retries=10):
"""
Connect to a WIFI network
"""
wlan = WLAN(mode=WLAN.STA)
print("Connecting to wifi network '%s'" % ssid)
wlan.connect(ssid=ssid, auth=(WLAN.WPA2, password))
retry_count = 0
while not wlan.isconnected():
sleep(1)
retry_count += 1
if retry_count > retries:
return False
print('Connected', wlan.ifconfig())
return True
示例7: __init__
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
class Theta:
def __init__(self):
self.wlan = WLAN(WLAN.STA)
pass
def log(self, msg):
print(msg)
def findWifi(self):
wlans = self.wlan.scan()
# TODO: Return all visible Thetas
for w in wlans:
if w.ssid.startswith('THETA'):
self.log('Found Theta WiFi: %s' % w.ssid)
# THETAXL12345678 = Theta (original model) - PTP/IP
# THETAXN12345678 = Theta m15 - PTP/IP
# THETAXS12345678.OSC = Theta S - OSC
return w.ssid
return False
def connectWifi(self, ssid):
password = ssid[-8:]
return self.wlan.connect(ssid, auth=(WLAN.WPA, password))
# convenience - might get removed
def connect(self):
wifi = self.findWifi()
if not wifi:
return False
self.connectWifi(wifi)
self.ptpip = ptpip.PTPIP('192.168.1.1')
return self.ptpip
def initPTP(self):
answer = self.ptpip.initCommand('1234567812345678', 'WiPy')
if not answer:
print("Init failed!")
return False
(session_id, guid, name) = answer
pass2 = self.ptpip.initEvent(session_id)
if not pass2:
print("Init stage 2 failed!")
return False
return (session_id, guid, name)
def openSession(self):
answer = self.ptpip.createCommand(0x1002, [])
return answer
def closeSession(self):
answer = self.ptpip.createCommand(0x1003, [])
return answer
def shoot(self):
answer = self.ptpip.createCommand(0x100e, [0x0, 0x0])
return answer
def getPTPIP(self):
return self.ptpip
示例8: connect_to_wifi
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
def connect_to_wifi(ssid, password, retries=10):
"""
Connect to a WIFI network
"""
try:
from network import STA_IF
except ImportError:
return connect_to_wifi_wipy(ssid, password, retries=retries)
wlan = WLAN(STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
retry_count = 0
while not wlan.isconnected():
sleep(1)
retry_count += 1
if retry_count > retries:
return False
return True
示例9: connect_to_ap
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
def connect_to_ap(essids, tries=3):
from network import WLAN, STA_IF
from time import sleep
wlan = WLAN(STA_IF)
wlan.active(True)
## Select only known networks
ap_list = list(filter(lambda ap: ap[0].decode('UTF-8') in
essids.keys(), wlan.scan()))
## sort by signal strength
ap_list.sort(key=lambda ap: ap[3], reverse=True)
for ap in ap_list:
essid = ap[0].decode('UTF-8')
wlan.connect(essid, essids[essid])
for i in range(5):
## this is somewhat crude, we actually have a
## wlan.status() we can inspect. oh well...
if wlan.isconnected():
return True
sleep(1)
return False
示例10: wlan
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
def wlan():
"""Connect in STA mode, fallback to AP"""
try:
import wlanconfig
except ImportError:
print("WLAN: no wlanconfig.py")
wlanconfig = None
wlan = WLAN(mode=WLAN.AP)
except Exception as e:
print("WLAN: error in wlanconfig.py: {}".format(e))
wlanconfig = None
wlan = WLAN(mode=WLAN.AP)
else:
try:
# configure the WLAN subsystem in station mode (the default is AP)
wlan = WLAN(mode=WLAN.STA)
print("WLAN: connecting to network (AP)...")
wlan.connect(wlanconfig.ssid, auth=(WLAN.WPA2, wlanconfig.password), timeout=5000)
print("WLAN: waiting for IP...")
for tries in range(50):
if wlan.isconnected():
print(
"""\
WLAN: connected!
WiPy IP: {}
NETMASK: {}
GATEWAY: {}
DNS: {}""".format(
*wlan.ifconfig()
)
)
break
time.sleep_ms(100)
except OSError:
print("WLAN: found no router, going into AP mode instead")
wlanconfig = None
except Exception as e:
print("WLAN: error: {}".format(e))
wlanconfig = None
if wlanconfig is None:
wlan.init(mode=WLAN.AP, ssid="wipy-wlan", auth=(WLAN.WPA2, "www.wipy.io"), channel=7, antenna=WLAN.INT_ANT)
示例11: __init__
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
class LocalWifi:
"""
Create a local WiFi connection.
"""
ssid = ''
auth_mode = WLAN.WPA2
auth_password = ''
wlan = None
def __init__(self, ssid, ssid_password):
self.ssid = ssid
self.auth_password = ssid_password
self.wlan = WLAN(mode=WLAN.STA)
def connect(self):
self.wlan.scan()
self.wlan.connect(ssid=self.ssid, auth=(self.auth_mode, self.auth_password))
while not self.wlan.isconnected():
print('.', end="")
print("\nConnected to:\n", self.wlan.ifconfig())
示例12: wlan
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
def wlan():
"""Connect in STA mode, fallback to AP"""
log = ulog.Logger('WLAN: ')
try:
import wlanconfig
except ImportError:
log.notice('no wlanconfig.py')
wlanconfig = None
wlan = WLAN(mode=WLAN.AP)
except Exception as e:
log.error('error in wlanconfig.py: {}'.format(e))
wlanconfig = None
wlan = WLAN(mode=WLAN.AP)
else:
try:
# configure the WLAN subsystem in station mode (the default is AP)
wlan = WLAN(mode=WLAN.STA)
log.info('connecting to network (AP)...')
wlan.connect(wlanconfig.ssid, auth=(WLAN.WPA2, wlanconfig.password), timeout=5000)
log.info('waiting for IP...')
for tries in range(50):
if wlan.isconnected():
log.notice('''connected!
WiPy IP: {}
NETMASK: {}
GATEWAY: {}
DNS: {}'''.format(*wlan.ifconfig()))
break
time.sleep_ms(100)
except OSError:
log.error('found no router, going into AP mode instead')
wlanconfig = None
except Exception as e:
log.error('error: {}'.format(e))
wlanconfig = None
if wlanconfig is None:
wlan.init(mode=WLAN.AP, ssid='wipy-wlan', auth=(WLAN.WPA2,'www.wipy.io'), channel=7, antenna=WLAN.INT_ANT)
示例13: wlan
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
def wlan():
with open('/flash/wificonfig.txt') as f:
ssid = f.readline().strip()
passwd = f.readline().strip()
# configure the WLAN subsystem in station mode (the default is AP)
print('WLAN: connecting to network (AP)...')
wlan = WLAN(mode=WLAN.STA)
try:
wlan.connect(ssid, auth=(WLAN.WPA2, passwd), timeout=5000)
print('WLAN: waiting for IP...')
for tries in range(50):
if wlan.isconnected():
print('''\
WLAN: connected!
WiPy IP: {}
NETMASK: {}
GATEWAY: {}
DNS: {}'''.format(*wlan.ifconfig()))
break
time.sleep_ms(100)
except OSError:
print('WLAN: found no router, going into AP mode instead')
wlan.init(mode=WLAN.AP, ssid='wipy-wlan', auth=(WLAN.WPA2,'www.wipy.io'), channel=7, antenna=WLAN.INT_ANT)
示例14: connect_wifi
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
def connect_wifi(self):
from network import WLAN
if not self.cfg:
raise ValueError("Can't initialise wifi, no config")
self.log('Starting WLAN, attempting to connect to ' + ','.join(self.cfg.wifi.keys()))
wlan = WLAN(0, WLAN.STA)
wlan.ifconfig(config='dhcp')
while not wlan.isconnected():
nets = wlan.scan()
for network in nets:
if network.ssid in self.cfg.wifi.keys():
self.log('Connecting to ' + network.ssid)
self.feed_wdt() # just in case
wlan.connect(ssid=network.ssid, auth=(network.sec, self.cfg.wifi[network.ssid]))
while not wlan.isconnected():
idle()
break
self.feed_wdt() # just in case
sleep_ms(2000)
self.log('Connected as %s' % wlan.ifconfig()[0])
示例15: WLAN
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import connect [as 别名]
from machine import Timer
from machine import Pin
import BlynkLib
from network import WLAN
WIFI_SSID = 'YOUR_WIFI_SSID'
WIFI_AUTH = (WLAN.WPA2, 'YOUR_WIFI_PASSORD')
BLYNK_AUTH = 'YOUR_BLYNK_AUTH'
# connect to WiFi
wifi = WLAN(mode=WLAN.STA)
wifi.connect(WIFI_SSID, auth=WIFI_AUTH, timeout=5000)
while not wifi.isconnected():
pass
print('IP address:', wifi.ifconfig()[0])
# assign GP9, GP10, GP11, GP24 to alternate function (PWM)
p9 = Pin('GP9', mode=Pin.ALT, alt=3)
p10 = Pin('GP10', mode=Pin.ALT, alt=3)
p11 = Pin('GP11', mode=Pin.ALT, alt=3)
p24 = Pin('GP24', mode=Pin.ALT, alt=5)
# timer in PWM mode and width must be 16 buts
timer10 = Timer(4, mode=Timer.PWM, width=16)
timer9 = Timer(3, mode=Timer.PWM, width=16)
timer1 = Timer(1, mode=Timer.PWM, width=16)
# enable channels @1KHz with a 50% duty cycle
pwm9 = timer9.channel(Timer.B, freq=700, duty_cycle=100)
pwm10 = timer10.channel(Timer.A, freq=700, duty_cycle=100)