当前位置: 首页>>代码示例>>Python>>正文


Python WLAN.init方法代码示例

本文整理汇总了Python中network.WLAN.init方法的典型用法代码示例。如果您正苦于以下问题:Python WLAN.init方法的具体用法?Python WLAN.init怎么用?Python WLAN.init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在network.WLAN的用法示例。


在下文中一共展示了WLAN.init方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wlan

# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import init [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)
开发者ID:hoihu,项目名称:wipy-environment,代码行数:43,代码来源:autoconfig.py

示例2: wlan

# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import init [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)
开发者ID:zsquareplusc,项目名称:wipy-environment,代码行数:39,代码来源:autoconfig.py

示例3: wlan

# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import init [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)
开发者ID:talpah,项目名称:wipy-environment,代码行数:26,代码来源:autoconfig.py

示例4: WLAN

# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import init [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)
开发者ID:CoderDojoOlney,项目名称:PYCR-MicroPython,代码行数:32,代码来源:boot.py

示例5: print

# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import init [as 别名]
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)

wifi.disconnect()
print(wifi.isconnected() == False)

# test init again
wifi.init(WLAN.AP, ssid='www.wipy.io', auth=None, channel=5, antenna=WLAN.INT_ANT)

print(len(wifi.mac()) == 6)

# next ones MUST raise
try:
    wifi.init(mode=12345)
except:
    print('Exception')

try:
    wifi.init(1, mode=WLAN.AP)
except:
    print('Exception')

try:
开发者ID:worker-bee-micah,项目名称:micropython,代码行数:33,代码来源:wlan.py

示例6: WLAN

# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import init [as 别名]
# can run arbitrary Python, but best to keep it minimal

import os

import machine
from network import WLAN

# disable LED matrix first
latch = machine.Pin('GP13', mode=machine.Pin.OUT)
latch.value(0)

spi = machine.SPI(0, mode=machine.SPI.MASTER, bits=32, pins=('GP14', 'GP16', 'GP15'))
spi.write(b'\x00\x00\x00\x00')
latch.value(1)

# repl on serial
os.dupterm(machine.UART(0, 115200))

# now wifi
wlan = WLAN()

if machine.reset_cause() != machine.SOFT_RESET:
    wlan.init(WLAN.STA)
    wlan.ifconfig(config=('192.168.1.254', '255.255.255.0', '192.168.1.1', '192.168.1.1'))

if not wlan.isconnected():
    # change the line below to match your network ssid, security and password
    wlan.connect('XXX', auth=(WLAN.WPA2, 'XXX'), timeout=5000)
    while not wlan.isconnected():
        machine.idle()
开发者ID:chassing,项目名称:pyq2,代码行数:32,代码来源:boot.py


注:本文中的network.WLAN.init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。