def cmd_reboot(params): print("Rebooting unit...") try: cli.execute("reboot", 10) except: print("Failed to run 'reboot' command") return HTTPStatus.INTERNAL_SERVER_ERROR
def cmd_fwupdate(params): try: fw_uri = params["uri"] except: print("Firmware file URI not passed") return HTTPStatus.BAD_REQUEST print("Request to update firmware with URI: {}".format(fw_uri)) try: fd, fname = tempfile.mkstemp() os.close(fd) try: urllib.request.urlretrieve(fw_uri, fname) except: print("Failed to download FW file from URI {}".format(fw_uri)) return HTTPStatus.NOT_FOUND try: ret = cli.execute("system firmware update file " + fname, 60) except: print("Failed to run firmware update command") return HTTPStatus.INTERNAL_SERVER_ERROR if not "Firmware update completed" in ret: print("Failed to update firmware") return HTTPStatus.INTERNAL_SERVER_ERROR finally: os.remove(fname) print("Firmware update finished") return HTTPStatus.OK
def main(): # Verify the configured RTC date/time is valid. pattern = re.compile(RTC_DATE_TIME_PATTERN) if not pattern.match(RTC_DATE_TIME): print("Invalid alarm value. The RTC alarm date/time must follow this " "format: YYYY-MM-DD HH:MM:SS") sys.exit(1) # Configure the RTC as a wake up source with the desired time cfg = config.load(writable=True) old_wake_rtc = cfg.get(CFG_WAKEUP_RTC) old_wake_rtc_time = cfg.get(CFG_WAKEUP_RTC_TIME) cfg.set(CFG_WAKEUP_RTC, True) cfg.set(CFG_WAKEUP_RTC_TIME, RTC_DATE_TIME) cfg.commit() # Give time to the configuration scripts to execute time.sleep(2) # Suspend the device print("Going to suspend...") print(cli.execute(CLI_SUSPEND)) # At this point device is awake, print a message print("Device is awake!") # Restore the old wake up RTC value cfg = config.load(writable=True) cfg.set(CFG_WAKEUP_RTC, old_wake_rtc) cfg.set(CFG_WAKEUP_RTC_TIME, old_wake_rtc_time) cfg.commit()
def main(): # Configure the XBee interface as a wake up source cfg = config.load(writable=True) old_wake_xbee = cfg.get(CFG_WAKEUP_XBEE) cfg.set(CFG_WAKEUP_XBEE, True) cfg.commit() # Give time to the configuration scripts to execute time.sleep(2) # Open the XBee interface and register a receive data callback device = xbee.get_device() try: device.open() def data_receive_callback(xbee_message): print("From %s >> %s" % (xbee_message.remote_device.get_64bit_addr(), xbee_message.data.decode())) device.add_data_received_callback(data_receive_callback) # Suspend the device print("Going to suspend...") print(cli.execute(CLI_SUSPEND)) # At this point device is awake, print a message print("Device is awake!") # Remove the XBee data listener device.del_data_received_callback(data_receive_callback) finally: # Close the XBee interface if device.is_open(): device.close() # Restore the old wake up XBee value cfg = config.load(writable=True) cfg.set(CFG_WAKEUP_XBEE, old_wake_xbee) cfg.commit()
def main(): # Configure the Serial port as a wake up source cfg = config.load(writable=True) old_wake_serial = cfg.get(CFG_WAKEUP_SERIAL) cfg.set(CFG_WAKEUP_SERIAL, True) cfg.commit() # Give time to the configuration scripts to execute time.sleep(2) # Create and configure the serial port settings ser = serial.Serial() ser.baudrate = BAUD_RATE ser.bytesize = N_DATA_BITS ser.stopbits = STOP_BITS ser.parity = PARITY ser.rtscts = RTS_CTS ser.timeout = 0.1 ser.setPort(PORT) # Open the serial port ser.open() # Suspend the device print("Going to suspend...", flush=True) print(cli.execute(CLI_SUSPEND)) # At this point device is awake, print a message print("Device is awake!") # Close the serial port ser.close() # Restore the old wake up serial value cfg = config.load(writable=True) cfg.set(CFG_WAKEUP_SERIAL, old_wake_serial) cfg.commit()
Options: --help Print this help and exit --debug Output 'show tech-support' to tech_support_[timestamp].log file --time <seconds> Reboot time in seconds [default: {}] """.format(sys.argv[0], REBOOT_TIME)) if __name__ == "__main__": if "--help" in sys.argv: usage() exit() if "--debug" in sys.argv: DEBUG = True print("Debug option to output Tech Support before reboot enabled.") if "--time" in sys.argv: loc = sys.argv.index("--time") try: REBOOT_TIME = int(sys.argv[loc + 1]) except: pass print("Running reboot script, timeout {0} seconds".format(REBOOT_TIME)) while True: sleep(REBOOT_TIME) if DEBUG: log_name = "tech_support_{}.log".format( datetime.now().strftime("%Y%m%d_%H%M%S")) cli.execute("show tech-support {}".format(log_name)) cli.execute("reboot")