Python源码示例:machine.reset()

示例1
def setup(name, password, reset=True):
    if name != _cfg.config.wifi_name or \
            password != _cfg.config.wifi_pw:
        _cfg.wifi(name, password)
        print("Updated wifi config.")
        if reset:
            print("Resetting system in 3 seconds.")
            time.sleep(1)
            nr.stop()
            time.sleep(2)
            machine.reset()
        else:
            activate()

# when module loaded the first time start blocking to also bring up netrepl at
# right time 
示例2
def setup(name, password, reset=True):
    if name != _cfg.config.wifi_name or \
            password != _cfg.config.wifi_pw:
        _cfg.wifi(name, password)
        print("Updated wifi config.")
        if reset:
            print("Resetting system in 3 seconds.")
            time.sleep(1)
            nr.stop()
            time.sleep(2)
            machine.reset()
        else:
            activate()

# when module loaded the first time start blocking to also bring up netrepl at
# right time 
示例3
def setup(name, password, reset=True):
    if name != _cfg.config.wifi_name or \
            password != _cfg.config.wifi_pw:
        _cfg.wifi(name, password)
        print("Updated wifi config.")
        if reset:
            print("Resetting system in 3 seconds.")
            time.sleep(1)
            nr.stop()
            time.sleep(2)
            machine.reset()
        else:
            activate()

# when module loaded the first time start blocking to also bring up netrepl at
# right time 
示例4
def setup(name, password, reset=True):
    if name != _cfg.config.wifi_name or \
            password != _cfg.config.wifi_pw:
        _cfg.wifi(name, password)
        print("Updated wifi config.")
        if reset:
            print("Resetting system in 3 seconds.")
            time.sleep(1)
            nr.stop()
            time.sleep(2)
            machine.reset()
        else:
            activate()

# when module loaded the first time start blocking to also bring up netrepl at
# right time 
示例5
def setup(name, password, reset=True):
    if name != _cfg.config.wifi_name or \
            password != _cfg.config.wifi_pw:
        _cfg.wifi(name, password)
        print("Updated wifi config.")
        if reset:
            print("Resetting system in 3 seconds.")
            time.sleep(1)
            nr.stop()
            time.sleep(2)
            machine.reset()
        else:
            activate()

# when module loaded the first time start blocking to also bring up netrepl at
# right time 
示例6
def setup(name, password, reset=True):
    if name != _cfg.config.wifi_name or \
            password != _cfg.config.wifi_pw:
        _cfg.wifi(name, password)
        print("Updated wifi config.")
        if reset:
            print("Resetting system in 3 seconds.")
            time.sleep(1)
            nr.stop()
            time.sleep(2)
            machine.reset()
        else:
            activate()

# when module loaded the first time start blocking to also bring up netrepl at
# right time 
示例7
def __init__(self):
        super().__init__(
            id="relay", name="Wifi Power Socket", type="OW8266-02Q"
        )
        self.led = Pin(4, Pin.OUT, value=1)
        self.r_on = Pin(12, Pin.OUT)
        self.r_off = Pin(5, Pin.OUT)

        self.power_property = HomieNodeProperty(
            id="power",
            name="Relay",
            settable=True,
            retained=True,
            datatype=BOOLEAN,
            default=FALSE,
            restore=True,
        )
        self.add_property(self.power_property, self.on_power_msg)

        self.button = Pushbutton(Pin(14, Pin.IN, Pin.PULL_UP))
        self.button.release_func(self.toggle, ())
        self.button.long_func(reset, (self.led,)) 
示例8
def restart(microWebSrv2: MicroWebSrv2, request: HttpRequest):

        TerkinHttpApi.respond_text(request, 'ACK')

        def do_reset():
            """ """
            log.info('Resetting device')
            microWebSrv2.Stop()
            machine.reset()

        try:
            import _thread
            _thread.start_new_thread(do_reset, ())
        except:
            do_reset()

    # ===========
    # Application
    # =========== 
