How to stop PicoWeb

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
uracolix
Posts: 4
Joined: Tue Jan 07, 2020 7:17 pm

How to stop PicoWeb

Post by uracolix » Wed Feb 17, 2021 5:21 am

Hello community,

I'm currently trying to start and stop a picoweb server based on a IO-Pin. The use case for this is: The user activates the switch, the APP runs in normal mode and offers a website for configuration. If user the user deactivate the switch, the APP runs in power-save-mode and just does its embedded stuff.

This my current approach:

Code: Select all

class MyWebApp(picoweb.WebApp):
    
    def serve(self, loop, host, port):
        self.ServTask = loop.create_task(uasyncio.start_server(self._handle, host, port))
        loop.run_forever()

    def stop(self):
        self.ServTask.cancel()

wapp = MyWebApp(__name__)

async def run_web_app(bsa):
    print("run_web_app:", bsa)
    wapp.a_measure = bsa.a_measure
    x = await wapp.run(host="0.0.0.0", debug=True)
    print("end wapp run", x )

@wapp.route("/")
def index(req, resp):
    await picoweb.start_response(resp)
    m = await wapp.a_measure()
    await resp.awrite("This is webapp #1: %s" % m)

Anyway the code works, except ``wapp.stop()`` because the web page is still reachable after stopping ...

Any help is appreciated, Axel

Jeizooo
Posts: 10
Joined: Mon Jan 04, 2021 10:14 am

Re: How to stop PicoWeb

Post by Jeizooo » Sat Feb 20, 2021 6:15 pm

Is it necessary to stop the web server itself? Maybe stopping the network could be enough?

Post Reply