def __init__(self, display_web): ROUTES = [ ("/events", self.events), ] # logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.DEBUG) self.display_web = display_web self.webapp = picoweb.WebApp(__name__, ROUTES)
def main(): gc.collect() logging.basicConfig(level=logging.DEBUG) gc.collect() app._load_template("index.tpl") gc.collect() loop = uasyncio.get_event_loop() loop.create_task(push_status()) loop.call_soon(get_wifi) loop.call_soon(lambda: loop.create_task(app.black.do_anneal())) loop.call_soon(lambda: loop.create_task(app.black.calibrate_motor())) app.run(host="0.0.0.0", debug=True)
def main(**params): gc.collect() import ulogging as logging logging.basicConfig(level=logging.DEBUG) # Preload templates to avoid memory fragmentation issues gc.collect() APP._load_template("index.html") gc.collect() import micropython micropython.mem_info() loop = asyncio.get_event_loop() loop.create_task(coros.janitor()) APP.run(debug=True, **params)
def _init_logging(self): LOG_LOCALLY = env['LOG_LOCALLY'] if 'LOG_LOCALLY' in env.keys( ) else True self._log_stream = MQTTStream(self.mqtt, self.hardware_id, LOG_LOCALLY) self._asyncio_loop.create_task(self._log_stream._process_log_queue()) # Set the log level based on the global environment variable 'LOG_LEVEL' log_level_string = env['LOG_LEVEL'] if 'LOG_LEVEL' in env.keys( ) else 'DEBUG' # Convert the log level `string` to the right enum LOG_LEVEL = logging.DEBUG for x in ['DEBUG', 'INFO', 'WARNING', 'ERROR']: if x == log_level_string: LOG_LEVEL = eval('logging.%s' % x) break # Make this the default log stream logging.basicConfig(level=LOG_LEVEL, stream=self._log_stream) self._asyncio_loop.create_task(self._process_mqtt_messages())
for resp in event_sinks: try: await resp.awrite("{}data: {}\n\n".format( ("event: {}\n".format(e_type) if e_type else ""), json.dumps(ev)) ) except OSError as e: print("Event source %r disconnected (%r)" % (resp, e)) await resp.aclose() # Can't remove item from set while iterating, have to have # second pass for that (not very efficient). to_del.add(resp) for resp in to_del: event_sinks.remove(resp) def push_events(): global eventlist while True: for event in eventlist: await push_event(event[0], event[1]) eventlist.remove(event) await asyncio.sleep_ms(10) loop.create_task(push_events()) logging.basicConfig(level=logging.INFO) app.run(host='0.0.0.0', port=80, debug=True)
# Timer if (timerFinish != 0): display.updateTimer((timerFinish - utime.ticks_ms()) / 60000) await asyncio.sleep(1) async def runController(): global controller while (1): controller.run() await asyncio.sleep(0.1) import ulogging as logging #logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.DEBUG) def main(name): loop = asyncio.get_event_loop() loop.create_task(timer()) loop.create_task(updateDisplay()) loop.create_task(runController()) ROUTES = [ # You can specify exact URI string matches... ("/", lambda req, resp: (yield from app.sendfile(resp, "horno.html"))), ("/horno.js", lambda req, resp: (yield from app.sendfile(resp, "horno.js"))), ("/gauge.min.js", lambda req, resp: (yield from app.sendfile(resp, "gauge.min.js"))),
def auth(req, resp): auth = req.headers.get(b"Authorization") if not auth: yield from resp.awrite( 'HTTP/1.0 401 NA\r\n' 'WWW-Authenticate: Basic realm="Picoweb Realm"\r\n' '\r\n' ) return auth = auth.split(None, 1)[1] auth = ubinascii.a2b_base64(auth).decode() req.username, req.passwd = auth.split(":", 1) yield from func(req, resp) return auth @app.route("/") @require_auth def index(req, resp): yield from picoweb.start_response(resp) yield from resp.awrite("You logged in with username: %s, password: %s" % (req.username, req.passwd)) import ulogging as logging logging.basicConfig(level=logging.INFO) app.run(debug=True)
import mpylib import opcode import ulogging ulogging.basicConfig(level=ulogging.DEBUG) opcode.config.MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE = 1 op = mpylib.get_opcode_ns() with open("testout.mpy", "wb") as f: mpy = mpylib.MPYWriter(f) mpy.write_header( mpylib.MPY_VERSION, mpylib.MICROPY_PY_BUILTINS_STR_UNICODE | mpylib.MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE, 31) co = mpylib.CodeType() co.mpy_stacksize = 2 co.mpy_excstacksize = 0 co.co_flags = 0 co.co_argcount = 0 co.co_kwonlyargcount = 0 co.mpy_def_pos_args = 0 co.co_lnotab = b'\x00\x00' co.co_cellvars = () bc = mpylib.Bytecode() bc.add(op.LOAD_NAME, "print") bc.load_int(-65) bc.add(op.LOAD_CONST_OBJ, "string") bc.add(op.CALL_FUNCTION, 2, 0)
import ure as re import picoweb import signal import ulogging import uasyncio as asyncio import uerrno import machine import time import utemplate ulogging.basicConfig(level=ulogging.INFO) # ulogging.basicConfig(level=logging.DEBUG) log = ulogging.getLogger(__name__) def handle_signal(signalNumber): print("Received:", signalNumber) return class OpenMikoWebApp(picoweb.WebApp): def init(self): """Initialize the OpenMiko web application. """ log.info("Initializing OpenMiko application") self.setup_signal_handlers() self.inited = True def setup_signal_handlers(self): log.info("Setting up signal handlers") SIGUSR1 = 10
import time import machine import network import logger import ulogging if __name__ == '__main__': wlan = network.WLAN(network.STA_IF) if not wlan.isconnected(): import webrepl webrepl.stop() ulogging.basicConfig(level=ulogging.WARNING) try: import runner runner.run() except Exception as err: logger.error(err) time.sleep(10) machine.reset()