Keep WiFi alive when on battery and lid closed?

You could try this, no need to install extra sofyware

Open Terminal and use

$ caffeinate -s  

or

$ caffeinate -w PID

When used with the -w argument, sleep will be inhibited as long as the process ID PID is active. Once the the process exits, the assertion is released, and the configured sleep behavior will resume when appropriate.

Note also that Process ID's are available from Activity Monitor, or can be listed in the terminal by entering ps -Al