belyalov / tinyweb

Simple and lightweight HTTP async server for micropython
MIT License
247 stars 40 forks source link

Updated tinyweb for new uasyncio? #29

Closed UnexpectedMaker closed 3 years ago

UnexpectedMaker commented 4 years ago

Damien has merged the new uasyncio into mainline for ESP32 (and other ports) so I was hoping that we could get a new "compatible" version of tinyweb that uses it.

From what I understand (been told by Jim Mussared) tinyweb is using some internal asyncio APIs that wont carry over to the newer uasyncio. I'm not sure how hard it will be to move it, but the plan is to have the new uasyncio ship in 1.13 (frozen), so things are going to likely break when that happens.

I'm happy to be a bleeding edge tester on this as I'm keeping the project I am working on the latest mainline right now, so I'm happy to break things on my side to help get it done.

Cheers! Seon

belyalov commented 4 years ago

Hey, thanks for heads up!

I'll try to update it this weekend.. )

UnexpectedMaker commented 4 years ago

Wicked, thanks @belyalov !

mvincm commented 4 years ago

Hello.

I'm here to test it just push the beta version :-)

Best regards MvincM

UnexpectedMaker commented 4 years ago

Hey @belyalov, any progress on looking into this? No pressure, just curious. I see more uasyncio improvements have got into master, so it's get some love from Damien atm, so would be a good time to get any tinyweb/uasyncio issues addressed if needed. Cheers, Seon

belyalov commented 4 years ago

Hey,

No progress so far - but I'm going to give it a try today.. :)

belyalov commented 4 years ago

Made some progress. It seems working well, however, I hit few issues:

Anyway it is now looks better and really close to python3.x:

import tinyweb
import uasyncio

# Create web server application
app = tinyweb.webserver(host='0.0.0.0', port=8081)

# Index page
@app.route('/')
async def index(request, response):
    # Start HTTP response with content-type text/html
    await response.start_html()
    # Send actual HTML page
    await response.send('<html><body><h1>Hello, world! (<a href="/table">table</a>)</h1></html>\n')

async def main():
    await app.start()

if __name__ == '__main__':
    uasyncio.run(main())
    uasyncio.get_event_loop().run_forever()

Hopefully will get back in few days.. :)


Micropython issue: extmod/uasyncio: add serve_forever() WIP is on new_uasync_io branch.

UnexpectedMaker commented 4 years ago

Excellent progress, thanks @belyalov !

c0d3z3r0 commented 4 years ago

reader.readexactly() isn't implemented, yet

UnexpectedMaker commented 4 years ago

Hey @belyalov - I guess this isn't going to happen? I've been in a bit of a holding pattern waiting for this, as I need to move to a newer MP version for other fixes/features, and without this being compatible with the new asyncio, I'll have to remove it and use microdot instead, which would suck as I have the features using tinyweb fully implemented in my project already.

bsecker commented 4 years ago

@belyalov are there any plans to support the new uasyncio? Much like @UnexpectedMaker my v1.12 firmware has asyncio v3.0 baked in, and I would love to be able to use tinyweb with it.

Thanks for the awesome library :-)