示例9
def _httpHanderConfig(httpClient, httpResponse) :
	formData  = httpClient.GetRequestQueryParams()
	ssid      = formData.get("ssid")
	password  = formData.get("password")
	other_flg = formData.get("other")
	print(formData)
	content = ''
	is_connected = False

	if other_flg == 'true' or doConnect(ssid, password, False):
		is_connected = True
		saveWiFi(ssid, password)
		content = """<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><style>h1{text-align:center;margin-top:120px;font-size:1.4rem;color:#0064a0}p{text-align:center;font-size:1.1rem}div{width:200px;margin:0 auto;padding-left:60px}</style><title></title></head><body><h1>^_^ WiFi connection success</h1><div><span>Reset device now </span><span id="wating">...</span></div></body><script>var wating=document.getElementById("wating");setInterval(function(){if(wating.innerText==="..."){return wating.innerText="."}wating.innerText+="."},500);</script></html>"""
	else:
		content = """<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><style>h1{text-align:center;margin-top:120px;font-size:1.4rem;color:red}p{text-align:center;font-size:1.1rem}</style><title></title></head><body><h1>×_× WiFi connection failed</h1><p>Click <a href="/">here</a> return configure page.</p></body></html>"""

	httpResponse.WriteResponseOk( headers		 = None,
								  contentType	 = "text/html",
								  contentCharset = "UTF-8",
								  content 		 = content )

	if is_connected:
		lcd.image(0, 0, '/flash/img/1-3.jpg', type=lcd.JPG)
		time.sleep(3)
		wlan_ap.active(False)
		machine.reset() 
示例10
def reboot(delay = 5):
    print('rebooting ...')
    time.sleep(delay)
    machine.reset()

# start a wi-fi access point 
示例11
def reboot(pressed=True):
    machine.reset() 
示例12
def _keepalive(self):
        while True:
            due = self._tim_ka - utime.ticks_diff(utime.ticks_ms(), self._last_wr)
            if due <= 0:
                # error sets ._evfail, .run cancels this coro
                await self._send(b'\n')
            else:
                await asyncio.sleep_ms(due)

    # Read a line from nonblocking socket: reads can return partial data which
    # are joined into a line. Blank lines are keepalive packets which reset
    # the timeout: _readline() pauses until a complete line has been received. 
示例13
def _readline(self, to):
        led = self._led
        line = b''
        start = utime.ticks_ms()
        while True:
            if line.endswith(b'\n'):
                self._ok = True  # Got at least 1 packet after an outage.
                if len(line) > 1:
                    return line
                # Got a keepalive: discard, reset timers, toggle LED.
                self._feed(0)
                line = b''
                if led is not None:
                    if isinstance(led, machine.Pin):
                        led(not led())
                    else:  # On Pyboard D
                        led.toggle()
            try:
                d = self._sock.readline()
            except Exception as e:
                self._verbose and print('_readline exception', d)
                raise
            if d == b'':
                self._verbose and print('_readline peer disconnect')
                raise OSError
            if d is None:  # Nothing received: wait on server
                if utime.ticks_diff(utime.ticks_ms(), start) > to:
                    self._verbose and print('_readline timeout')
                    raise OSError
                await asyncio.sleep_ms(0)
            else:  # Something received: reset timer
                start = utime.ticks_ms()
                line = b''.join((line, d)) if line else d 
示例14
def reset(*args, **kwargs):
    try:
        import machine

        machine.reset()

    except ImportError:
        import microcontroller

        microcontroller.reset() 
示例15
def bootloader(*args, **kwargs):
    try:
        import machine

        machine.bootloader()

    except ImportError:
        import microcontroller

        microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER)
        microcontroller.reset() 
示例16
def reset(self, **kwargs):
        """
        Perform a device reset, similar to the user pushing the RESET button.
        :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.execute`.
        """
        code = '''
import machine
machine.reset()
'''
        return self.execute(code, wait_response=False, **kwargs).output 
