Pi Pico W web server without infinite loop

I am trying to re-program a garden watering system to include a wifi connection.

All the examples of Pico W web servers I’ve found involve an infinite loop for the server.

What I need is code running the watering system to run with the server in the background. The server traffic will be minimal… just me on the LAN occasionally. I’m not sure if I should try to use uasyncio or just run through the server code every few cycles to see if there is incoming requests.

I’m hoping someone has successfully set up something like this.

Any advice?

The Pico W has 2 cores, so you can launch another thread to handle the web server side of things. There’s a walkthrough here Multithreaded on Raspberry Pi Pico (MicroPython) - ElectroSoftCloud

Currently working on a project where two Pico W’s communicate, one setup as an Access Point.
Highly recommend uasyncio, It is easy to use and just works.

The only issue I found is that an uasyncio task will not get serviced if the main loop does not have a await asyncio.sleep() statement. I run the main loop as a uasyncio task, the server as another and yet another to check the state of a push button switch. Happy with how it is all working so far.


Thank you Doug. I’ll look into threads but as I have already had an early look at uasyncio I think I’ll start by going down that route. I got it to work in another project but was a bit wary about its stability. Jim’s comments makes me more confident that it could do what I need.

Thanks Jim. I’ll give uasyncio a go.