Exemple #1
0
def run():
    global app
    global hooks

    if not hooks:
        raise Exception('Please setup server with hooks first!')

    logging.info('About to start server...')
    app.run(debug=1, port=80, host='0.0.0.0')
Exemple #2
0
def events(req, resp):
    logging.info("Event source %r connected", resp)
    yield from resp.awrite("HTTP/1.0 200 OK\r\n")
    yield from resp.awrite("Content-Type: text/event-stream\r\n")
    yield from resp.awrite("\r\n")
    try:
        while True:
            if APP.push_event:
                yield from resp.awrite("data: %s\n\n" % APP.push_event)
            yield from asyncio.sleep(0.1)
    except OSError:
        logging.info("Event source connection closed")
        yield from resp.aclose()
Exemple #3
0
def get_last_measurement(req, resp):
    assert req.method == 'GET'
    try:
        battery_v = machine.ADC(machine.Pin(config.cfg.battery_voltage_pin))
        battery_v.atten(machine.ADC.ATTN_11DB)
        ADC_11DB_TO_VOLT = 0.000805664
        voltage = battery_v.read() * ADC_11DB_TO_VOLT

        voltage_divider_ratio = config.cfg.voltage_divider_r2_k / \
                                (config.cfg.voltage_divider_r1_k + config.cfg.voltage_divider_r2_k)

        voltage = voltage / voltage_divider_ratio
    except:
        logging.info("Error reading battery voltage!")
        voltage = 'ERROR'
    data = {"voltage": voltage}

    encoded = create_success_response(data=data)
    yield from picoweb.start_response(resp, content_type="application/json")
    yield from resp.awrite(encoded)
Exemple #4
0
def index(req, resp):
    logging.debug("push event is {}".format(APP.push_event))
    if req.method == "POST":
        yield from req.read_form_data()
        logging.debug(req.form)
        complete_seconds = int(req.form["full_process_time"]) * 60
        recur_interval = int(req.form["recur_interval"])
        agitate_list = yield from create_agitate_list(complete_seconds,
                                                      recur_interval)
        # redirect to process page
        yield from redirect(req, resp, "/process")
        # start process
        yield from process(complete_seconds, agitate_list)
    if not APP.push_event or APP.push_event == "DONE":
        yield from picoweb.start_response(resp)
        yield from APP.render_template(resp, "index.html")
    else:
        # if a process is running it will redirect to the process page
        logging.info(
            "process is running so i will directly redirect to process page")
        yield from redirect(req, resp, "/process")
Exemple #5
0
def info(message):
    ulogging.info(message)
Exemple #6
0
async def agitate():
    logging.info("moving servo motor")
    SERVO.duty(30)
    await asyncio.sleep(0.5)
    SERVO.duty(130)
    await asyncio.sleep(0.5)
Exemple #7
0
def run():
    global app

    logging.info('About to start server...')
    app.run(debug=1, port=80, host='0.0.0.0')
Exemple #8
0
def get_static_file(req, resp):
    print("Get static call")
    file_path = '/web_server/web_pages/' + req.url_match.group(1)
    logging.info('About to send file: ' + file_path)
    yield from app.sendfile(resp, file_path)