Nexus 4, Lollipop 5.1 WiFi Issue
Some sites recommend to restart the router device, and sometime it works.
Instead of every time restart the router to solve this Android 5.1 Wi-Fi problem, it worked for me:

Inside the router configuration (e.g., accessing the IP 192.168.0.1), change the "Group key update" value from 0 to 30 seconds, under the "Wireless > Security" configuration, right below the WPA-PSK/WPA2-PSK item.

My router model is: TP-LINK TL-WR740N / TL-WR740ND.