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

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

项目: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)
项目:esp32    作者:smeenka    | 项目源码 | 文件源码
def modeStation(self):   
        log.debug ("modeStation") 
        server = self.server
        server.resetRouteTable()
        server.onEnd(".css",    self.handleStatic )
        server.onEnd(".js",     self.handleStatic )
        self.server.onExact("/",           self.handleRoot )
        self.server.onExact("/index.html", self.handleRoot )
        self.server.onExact("/aplist.html", self.handleApList )
        self.server.onExact("/ap.html", self.handleAp )
        self.server.onExact("/station.html", self.handleStation )
        self.server.onExact("/kill/os", self.handleKillOs )
        self.server.onExact("/get_ip", self.handleGetIp )
        self.server.onPost("/settings", self.handleStationSettings)
        self.server.onPost("/set_ssid", self.handleSetSSID)
        self.server.onExact("/reset", self.handleReset)
        self.server.onStart("/mode/", self.handleMode)
        log.debug ("finished modeStation")
项目:ulnoiot    作者:ulno    | 项目源码 | 文件源码
def setup( name,  password, reset=True ):
    global wifi_cfg

    if name != wifi_cfg.name or \
          password != wifi_cfg.password:
        f=open(_config_file, "w")
        f.write("name=\"%s\"\npassword=\"%s\"" % (name,password))
        f.close()
        print("Updated wifi_cfg.")
        wifi_cfg.name = name
        wifi_cfg.password = password
        if reset:
            print("Resetting system in 3 seconds.")
            time.sleep(1)
            #webrepl.stop()
            nr.stop()
            time.sleep(2)
            machine.reset()
        else:
            connect()

# Try to find wifi_cfg
项目:uPython-ESP8266-01-umqtt    作者:phieber    | 项目源码 | 文件源码
def main():
    while True:
        try:
            i2c = machine.I2C(scl=machine.Pin(0), sda=machine.Pin(2))
            bme = bme280.BME280(i2c=i2c, address=119)

            c.connect()
            c.publish(b"heartbeat", CLIENT_ID)

            c.publish(CLIENT_ID + "/temperature", bme.values[0])
            c.publish(CLIENT_ID + "/pressure", bme.values[1])
            c.publish(CLIENT_ID + "/humidity", bme.values[2])
            print("published msg")

        except Exception as e:
            print(str(e))
            machine.reset()
        finally:
            c.disconnect()
        time.sleep(5)
项目:uPython-ESP8266-01-umqtt    作者:phieber    | 项目源码 | 文件源码
def main():
    c = initMQTT()

    while True:
        try:
            c.connect()
            c.publish(b"heartbeat", getClientID())
            print("publish msg")
            #c.disconnect()

            # read ds18x20 sensors
            values = readDS18x20()
            for value in values:
                #c.connect()
                pubMQTT(c, str(values.index(value)), str(value))
                #c.disconnect()

        except Exception as e:
            print(str(e))
            time.sleep(10)
            import machine
            machine.reset()
        finally:
            c.disconnect()
        time.sleep(5)
项目:illuminOS    作者:idimitrakopoulos    | 项目源码 | 文件源码
def reboot(self):
        log.info("Rebooting board ...")
        import machine
        machine.reset()
项目:esp32    作者:smeenka    | 项目源码 | 文件源码
def __init__(self,httpserver ):
        log.debug ("Constructor WebServer") 
        self.server = httpserver 

        server = self.server
        server.resetRouteTable()
        server.onEnd(".css",    self.handleStatic )
        server.onEnd(".js",     self.handleStatic )
        self.server.onExact("/servos/positions", self.handleGetPos)

        self.server.onExact("/",           self.handleRoot )
        self.server.onExact("/index.html", self.handleRoot )
        self.server.onExact("/aplist.html", self.handleApList )
        self.server.onExact("/ap.html", self.handleAp )
        self.server.onExact("/station.html", self.handleStation )
        self.server.onExact("/reset", self.handleReset)

        self.server.onExact("/kill/os", self.handleKillOs )
        self.server.onExact("/get_ip", self.handleGetIp )

        self.server.onPost ("/servos/position", self.handleSetPos)
        self.server.onPost ("/servos/speed", self.handleSetSpeed)
        self.server.onPost ("/servos/gain", self.handleSetGain)
        self.server.onPost ("/servos/id", self.handleSetId)
        self.server.onPost ("/servos/off", self.handleSetOff)
        self.server.onPost ("/servos/all", self.handleSetAll)
        self.server.onPost ("/set_ssid", self.handleSetSSID)
