Wifi goes off when phone is in sleep/lock mode

I solved changing the modem setting. The last versions of Android has problems with the WiFi channel 1 and 13, so the better way is to setting the transmission channel NO automatic, but fixed to an intermediate channel like 5, 7, etc... Since I've done this change the connection works great.
 
This has been driving me nuts for over a year. I stream music in HIFI so it chews up data.

This works for me...Go to "Battery and power saving"...Battery usage"..."Battery optimization"..."Ignore optimization"...then select individual apps you want to run when the phone is asleep. For me the App I want running on WIFI is Sonos as I am streaming music.

Now my WIFI is always on when I am using Sonos, even after a long period of time.
 
HI,
I am an Andriod 9 user and recently i found fix for this issue.
you will have to follw these steps
1: keep wifi on even during sleep.
I found this setting in battery setting
settings -> battery -> more battery settings -> stay connected when device sleeps (Turned on)
2: enable app running in background
Settings -> Battery -> App Launch -> uncheck manage all automatically -> Go to the app which needs to be
Alive when screen if off(whats app for instance) and select manage manually. You will get 3 options later i.e.,
Auto launch , Secondary Launch and Run in background . Enable all these option mainly the 3rd option
This should fix the issue.
Note Apps which need to be active when screen is off should always run in background so manually.