• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python network.WLAN类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __init__

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
开发者ID:theta360developers,项目名称:wipy-theta,代码行数:60,代码来源:theta.py


示例2: connect

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
开发者ID:Ortofta,项目名称:wipy,代码行数:10,代码来源:wifi_station.py


示例3: disconnectWLAN

 def disconnectWLAN(self):
  try:
   from network import WLAN
   wlan=None
   if self.isWipy1():
    wlan=WLAN()
   else:
    wlan=WLAN(mode=WLAN.STA)
   wlan.disconnect()
  except:
   pass
开发者ID:ainehanta,项目名称:pymakr-atom,代码行数:11,代码来源:monitor.py


示例4: enable_ap_mode

def enable_ap_mode(essid=None, password=None):
    from network import AP_IF, AUTH_WPA_WPA2_PSK, WLAN
    from ubinascii import hexlify

    wifi_interface = WLAN(AP_IF)
        
    if not essid:
        essid = b"micropython-esp8266-%s" % hexlify(wifi_interface.config("mac")[-3:])
    if not password:
        password = b'micropybootconfig'

    wifi_interface.config(essid=essid, authmode=AUTH_WPA_WPA2_PSK, password=password)
    del hexlify
开发者ID:dwighthubbard,项目名称:micropython-bootconfig,代码行数:13,代码来源:wifi.py


示例5: wlan_connect

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()
开发者ID:aidium,项目名称:WiPy,代码行数:14,代码来源:init.py


示例6: connect_to_wifi_wipy

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
开发者ID:dwighthubbard,项目名称:micropython-bootconfig,代码行数:15,代码来源:wifi.py


示例7: disconnectWLAN

    def disconnectWLAN(self):
        # disconnect wlan because it spams debug messages that disturb the monitor protocol
        try:
            from network import WLAN
            wlan = None
            if self.isWipy1():
                wlan = WLAN()
            else:
                wlan = WLAN(mode=WLAN.STA)

            wlan.disconnect()
        except:
            # if wifi disconnect fails for whatever reason, let it continue to sync
            # often this is the 'OSError: the requested oparation is not possible' thrown by the wlan.disconnect line
            pass
开发者ID:ainehanta,项目名称:pymakr-atom,代码行数:15,代码来源:monitor.py


示例8: start

    def start(self):
        # Change WiFi to STA mode and connect
        self.wlan = WLAN(mode=WLAN.STA)
        self._connect_to_wifi()

        # Get a time Sync
        self.rtc = machine.RTC()
        self.rtc.ntp_sync(self.ntp, update_period=self.ntp_period)

        # Get the server IP and create an UDP socket
        self.server_ip = socket.getaddrinfo(self.server, self.port)[0][-1]
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.sock.setblocking(False)

        # Push the first time immediatelly
        self._push_data(self._make_stat_packet())

        # Create the alarms
        self.stat_alarm = Timer.Alarm(handler=lambda t: self._push_data(self._make_stat_packet()), s=60, periodic=True)
        self.pull_alarm = Timer.Alarm(handler=lambda u: self._pull_data(), s=25, periodic=True)

        # Start the UDP receive thread
        _thread.start_new_thread(self._udp_thread, ())

        # Initialize LoRa in LORA mode
        self.lora = LoRa(mode=LoRa.LORA, frequency=self.frequency, bandwidth=LoRa.BW_125KHZ, sf=self.sf,
                         preamble=8, coding_rate=LoRa.CODING_4_5, tx_iq=True)
        # Create a raw LoRa socket
        self.lora_sock = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
        self.lora_sock.setblocking(False)
        self.lora_tx_done = False

        self.lora.callback(trigger=(LoRa.RX_PACKET_EVENT | LoRa.TX_PACKET_EVENT), handler=self._lora_cb)
开发者ID:AndersonJV,项目名称:IoT_ICTP_Workshop,代码行数:34,代码来源:nanogateway.py


