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:
Anyway the code works, except ``wapp.stop()`` because the web page is still reachable after stopping ...
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)
Any help is appreciated, Axel