本文整理汇总了Python中network.WLAN.ifconfig方法的典型用法代码示例。如果您正苦于以下问题:Python WLAN.ifconfig方法的具体用法?Python WLAN.ifconfig怎么用?Python WLAN.ifconfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network.WLAN
的用法示例。
在下文中一共展示了WLAN.ifconfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connectLocalBox
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [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;
示例2: wlan_connect
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [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()
示例3: connect_wifi
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [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')
示例4: do_connect
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [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())
示例5: connect_to_wifi_wipy
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [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
示例6: connect_wifi
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [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])
示例7: wlan
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [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)
示例8: __init__
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [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())
示例9: wlan
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [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)
示例10: wlan
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [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)
示例11: WLAN
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [as 别名]
# Connect to my WiFi
import machine
from network import WLAN
wlan = WLAN() # get current object, without changing the mode
# Settings for TP-LINK home network
KEY = ''
IP = '192.168.1.253' # WiPy Fixed IP address
GATEWAY = '192.168.1.1' # IP address of gateway
DNS = '192.168.1.1' # IP address of DNS
NETMASK = '255.255.255.0' # Netmask for this subnet
if machine.reset_cause() != machine.SOFT_RESET:
print('Switching to Wifi Device Mode')
wlan.init(WLAN.STA)
wlan.ifconfig(config=(IP, NETMASK, GATEWAY, DNS))
if not wlan.isconnected():
print('Attempting to connect to WiFi', end=' ')
nets = wlan.scan()
for net in nets:
if net.ssid == 'Robotmad':
KEY = 'mou3se43'
break
elif net.ssid == 'CoderDojo':
KEY = 'coderdojo'
break
if KEY != '':
print(net.ssid, end=" ")
wlan.connect(net.ssid, auth=(net.sec, KEY), timeout=10000)
if wlan.isconnected():
示例12: WLAN
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [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)
示例13: WLAN
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [as 别名]
from network import WLAN
import time
import os
import machine
# Substitute your wifi network name & password
SSID = 'My-wifi-network'
AUTH = (WLAN.WPA2, 'My-wifi-password')
# duplicate terminal on USB-UART
uart = machine.UART(0, 115200)
os.dupterm(uart)
# Try connecting in station mode
wlan = WLAN(mode=WLAN.STA)
wlan.ifconfig(config='dhcp')
wlan.connect(ssid=SSID, auth=AUTH)
# Try for 30 seconds
retry = 60
while not wlan.isconnected():
if retry > 0:
time.sleep_ms(500)
print('.', end='')
retry = retry - 1
else:
break
# If connected print ipaddr and info
if wlan.isconnected():
print('Connected to My-wifi-network\n')
示例14: print
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [as 别名]
wifi.antenna(WLAN.EXT_ANT)
print(wifi.antenna() == WLAN.EXT_ANT)
scan_r = wifi.scan()
print(len(scan_r) > 3)
for net in scan_r:
if net.ssid == testconfig.wlan_ssid:
print('Network found')
break
wifi.antenna(WLAN.INT_ANT)
wifi.mode(WLAN.STA)
print(wifi.mode() == WLAN.STA)
wifi.connect(testconfig.wlan_ssid, auth=testconfig.wlan_auth, timeout=10000)
wait_for_connection(wifi)
wifi.ifconfig(config='dhcp')
wait_for_connection(wifi)
print('0.0.0.0' not in wifi.ifconfig())
wifi.ifconfig(0, ('192.168.178.109', '255.255.255.0', '192.168.178.1', '8.8.8.8'))
wait_for_connection(wifi)
print(wifi.ifconfig(0) == ('192.168.178.109', '255.255.255.0', '192.168.178.1', '8.8.8.8'))
wait_for_connection(wifi)
print(wifi.isconnected() == True)
wifi.disconnect()
print(wifi.isconnected() == False)
t0 = time.ticks_ms()
wifi.connect(testconfig.wlan_ssid, auth=testconfig.wlan_auth, timeout=0)
print(time.ticks_ms() - t0 < 500)
示例15: Pin
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import ifconfig [as 别名]
RMotorB = Pin('GPIO8', af=0, mode=Pin.OUT)
LMotorB.low()
RMotorB.low()
# assign GPIO9 and 10 to alternate function 3 (PWM)
# These will be the pins to control speed
LMotorA = Pin('GPIO9', af=3, type=Pin.STD)
RMotorA = Pin('GPIO10', af=3, type=Pin.STD)
# Enable timer channels 3B and 4A for PWM pins
LMTimer = Timer(3, mode=Timer.PWM, width=16)
RMTimer = Timer(4, mode=Timer.PWM, width=16)
# enable channel A @1KHz with a 50% duty cycle
LMT_a = LMTimer.channel(Timer.B, freq=1000, duty_cycle=50)
RMT_a = RMTimer.channel(Timer.A, freq=1000, duty_cycle=50)
def Setup_WIFI()
wifi = WLAN(WLAN.STA)
# go for fixed IP settings
wifi.ifconfig('192.168.0.107', '255.255.255.0', '192.168.0.1', '8.8.8.8')
wifi.scan() # scan for available netrworks
wifi.connect(ssid='mynetwork', security=2, key='mynetworkkey')
while not wifi.isconnected():
pass
print(wifi.ifconfig())
# enable wake on WLAN
wifi.callback(wakes=Sleep.SUSPENDED)
# go to sleep
Sleep.suspend()
# now, connect to the FTP or the Telnet server and the WiPy will wake-up