项目:esp32    作者:smeenka    | 项目源码 | 文件源码
def handleReset(self):
        log.debug ("Reset requested")
        import machine
        yield
        machine.reset()
项目:esp32    作者:smeenka    | 项目源码 | 文件源码
def handleReset(self):
        log.debug ("Reset of clock requested")
        import machine
        yield
        machine.reset()
项目:automatic-fiesta    作者:Narcolapser    | 项目源码 | 文件源码
def reboot(val,telServer=None):
    if telServer:
        telServer.conn.sendall("Rebooting...\n\000")
        telServer.conn.close()

    import machine
    machine.reset()
项目:automatic-fiesta    作者:Narcolapser    | 项目源码 | 文件源码
def reboot(val,telServer=None):
    if telServer:
        telServer.conn.sendall(telServer.content.format("Rebooting","Rebooting...\n\000"))
        telServer.conn.close()

    import machine
    machine.reset()
项目:ulnoiot    作者:ulno    | 项目源码 | 文件源码
def reset():
    machine.reset()
项目:esp-bootstrap    作者:craftyguy    | 项目源码 | 文件源码
def sock_cb(s):
    client , _ = s.accept()
    try:
        # read checksum from sender
        checksum_orig = client.read(CHECKSUM_SIZE)
        #print_c("Checksum received:")
        #print_hex(checksum_orig)
        with open(TMP_FILENAME, 'w') as f:
            chunk = client.read(CHUNK_SIZE)
            while len(chunk) > 0:
                f.write(chunk.decode())
                chunk = client.read(CHUNK_SIZE)
    except Exception as e:
        print_c("exception: {0}".format(e))
    finally:
        client.close()

    checksum = chksum_file(TMP_FILENAME)
    #print_c("Checksum:")
    #print_hex(checksum)
    if checksum != checksum_orig:
        print_c("Checksum: FAILED")
        print_c("User app NOT updated")
        return
    if not config.SILENT:
        print_c("Checksum: OK")
    # Back up old application if it exists
    for f in os.listdir():
        if f == APP_FILENAME:
            os.rename(APP_FILENAME, APP_BAK_FILENAME)
    # "apply" backup and reset system
    os.rename(TMP_FILENAME, APP_FILENAME)
    reset()


# Calculate checksum of file using SHA256, return checksum as byte array
项目:py-mpu6050    作者:larsks    | 项目源码 | 文件源码
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()
项目:esp8266    作者:fadushin    | 项目源码 | 文件源码
def reboot():
    import machine
    machine.reset()
项目:esp8266    作者:fadushin    | 项目源码 | 文件源码
def reboot() :
    import machine
    machine.reset()
项目:esp8266    作者:fadushin    | 项目源码 | 文件源码
def handle_command(self, _args):
        import machine
        machine.reset()
项目:pyCom    作者:dinosd    | 项目源码 | 文件源码
def reset():
    machine.reset()
项目:pyCom    作者:dinosd    | 项目源码 | 文件源码
def ap_set(ssid, pwd):
    CODA_CONFIG["lastssid"] = ssid
    CODA_CONFIG["lastappwd"] = pwd
    coda_save_config()
    machine.reset()
项目:pyCom    作者:dinosd    | 项目源码 | 文件源码
def reboot():
    machine.reset()
