def main(): gc.collect() # process_requirements() gc.collect() loop = asyncio.get_event_loop() try: asyncio.ensure_future(wlog.logger.start()) log('Logger initialized') try: loop.run_until_complete(run()) except Exception as e: log(exception_traceback_string(e)) while True: try: loop.run_forever() except Exception as e: log(exception_traceback_string(e)) loop.close() except Exception as e: log(exception_traceback_string(e)) try: log('Restarting esp as asyncio loop closed') except: pass machine.reset()
async def run(): log('All initialized') try: asyncio.ensure_future(notify_memory()) import app asyncio.ensure_future(app.main()) import discovery asyncio.ensure_future( discovery.DiscoveryServer(local_ip=wifi.get_ip()).start()) except Exception as e: log(exception_traceback_string(e), important=True) while True: await asyncio.sleep(1)
def __init__(self): self.oled = None try: i2c = machine.I2C( scl=machine.Pin(D2, machine.Pin.OUT), sda=machine.Pin(D1, machine.Pin.OUT), ) self.oled = ssd1306.SSD1306_I2C(128, 64, i2c, 0x3c) self.oled.fill(0) self.oled.text('Initialized!', 0, 0) self.oled.show() except: log('Error: display not initialized') return self.initialized = self.oled is not None
def connect(ssid, password): global client log('Connecting to "{}"... '.format(ssid), end='') client = network.WLAN(network.STA_IF) client.active(True) client.connect(ssid, password) while not client.isconnected(): pass log('IP: {}'.format(get_ip())) log('done')
def on_message(self, message): log('Got message: {}'.format(message))
async def notify_memory(delay=5): while True: # gc.collect() log('FM: {:0.2f} KB'.format(gc.mem_free() / 1024)) await asyncio.sleep(delay)
async def main(): log('App running!')
def main(options, args): log('Create service') global pr pr = process_run(options)