本文整理汇总了Python中network.WLAN.scan方法的典型用法代码示例。如果您正苦于以下问题:Python WLAN.scan方法的具体用法?Python WLAN.scan怎么用?Python WLAN.scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network.WLAN
的用法示例。
在下文中一共展示了WLAN.scan方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connectLocalBox
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import scan [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 scan [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: __init__
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import scan [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
示例4: connect
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import scan [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
示例5: __init__
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import scan [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())
示例6: connect_to_ap
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import scan [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
示例7: connect_wifi
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import scan [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])
示例8: print
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import scan [as 别名]
# 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():
print('Connected')
tim_a.freq(10)
wlan.irq(trigger=WLAN.ANY_EVENT, wake=machine.SLEEP)
else :
示例9: dupterm
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import scan [as 别名]
# boot.py -- run on boot-up
# can run arbitrary Python, but best to keep it minimal
# Copy config.example.py to config.py and modify to your needs first!
import config
import machine
#from machine import UART
from os import dupterm
uart = machine.UART(0, 115200)
dupterm(uart)
if machine.reset_cause() != machine.SOFT_RESET:
from network import WLAN
wifi = WLAN()
wifi.mode(WLAN.STA)
ssids = wifi.scan()
found = False
for net in ssids:
print("Checking %s" % net.ssid)
if net.ssid == config.HOME_SSID:
print("Found %s!" % net.ssid)
wifi.connect(config.HOME_SSID, auth=(WLAN.WPA, config.HOME_PASSWORD))
found = True
break
if not found:
print("No eligible WiFi found.")
wifi.mode(WLAN.AP)
示例10: WLAN
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import scan [as 别名]
wifi = WLAN(mode=WLAN.AP)
print(wifi.mode() == WLAN.AP)
print(wifi.channel() == 1)
print(wifi.auth() == None)
print(wifi.antenna() == WLAN.INT_ANT)
wifi = WLAN(0, mode=WLAN.AP, ssid='test-wlan', auth=(WLAN.WPA, '123456abc'), channel=7)
print(wifi.mode() == WLAN.AP)
print(wifi.channel() == 7)
print(wifi.ssid() == 'test-wlan')
print(wifi.auth() == (WLAN.WPA, '123456abc'))
print(wifi.antenna() == WLAN.INT_ANT)
wifi = WLAN(mode=WLAN.STA)
print(wifi.mode() == WLAN.STA)
scan_r = wifi.scan()
print(len(scan_r) > 3)
for net in scan_r:
if net.ssid == testconfig.wlan_ssid:
# test that the scan results contains the desired params
print(len(net.bssid) == 6)
print(net.channel == None)
print(net.sec == testconfig.wlan_auth[0])
print(net.rssi < 0)
print('Network found')
break
wifi.mode(WLAN.STA)
print(wifi.mode() == WLAN.STA)
wifi.channel(7)
print(wifi.channel() == 7)
示例11: Pin
# 需要导入模块: from network import WLAN [as 别名]
# 或者: from network.WLAN import scan [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