示例17
def soft_reset(self, **kwargs):
        """
        Performs a soft reset of the interpreter, deleting all Python objects and resetting the Python heap.
        :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.execute`.
        """
        code = '''
import machine
machine.soft_reset()
'''
        return self.execute(code, wait_response=False, **kwargs).output 
示例18
def deep_sleep(self, seconds: Optional[float] = None, **kwargs):
        """
        Stops execution in an attempt to enter a low power state.
        A deepsleep may not retain RAM or any other state of the system (for example peripherals or network interfaces).
        Upon wake execution is resumed from the main script, similar to a hard or power-on reset.

        :param seconds: Sleep seconds (default: sleep until there are some PIN/RTC events to process)
        :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.execute`.
        """
        code = '''
import machine
machine.deepsleep({msec})
'''.format(msec=int(seconds * 1000) if seconds else '')

        return self.execute(code, wait_response=False, **kwargs).output 
示例19
def handle_command(self, _args):
        import machine
        machine.reset() 
示例20
def reboot():
    import machine
    machine.reset() 
示例21
def reboot() :
    import machine
    machine.reset() 
示例22
def main():
    print("free ram {!r}".format(gc.mem_free()))
    gc.collect()
    loop.create_task(_resetReason())
    config.getMQTT().registerWifiCallback(start_services)

    print("Starting uasyncio loop")
    try:
        loop.run_forever()
    except Exception as e:
        try:
            config.getMQTT().close()
        except:
            pass
        if config.DEBUG_STOP_AFTER_EXCEPTION:
            # want to see the exception trace in debug mode
            if config.USE_SOFTWARE_WATCHDOG:
                wdt.deinit()  # so it doesn't reset the board
            raise e
        # just log the exception and reset the microcontroller
        if sys.platform == "esp8266":
            try:
                rtc.memory("{!s}".format(e).encode())
            except Exception as e:
                print(e)
            print("{!s}".format(e).encode())
        else:
            with open("reset_reason.txt", "w") as f:
                f.write(e)
        machine.reset() 
示例23
def __init__(self, id=0, timeout=120, use_rtc_memory=True):
        self._timeout = timeout / 10
        self._counter = 0
        self._timer = machine.Timer(id)
        self._use_rtc_memory = use_rtc_memory
        self._has_filesystem = False
        self.init()
        asyncio.get_event_loop().create_task(self._resetCounter())
        """ Done in pysmartnode.main
        if use_rtc_memory and platform == "esp8266":
            rtc = machine.RTC()
            if rtc.memory() == b"WDT reset":
                logging.getLogger("WDT").critical("Reset reason: Watchdog")
            rtc.memory(b"")
        elif sys_vars.hasFilesystem():
            self._has_filesystem = True
            try:
                with open("reset_reason.txt", "r") as f:
                    if f.read() == "True":
                        logging.getLogger("WDT").warn("Reset reason: Watchdog")
            except Exception as e:
                print(e)  # file probably just does not exist
            try:
                os.remove("reset_reason.txt")
            except Exception as e:
                logging.getLogger("WDT").error("Error saving to file: {!s}".format(e))
        """ 
示例24
def _wdt(self, t):
        self._counter += self._timeout
        if self._counter >= self._timeout * 10:
            if self._use_rtc_memory and platform == "esp8266":
                rtc = machine.RTC()
                rtc.memory(b"WDT reset")
            elif self._has_filesystem:
                try:
                    with open("reset_reason.txt", "w") as f:
                        f.write("WDT reset")
                except Exception as e:
                    print("Error saving to file: {!s}".format(e))
            machine.reset() 
示例25
def reset():
    machine.reset() 
示例26
def reset():
    machine.reset() 
示例27
def reset():
    machine.reset() 
示例28
def reset():
    machine.reset() 
示例29
def isr(self, pin):
        # debounce
        if time.ticks_diff(time.ticks_ms(), self.last_isr) < 10:
            return

        print('! reset gyro request')
        self.flag_reset_gyro = True
        self.last_isr = time.ticks_ms() 
示例30
def reboot(self):
        log.info("Rebooting board ...")
        import machine
        machine.reset()