示例9: __init__

 def __init__(self):
     self.sock = None
     self.connected = False
     self.wlan = WLAN(mode=WLAN.STA)
     self.riders = {} # dictionary of riders
     # initialize LoRa as a Gateway (with Tx IQ inversion)
     self.lora = LoRa(tx_iq=True, rx_iq=False)
开发者ID:danicampora,项目名称:lopy_ews,代码行数:7,代码来源:gateway.py


示例10: do_connect

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())
开发者ID:Naish21,项目名称:themostat,代码行数:10,代码来源:main.py


示例11: connectLocalBox

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;
开发者ID:gabriel-farache,项目名称:homautomation,代码行数:12,代码来源:sendData.py


示例12: start

    def start(self):
        """
        Starts the LoRaWAN nano gateway.
        """

        self._log('Starting LoRaWAN nano gateway with id: {}', self.id)

        # setup WiFi as a station and connect
        self.wlan = WLAN(mode=WLAN.STA)
        self._connect_to_wifi()

        # get a time sync
        self._log('Syncing time with {} ...', self.ntp_server)
        self.rtc.ntp_sync(self.ntp_server, update_period=self.ntp_period)
        while not self.rtc.synced():
            utime.sleep_ms(50)
        self._log("RTC NTP sync complete")

        # get the server IP and create an UDP socket
        self.server_ip = usocket.getaddrinfo(self.server, self.port)[0][-1]
        self._log('Opening UDP socket to {} ({}) port {}...', self.server, self.server_ip[0], self.server_ip[1])
        self.sock = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM, usocket.IPPROTO_UDP)
        self.sock.setsockopt(usocket.SOL_SOCKET, usocket.SO_REUSEADDR, 1)
        self.sock.setblocking(False)

        # push the first time immediatelly
        self._push_data(self._make_stat_packet())

        # create the alarms
        self.stat_alarm = Timer.Alarm(handler=lambda t: self._push_data(self._make_stat_packet()), s=60, periodic=True)
        self.pull_alarm = Timer.Alarm(handler=lambda u: self._pull_data(), s=25, periodic=True)

        # start the UDP receive thread
        self.udp_stop = False
        _thread.start_new_thread(self._udp_thread, ())

        # initialize the LoRa radio in LORA mode
        self._log('Setting up the LoRa radio at {:.1f} Mhz using {}', self._freq_to_float(self.frequency), self.datarate)
        self.lora = LoRa(
            mode=LoRa.LORA,
            frequency=self.frequency,
            bandwidth=self.bw,
            sf=self.sf,
            preamble=8,
            coding_rate=LoRa.CODING_4_5,
            tx_iq=True
        )

        # create a raw LoRa socket
        self.lora_sock = usocket.socket(usocket.AF_LORA, usocket.SOCK_RAW)
        self.lora_sock.setblocking(False)
        self.lora_tx_done = False

        self.lora.callback(trigger=(LoRa.RX_PACKET_EVENT | LoRa.TX_PACKET_EVENT), handler=self._lora_cb)
        self._log('LoRaWAN nano gateway online')
开发者ID:H-LK,项目名称:pycom-libraries,代码行数:55,代码来源:nanogateway.py


示例13: wlan

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,代码行数:41,代码来源:autoconfig.py


示例14: wlan

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,代码行数:37,代码来源:autoconfig.py


示例15: connect_wifi

    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])
开发者ID:widget,项目名称:iot-display,代码行数:24,代码来源:display.py


示例16: connect_wifi

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')
开发者ID:widget,项目名称:iot-display,代码行数:15,代码来源:tools.py


示例17: connect_to_ap

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
开发者ID:yschaeff,项目名称:ICantBelieveItsNotDNS,代码行数:20,代码来源:boot.py


示例18: connect_to_wifi

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
开发者ID:dwighthubbard,项目名称:micropython-bootconfig,代码行数:19,代码来源:wifi.py


示例19: wlan

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,代码行数:24,代码来源:autoconfig.py


示例20: __init__

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())
开发者ID:nostalgio,项目名称:shop-o-data,代码行数:21,代码来源:wifi.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python nettestlib.dummy_devices函数代码示例发布时间:2022-05-27
下一篇:
Python network.Network类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap