I know it's an old thread, but this app helped me.
I am on official 5.1.1 android version (so no battery optimization options here).
I've been testing this app for about an hour and wifi is still working (I am testing by keeping a continuous ping form my computer to android wifi's IP).
So far...