def reboot_collect(): report_collect() if gc.mem_free() > LOW_MEMORY: print("MEMORY OK") else: print("LOW MEMORY, REBOOTING") reboot()
def _download_and_install_update(self, latest_version): self.download_all_files( self.github_repo + '/contents/' + self.main_dir, latest_version) self.rmtree(self.modulepath(self.main_dir)) os.rename(self.modulepath('next/.version_on_reboot'), self.modulepath('next/.version')) os.rename(self.modulepath('next'), self.modulepath(self.main_dir)) print('Update installed (', latest_version, '), will reboot now') reboot()
def connect_wifi(): rgb.pixel((255, 255, 0), (31, 0)) # yellow connecting to wifi if not wifi.status(): wifi.connect() if wifi.wait(): rgb.pixel((0, 255, 0), (31, 0)) # green for wifi rgb.framerate(20) else: rgb.clear() rgb.framerate(20) data, frames = icon_no_wifi rgb.image(data, (12, 0), (8, 8)) time.sleep(3) rgb.clear() machine.reboot()
import config import machine import server import status_server_controller import temperature_sensor import thermostat_server_controller import utils utils.printInfo("THERMOSTAT", "boot up") utils.createSyncDateTimeTimer() _temperature_sensor = temperature_sensor.TemperatureSensor(machine.Pin(config.DS18B20_PIN)) _relay_pin = machine.Pin(config.THERMOSTAT_RELAY_PIN, machine.Pin.OUT) _switch_pin = machine.Pin(config.THERMOSTAT_SWITCH_PIN, machine.Pin.IN) _led_pin = machine.Pin(config.THERMOSTAT_LED_PIN, machine.Pin.OUT) _thermostat_server_controller = thermostat_server_controller.ThermostatServerController(_temperature_sensor, _relay_pin, _switch_pin, _led_pin) _controllers = [_thermostat_server_controller] _statusController = status_server_controller.StatusServerController('Thermostat', _controllers) _server = server.Server(config.SERVER_PORT, _controllers + [_statusController]) try: _server.run() except KeyboardInterrupt: utils.printInfo("THERMOSTAT", "stopped by the user") utils.deleteTimers() except Exception as e: utils.printWarn("THERMOSTAT", "exception during server run: %s" % e) machine.reboot()