Esempio n. 1
0
# The simplest possible WEB server printing "Hello World!"
# Program written for the IoT course at the University of Cape Coast
# copyright (c) U. Raich April 2020
# This program is released under GPL

import picoweb
import time
import network
import uasyncio as asyncio
import wifi_connect

print("Connecting to the network")
wifi_connect.connect()
ipaddr = wifi_connect.getIPAddress()

print("Starting the Hello World WEB server")

app = picoweb.WebApp("__main__")


@app.route("/")
def index(req, resp):
    yield from app.sendfile(resp,
                            "html/helloWorldV2.html.gz",
                            content_type="text/html; charset=utf-8",
                            headers=b"Content-Encoding: gzip\r\n")


import ulogging as logging
logging.basicConfig(level=logging.INFO)
Esempio n. 2
0
File: o.py Progetto: uraich/mpy_ucad
            self.led(not self.led())
            print(adc.read())
            sleep_ms(200)
            await asyncio.sleep_ms(0)

    def measure(self,sreader,swriter):
        print("measure task")
        trace_task = asyncio.create_task(self.trace.read_trace())
        await trace_task
        print("read trace ready")
        swriter.write(self.trace.traceBuf)
        await swriter.drain()
        
    async def close(self):
        print('Closing server')
        self.server.close()
        await self.server.wait_closed()
        print('Server closed.')
        
# connect to wifi first
connect()
ip = getIPAddress()
server = Server()
try:
    asyncio.run(server.run())
except KeyboardInterrupt:
    print('Interrupted')  # This mechanism doesn't work on Unix build.
finally:
    asyncio.run(server.close())
    _ = asyncio.new_event_loop()