this looks like the typical hassle with Qualcomm's WiFi chips and some routers. Both Nexus 4 and 7 use a WiFi chip manufactured by Qualcomm. Depending on your router's configuration those chips will stop responding after some time when the device is in standby.
A temporary quick fix for this problem is to assign a static IP to your devices instead of using DHCP. This can be done in most routers using a MAC->IP mapping.
If this doesn't help, you can stop reading now.
There are three other methods of fixing (of which one will require root):
Non-root:
- Go to WiFi settings -> Advanced and set your frequency to 2,4 GHz only (this will work at a 50% chance)
- Go to WiFi settings -> Advanced and disable "WiFi Optimisation" (WARNING: this can lead to a huge battery drain in busy networks)
Root:
- Open a file explorer (e.g. ES Explorer) with root privilegs, move to /etc/wifi and open the file WCNSS_qcom_cfg.ini.
Edit these three parameters so that they will all be enabled (=1):
- gEnableActiveModeOffload=1
- hostArpOffload=1
- hostNSOffload=1
Save the file and reboot your device.
A little bit of explanation:
The feature that is messed up in Qualcomm's configuration file is ARP - Adress Resolution Protocol. ARP is meant to map a hardware's MAC adress to it's IP adress so the router can directly call the connected hardware via MAC adress. Usually the router periodically sends ARP requests to connected devices to ensure they're still in the network. When the device is awake and the CPU is active, it will deal with the ARP request and everything goes well.
Once the CPU is asleep, it's the WiFi chip's job to deal with ARP requests so that the CPU needn't to be powered on every time an ARP request arrives. If ARP-Offloading is disabled though, the chip won't respond to the request and the router will kick the device out of its IP<->MAC map, which eventually leads to a dead connection.
When you assign a static IP, the whole ARP stuff is not needed obviously.
Disabling WiFi Optimisation will make the CPU inspect every packet so it will deal with ARP instead of the WiFi chip. The problem here, that this will hinder the device from going into power save mode.
I personally had the same WiFi problems until I manually fixed my .ini the way I described above. It took me nearly half a year to figure the problem out. I hope that I can help you with that!
Best regards!
DISCLAIMER: I'm not responsible if you harm your phone or data.