Python machine 模块,idle() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用machine.idle()

项目:ulnoiot    作者:ulno    | 项目源码 | 文件源码
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)
项目:micropython-share    作者:pacmac    | 项目源码 | 文件源码
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
项目:pycom-libraries    作者:pycom    | 项目源码 | 文件源码
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
项目:pycom-libraries    作者:pycom    | 项目源码 | 文件源码
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
项目:micropython-lcd160cr-gui    作者:peterhinch    | 项目源码 | 文件源码
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)
项目:micropython-dev-kit    作者:db4linq    | 项目源码 | 文件源码
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'])