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

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

项目:templogger    作者:aequitas    | 项目源码 | 文件源码
def templog(sleep=True):
    """Log voltage and temperature to MQTT."""
    start = time.ticks_ms()

    # get sensor values
    values = read_voltage()
    values.update(read_temps())
    print(values)

    # send values over MQTT if connected
    if wait_connect():
        if not mqtt_send(values):
            machine.reset()
    else:
        # failed to connect, reboot
        machine.reset()

    if sleep:
        delta = time.ticks_diff(start, time.ticks_ms())
        deepsleep(delta)
项目:illuminOS    作者:idimitrakopoulos    | 项目源码 | 文件源码
def sleep(self, milliseconds):
        # To be able to use this fea
        import machine

        # configure RTC.ALARM0 to be able to wake the device
        rtc = machine.RTC()
        rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)

        # set RTC.ALARM0 to fire after some milliseconds
        rtc.alarm(rtc.ALARM0, milliseconds)

        # put the device to sleep
        machine.deepsleep()
项目:esp32    作者:smeenka    | 项目源码 | 文件源码
def wlanOff():
    log.info("In about 15 minutes wifi will be switched off.")
    yield
    yield
    yield asyncio.Wait(1000 * 60 * 15)
    log.info("Switching off wifi. going to lowpower")
    wifi.ap.active(False)
    wifi.wlan.active(False)    
    machine.deepsleep(1)
项目:MicroPython    作者:Euter2    | 项目源码 | 文件源码
def go_sleep(sleep_minutes):
    """Perform deepsleep to save energy."""
    rtc = machine.RTC()
    rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
    # ticks_ms is used to make wake up period more consistent
    sleep_seconds = (sleep_minutes * 60) - (ticks_ms() // 1000)
    rtc.alarm(rtc.ALARM0, sleep_seconds * 1000)
    print(str(sleep_seconds // 60) +
          ":" + str(sleep_seconds % 60) +
          " minutes deep sleep NOW!")
    machine.deepsleep()
项目:templogger    作者:aequitas    | 项目源码 | 文件源码
def deepsleep(uptime=0, calibrate=False):
    """Put to sleep for 60 seconds minus uptime."""
    rtc = machine.RTC()
    rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
    sleeptime = max(MIN_INTERVAL, (INTERVAL_SEC * 1000) - uptime)
    rtc.alarm(rtc.ALARM0, sleeptime)
    machine.deepsleep()
项目:esp8266    作者:fadushin    | 项目源码 | 文件源码
def deep_sleep(secs) :
    import machine

    # configure RTC.ALARM0 to be able to wake the device
    rtc = machine.RTC()
    rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)

    # set RTC.ALARM0 to fire after 10 seconds (waking the device)
    rtc.alarm(rtc.ALARM0, secs)

    # put the device to sleep
    machine.deepsleep()
项目:uPython-esp8266-httpserver    作者:ernitron    | 项目源码 | 文件源码
def gotosleep(sleep_timeout):
    # Remember for this to work GPIO16 (D0) must be connected to RST
    # configure RTC.ALARM0 to be able to wake the device
    rtc = machine.RTC()
    rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)

    # set RTC.ALARM0 to fire after a while (waking the device)
    sleep_timeout = sleep_timeout * 1000 # in microseconds
    rtc.alarm(rtc.ALARM0, sleep_timeout)

    # put the device to sleep
    print('Sleep for %d usec' % sleep_timeout)
    machine.deepsleep()
项目:MASUGUX    作者:DjamesSuhanko    | 项目源码 | 文件源码
def now(self):
        """Rotina a ser chamada no boot.py.
        0 - coleta temperatura e publica
        1 - fica em loop ate que seja publicado que pode dormir
        2 - faz a rotina de dormir. Dorme no intervalo definido em self.SLEEP_TIME
        3 - quando der o timeout, acorda, coleta, envia e repete.
        """
        size = 0
        print("Estabelecendo conexao de rede...")
        while size < 11:
            try:
                size = len(self.sta_if.ifconfig()[0])
                time.sleep_ms(80)
            except:
                size = 0

        print("setting callback...")
        self.myMQTT.set_callback(self.sub_cb)
        print("connecting for...")
        self.myMQTT.connect()

        print("Subscribe for sleep...")
        self.myMQTT.subscribe(b'freezer/sleep')
        print("Publishing termometer status")
        self.myMQTT.publish(b'freezer/termometro',b'ON')
        # coleta e publica temperatura...
        print("Coletando temperatura e publicando...")
        t = self.tasks()

        # ...aguarda por ordem de dormir...
        print("Aguardando ordem para dormir...")
        self.waiting()
        if self.DO_SLEEP:
            self.myMQTT.publish("freezer/termometro", "OFF")
            print("Dormindo. Ate logo.")
            # ...inicia processo de deepsleep.
            self.DO_SLEEP = False
            rtc = machine.RTC()
            rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)

            # wake up after...
            rtc.alarm(rtc.ALARM0, self.SLEEP_TIME)

            # sleep
            machine.deepsleep()