项目:pycom-libraries    作者:pycom    | 项目源码 | 文件源码
def update(self):
        manifest = self.get_update_manifest()
        if manifest is None:
            print("Already on the latest version")
            return

        # Download new files and verify hashes
        for f in manifest['new'] + manifest['update']:
            # Upto 5 retries
            for _ in range(5):
                try:
                    self.get_file(f)
                    break
                except Exception as e:
                    print(e)
                    msg = "Error downloading `{}` retrying..."
                    print(msg.format(f['URL']))
            else:
                raise Exception("Failed to download `{}`".format(f['URL']))

        # Backup old files
        # only once all files have been successfully downloaded
        for f in manifest['update']:
            self.backup_file(f)

        # Rename new files to proper name
        for f in manifest['new'] + manifest['update']:
            new_path = "{}.new".format(f['dst_path'])
            dest_path = "{}".format(f['dst_path'])

            os.rename(new_path, dest_path)

        # `Delete` files no longer required
        # This actually makes a backup of the files incase we need to roll back
        for f in manifest['delete']:
            self.delete_file(f)

        # Flash firmware
        if "firmware" in manifest:
            self.write_firmware(manifest['firmware'])

        # Save version number
        try:
            self.backup_file({"dst_path": "/flash/OTA_VERSION.py"})
        except OSError:
            pass  # There isnt a previous file to backup
        with open("/flash/OTA_VERSION.py", 'w') as fp:
            fp.write("VERSION = '{}'".format(manifest['version']))
        from OTA_VERSION import VERSION

        # Reboot the device to run the new decode
        machine.reset()
项目:pycom-libraries    作者:pycom    | 项目源码 | 文件源码
def update(self):
        manifest = self.get_update_manifest()
        if manifest is None:
            print("Already on the latest version")
            return

        # Download new files and verify hashes
        for f in manifest['new'] + manifest['update']:
            # Upto 5 retries
            for _ in range(5):
                try:
                    self.get_file(f)
                    break
                except Exception as e:
                    print(e)
                    print("Error downloading `{}` retrying...".format(f['URL']))
            else:
                raise Exception("Failed to download `{}`".format(f['URL']))

        # Backup old files
        # only once all files have been successfully downloaded
        for f in manifest['update']:
            self.backup_file(f)

        # Rename new files to proper name
        for f in manifest['new'] + manifest['update']:
            new_path = "{}.new".format(f['dst_path'])
            dest_path = "{}".format(f['dst_path'])

            os.rename(new_path, dest_path)

        # `Delete` files no longer required
        # This actually makes a backup of the files incase we need to roll back
        for f in manifest['delete']:
            self.delete_file(f)

        # Flash firmware
        if "firmware" in manifest:
            self.write_firmware(manifest['firmware'])

        # Save version number
        try:
            self.backup_file({"dst_path": "/flash/OTA_VERSION.py"})
        except OSError:
            pass  # There isnt a previous file to backup
        with open("/flash/OTA_VERSION.py", 'w') as fp:
            fp.write("VERSION = '{}'".format(manifest['version']))
        from OTA_VERSION import VERSION

        # Reboot the device to run the new decode
        machine.reset()
项目:automatic-fiesta    作者:Narcolapser    | 项目源码 | 文件源码
def main(use_stream=False):
    s = socket.socket()

    # Binding to all interfaces - server will be accessible to other hosts!
    ai = socket.getaddrinfo("0.0.0.0", 8080)
    print("Bind address info:", ai)
    addr = ai[0][-1]

    #prepping LED pin
    p = Pin(2,Pin.OUT)
#   p.high()
#   time.sleep(1)
#   p.low()


    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.bind(addr)
    s.listen(5)
    print("Listening, connect your browser to http://<this_host>:8080/")

    counter = 0
    while True:
        res = s.accept()
        client_s = res[0]
        client_addr = res[1]
        print("Client address:", client_addr)
        print("Client socket:", client_s)
        print("Request:")
        if use_stream:
            # MicroPython socket objects support stream (aka file) interface
            # directly.
            #print(client_s.read(4096))
            val = client_s.read(4096)
            print(val)
            client_s.write(CONTENT % counter)
        else:
            #print(client_s.recv(4096))
            val = client_s.recv(4096)
            print(val)
            client_s.send(CONTENT % counter)
        if "GET /toggle" in val:
            print("Toggling!")
            p.high()
            time.sleep(1)
            p.low()
            machine.reset()
        client_s.close()
        counter += 1
        print()