python类idle()的实例源码

_wifi.py 文件源码 项目:ulnoiot 作者: ulno 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def connect():
    global wifi_cfg,  _wlan

    _ap.active(False)
    _wlan.active(True)

    # removed scan of networks to allow connect to hidden essid
    # Try to connect
    _wlan.connect(wifi_cfg.name, wifi_cfg.password)
    tries=15
    for i in range(tries):
        print("%d/%d. Trying to connect." %(i+1, tries))
        machine.idle()
        time.sleep(1)
#                if _wlan.isconnected(): break
        if _wlan.status() == network.STAT_GOT_IP: break

    if _wlan.isconnected() and _wlan.status() == network.STAT_GOT_IP:
        print('Wifi: connection succeeded!')
        print(_wlan.ifconfig())
    else:
        print('Wifi: connection failed, starting accesspoint!')
        accesspoint()
    nr.start(nostop=True)
blynklib.py 文件源码 项目:micropython-share 作者: pacmac 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def sleep_from_until (start, delay):
  ## while time.ticks_diff(start, time.ticks_ms()) < delay:
  while time.ticks_diff(time.ticks_ms(),start) < delay:
    machine.idle()
  return start + delay
OTA.py 文件源码 项目:pycom-libraries 作者: pycom 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def connect(self):
        self.wlan = network.WLAN(mode=network.WLAN.STA)
        if not self.wlan.isconnected() or self.ssid() != self.SSID:
            for net in self.wlan.scan():
                if net.ssid == self.SSID:
                    self.wlan.connect(self.SSID, auth=(network.WLAN.WPA2,
                                                       self.password))
                    while not self.wlan.isconnected():
                        machine.idle()  # save power while waiting
                    break
            else:
                raise Exception("Cannot find network '{}'".format(SSID))
        else:
            # Already connected to the correct WiFi
            pass
OTA.py 文件源码 项目:pycom-libraries 作者: pycom 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def connect(self):
        self.wlan = network.WLAN(mode=network.WLAN.STA)
        if not self.wlan.isconnected() or self.ssid() != self.SSID:
            for net in self.wlan.scan():
                if net.ssid == self.SSID:
                    self.wlan.connect(self.SSID, auth=(network.WLAN.WPA2,
                                                       self.password))
                    while not self.wlan.isconnected():
                        machine.idle()  # save power while waiting
                    break
            else:
                raise Exception("Cannot find network '{}'".format(SSID))
        else:
            # Already connected to the correct WiFi
            pass
lcd160cr.py 文件源码 项目:micropython-lcd160cr-gui 作者: peterhinch 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def oflush(self, n=255):
        t = 5000
        while t:
            self.i2c.readfrom_into(self.i2c_addr + 1, self.buf1)
            r = self.buf1[0]
            if r >= n:
                return
            t -= 1
            machine.idle()
        raise OSError(uerrno.ETIMEDOUT)
nodered_dht22.py 文件源码 项目:micropython-dev-kit 作者: db4linq 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def setup():
    global d
    d = dht.DHT22(Pin(2)) 
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    cfg = load_config()
    ap = cfg['ap']
    wlan.connect(ap['ssid'], ap['pwd'])
    while not wlan.isconnected():
        machine.idle()
    wifi(cfg['mqtt'])


问题


面经


文章

微信
公众号

扫码关注公众号