我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用machine.reset()。
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)
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")
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
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)
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)
def reboot(self): log.info("Rebooting board ...") import machine machine.reset()
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)
def handleReset(self): log.debug ("Reset requested") import machine yield machine.reset()
def handleReset(self): log.debug ("Reset of clock requested") import machine yield machine.reset()
def reboot(val,telServer=None): if telServer: telServer.conn.sendall("Rebooting...\n\000") telServer.conn.close() import machine machine.reset()
def reboot(val,telServer=None): if telServer: telServer.conn.sendall(telServer.content.format("Rebooting","Rebooting...\n\000")) telServer.conn.close() import machine machine.reset()
def reset(): machine.reset()
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
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()
def reboot(): import machine machine.reset()
def reboot() : import machine machine.reset()
def handle_command(self, _args): import machine machine.reset()
def ap_set(ssid, pwd): CODA_CONFIG["lastssid"] = ssid CODA_CONFIG["lastappwd"] = pwd coda_save_config() machine.reset()
def reboot(): machine.reset()
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()
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()
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()